chiark / gitweb /
Always check asprintf return code
[elogind.git] / src / systemctl / systemctl.c
index 96a0d0578ee2459f153dcd9c99a518d409b00e54..f3d7fc8d6e5c0573a5e7442180e1b41ce7c5c0ab 100644 (file)
@@ -3503,50 +3503,11 @@ static void show_unit_help(UnitStatusInfo *i) {
                 return;
         }
 
-        STRV_FOREACH(p, i->documentation) {
-
-                if (startswith(*p, "man:")) {
-                        const char *args[4] = { "man", NULL, NULL, NULL };
-                        _cleanup_free_ char *page = NULL, *section = NULL;
-                        char *e = NULL;
-                        pid_t pid;
-                        size_t k;
-
-                        k = strlen(*p);
-
-                        if ((*p)[k-1] == ')')
-                                e = strrchr(*p, '(');
-
-                        if (e) {
-                                page = strndup((*p) + 4, e - *p - 4);
-                                section = strndup(e + 1, *p + k - e - 2);
-                                if (!page || !section) {
-                                        log_oom();
-                                        return;
-                                }
-
-                                args[1] = section;
-                                args[2] = page;
-                        } else
-                                args[1] = *p + 4;
-
-                        pid = fork();
-                        if (pid < 0) {
-                                log_error("Failed to fork: %m");
-                                continue;
-                        }
-
-                        if (pid == 0) {
-                                /* Child */
-                                execvp(args[0], (char**) args);
-                                log_error("Failed to execute man: %m");
-                                _exit(EXIT_FAILURE);
-                        }
-
-                        wait_for_terminate(pid, NULL);
-                } else
+        STRV_FOREACH(p, i->documentation)
+                if (startswith(*p, "man:"))
+                        show_man_page(*p + 4, false);
+                else
                         log_info("Can't show: %s", *p);
-        }
 }
 
 static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *i, const char *contents) {
@@ -5038,11 +4999,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         _cleanup_free_ char *path = NULL;
 
                         if (!isempty(arg_root))
-                                asprintf(&path, "%s/%s/%s", arg_root, *k, name);
+                                j = asprintf(&path, "%s/%s/%s", arg_root, *k, name);
                         else
-                                asprintf(&path, "%s/%s", *k, name);
-
-                        if (!path) {
+                                j = asprintf(&path, "%s/%s", *k, name);
+                        if (j < 0) {
                                 r = log_oom();
                                 goto finish;
                         }
@@ -5056,10 +5016,10 @@ static int enable_sysv_units(const char *verb, char **args) {
                         continue;
 
                 if (!isempty(arg_root))
-                        asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
+                        j = asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
                 else
-                        asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
-                if (!p) {
+                        j = asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
+                if (j < 0) {
                         r = log_oom();
                         goto finish;
                 }