Remove the requirement to separate service parameters with "--" 59/255959/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 25 Mar 2021 12:27:20 +0000 (13:27 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 25 Mar 2021 13:19:33 +0000 (14:19 +0100)
This change removes the requirement to separate service options from
dumpsys options with "--". Now all options after the service name are
passed to the target service.

After this change there is no need to call:

    dumpsys -o /tmp/data.txt org.tizen.some_service -- --opt1 arg1

Can be called simply:

    dumpsys -o /tmp/data.txt org.tizen.some_service --opt1 arg1

Change-Id: I6886f7dfd8e0cf550833163901c07c7c7f25d933

src/dumpsys/dumpsys.c

index a7447b9..26868c3 100644 (file)
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
        int out_fd = STDOUT_FILENO;
        bool result = false;
 
-       while ((opt = getopt(argc, argv, "o:")) != -1) {
+       while ((opt = getopt(argc, argv, "+o:")) != -1) {
                switch(opt) {
                case 'o':
                        filename = optarg;
@@ -105,8 +105,16 @@ int main(int argc, char *argv[])
        int i = optind;
        const char *service_name = argv[i];
 
+       int arg_offset = 1;
+
+       /*
+        * If the service name is followed by "--", we do not send it as argument.
+        */
+       if (optind + 1 < argc && strncmp(argv[optind + 1], "--", 3) == 0)
+               arg_offset += 1;
+
        int in_fd;
-       if (dumpsys_dump(service_name, argc-i-1, (const char **)&argv[i+1], &in_fd) == TIZEN_ERROR_NONE)
+       if (dumpsys_dump(service_name, argc-i-arg_offset, (const char **)&argv[i+arg_offset], &in_fd) == TIZEN_ERROR_NONE)
                result = copy_data(out_fd, in_fd);
 
 end: