chiark / gitweb /
clients: try to follow roughly the same order in --help texts for common options
[elogind.git] / src / analyze / analyze.c
index 8f965e7a8b28ff61d9d268829d1153d554270aeb..4637424d628b4f33ff4ce9d43bf7cb39cfdccd99 100644 (file)
@@ -190,10 +190,8 @@ static int bus_parse_unit_info(sd_bus_message *message, struct unit_info *u) {
                                                          &u->job_id,
                                                          &u->job_type,
                                                          &u->job_path);
-        if (r < 0) {
-                log_error("Failed to parse message as unit_info.");
-                return -EIO;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
 
         return r;
 }
@@ -230,6 +228,9 @@ static int bus_get_unit_property_strv(sd_bus *bus, const char *unit_path, const
                 }
         }
 
+        if (r < 0)
+                return bus_log_parse_error(r);
+
         return r;
 }
 
@@ -839,15 +840,13 @@ static int list_dependencies(sd_bus *bus, const char *name) {
                         &reply,
                         "s");
         if (r < 0) {
-                log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
+                log_error("Failed to get ID: %s", bus_error_message(&error, -r));
                 return r;
         }
 
         r = sd_bus_message_read(reply, "s", &id);
-        if (r < 0) {
-                log_error("Failed to parse reply.");
-                return r;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
 
         times = hashmap_get(unit_times_hashmap, id);
 
@@ -1085,6 +1084,7 @@ static int dot(sd_bus *bus, char* patterns[]) {
 
         return 0;
 }
+
 static int dump(sd_bus *bus, char **args) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -1113,10 +1113,8 @@ static int dump(sd_bus *bus, char **args) {
         }
 
         r = sd_bus_message_read(reply, "s", &text);
-        if (r < 0) {
-                log_error("Failed to parse reply");
-                return r;
-        }
+        if (r < 0)
+                return bus_log_parse_error(r);
 
         fputs(text, stdout);
         return 0;
@@ -1151,7 +1149,7 @@ static int set_log_level(sd_bus *bus, char **args) {
         return 0;
 }
 
-static void help(void) {
+static int help(void) {
 
         pager_open_if_enabled();
 
@@ -1159,6 +1157,7 @@ static void help(void) {
                "Process systemd profiling information.\n\n"
                "  -h --help               Show this help\n"
                "     --version            Show package version\n"
+               "     --no-pager           Do not pipe output into a pager\n"
                "     --system             Connect to system manager\n"
                "     --user               Connect to user manager\n"
                "  -H --host=[USER@]HOST   Operate on remote host\n"
@@ -1171,8 +1170,7 @@ static void help(void) {
                "     --fuzz=TIMESPAN      When printing the tree of the critical chain, print also\n"
                "                          services, which finished TIMESPAN earlier, than the\n"
                "                          latest in the branch. The unit of TIMESPAN is seconds\n"
-               "                          unless specified with a different unit, i.e. 50ms\n"
-               "     --no-pager           Do not pipe output into a pager\n\n"
+               "                          unless specified with a different unit, i.e. 50ms\n\n"
                "Commands:\n"
                "  time                    Print time spent in the kernel before reaching userspace\n"
                "  blame                   Print list of running units ordered by time to init\n"
@@ -1186,11 +1184,11 @@ static void help(void) {
         /* When updating this list, including descriptions, apply
          * changes to shell-completion/bash/systemd and
          * shell-completion/systemd-zsh-completion.zsh too. */
+
+        return 0;
 }
 
 static int parse_argv(int argc, char *argv[]) {
-        int r;
-
         enum {
                 ARG_VERSION = 0x100,
                 ARG_ORDER,
@@ -1214,18 +1212,20 @@ static int parse_argv(int argc, char *argv[]) {
                 { "to-pattern",   required_argument, NULL, ARG_DOT_TO_PATTERN   },
                 { "fuzz",         required_argument, NULL, ARG_FUZZ             },
                 { "no-pager",     no_argument,       NULL, ARG_NO_PAGER         },
-                { NULL,           0,                 NULL, 0                    }
+                {}
         };
 
+        int r, c;
+
         assert(argc >= 0);
         assert(argv);
 
-        for (;;) {
-                switch (getopt_long(argc, argv, "hH:M:", options, NULL)) {
+        while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+
+                switch (c) {
 
                 case 'h':
-                        help();
-                        return 0;
+                        return help();
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
@@ -1280,9 +1280,6 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_host = optarg;
                         break;
 
-                case -1:
-                        return 1;
-
                 case '?':
                         return -EINVAL;
 
@@ -1290,6 +1287,8 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
         }
+
+        return 1;
 }
 
 int main(int argc, char *argv[]) {