procd: Add %m to several functions that return errno.
authorRosen Penev <rosenp@gmail.com>
Mon, 25 Dec 2017 22:14:46 +0000 (14:14 -0800)
committerJohn Crispin <john@phrozen.org>
Tue, 2 Jan 2018 12:01:50 +0000 (13:01 +0100)
Might help with debugging. No size impact.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
initd/early.c
initd/init.c
initd/preinit.c
initd/zram.c
inittab.c
jail/fs.c
plug/coldplug.c
plug/hotplug.c
rcS.c
service/instance.c
state.c

index 7028ff8a4b79e0d5f29573d29855a21b8cae1bf8..00fd9467912085fcba2b2abab2163e49b025009e 100644 (file)
@@ -39,7 +39,7 @@ early_console(const char *dev)
        struct stat s;
 
        if (stat(dev, &s)) {
        struct stat s;
 
        if (stat(dev, &s)) {
-               ERROR("Failed to stat %s\n", dev);
+               ERROR("Failed to stat %s: %m\n", dev);
                return;
        }
 
                return;
        }
 
index e453cff21e426bc80bf7bc3cbf92df42aea0db80..0349e6e9d77ef57288a10108326b2f8a43499d8a 100644 (file)
@@ -90,11 +90,11 @@ main(int argc, char **argv)
                        patch_stdio("/dev/null");
 
                execvp(kmod[0], kmod);
                        patch_stdio("/dev/null");
 
                execvp(kmod[0], kmod);
-               ERROR("Failed to start kmodloader\n");
+               ERROR("Failed to start kmodloader: %m\n");
                exit(-1);
        }
        if (pid <= 0) {
                exit(-1);
        }
        if (pid <= 0) {
-               ERROR("Failed to start kmodloader instance\n");
+               ERROR("Failed to start kmodloader instance: %m\n");
        } else {
                int i;
 
        } else {
                int i;
 
index 09edb8fb88d0c9a1da8854bae54285b4fcaba59b..fbb36df9e5adb2e668f0b033bbc2fda0f1e20ee0 100644 (file)
@@ -42,7 +42,7 @@ check_dbglvl(void)
        if (!fp)
                return;
        if (fscanf(fp, "%d", &lvl) == EOF)
        if (!fp)
                return;
        if (fscanf(fp, "%d", &lvl) == EOF)
-               ERROR("failed to read debug level\n");
+               ERROR("failed to read debug level: %m\n");
        fclose(fp);
        unlink("/tmp/debug_level");
 
        fclose(fp);
        unlink("/tmp/debug_level");
 
@@ -134,11 +134,11 @@ preinit(void)
        plugd_proc.pid = fork();
        if (!plugd_proc.pid) {
                execvp(plug[0], plug);
        plugd_proc.pid = fork();
        if (!plugd_proc.pid) {
                execvp(plug[0], plug);
-               ERROR("Failed to start plugd\n");
+               ERROR("Failed to start plugd: %m\n");
                exit(-1);
        }
        if (plugd_proc.pid <= 0) {
                exit(-1);
        }
        if (plugd_proc.pid <= 0) {
-               ERROR("Failed to start new plugd instance\n");
+               ERROR("Failed to start new plugd instance: %m\n");
                return;
        }
        uloop_process_add(&plugd_proc);
                return;
        }
        uloop_process_add(&plugd_proc);
@@ -148,7 +148,7 @@ preinit(void)
        fd = creat("/tmp/.preinit", 0600);
 
        if (fd < 0)
        fd = creat("/tmp/.preinit", 0600);
 
        if (fd < 0)
-               ERROR("Failed to create sentinel file\n");
+               ERROR("Failed to create sentinel file: %m\n");
        else
                close(fd);
 
        else
                close(fd);
 
@@ -156,11 +156,11 @@ preinit(void)
        preinit_proc.pid = fork();
        if (!preinit_proc.pid) {
                execvp(init[0], init);
        preinit_proc.pid = fork();
        if (!preinit_proc.pid) {
                execvp(init[0], init);
-               ERROR("Failed to start preinit\n");
+               ERROR("Failed to start preinit: %m\n");
                exit(-1);
        }
        if (preinit_proc.pid <= 0) {
                exit(-1);
        }
        if (preinit_proc.pid <= 0) {
-               ERROR("Failed to start new preinit instance\n");
+               ERROR("Failed to start new preinit instance: %m\n");
                return;
        }
        uloop_process_add(&preinit_proc);
                return;
        }
        uloop_process_add(&preinit_proc);
index d438372469451fa3a8c7794435e1a6e8beacf19f..b41bfd999ba2630f086cba140e5fdcd7aabfac6b 100644 (file)
@@ -64,12 +64,12 @@ early_insmod(char *module)
                sprintf(path, module, ver.release);
                modprobe[1] = path;
                execvp(modprobe[0], modprobe);
                sprintf(path, module, ver.release);
                modprobe[1] = path;
                execvp(modprobe[0], modprobe);
-               ERROR("Can't exec %s\n", modprobe[0]);
+               ERROR("Can't exec %s: %m\n", modprobe[0]);
                exit(-1);
        }
 
        if (pid <= 0) {
                exit(-1);
        }
 
        if (pid <= 0) {
-               ERROR("Can't exec %s\n", modprobe[0]);
+               ERROR("Can't exec %s: %m\n", modprobe[0]);
                return -1;
        } else {
                waitpid(pid, NULL, 0);
                return -1;
        } else {
                waitpid(pid, NULL, 0);
@@ -107,10 +107,10 @@ mount_zram_on_tmp(void)
        pid = fork();
        if (!pid) {
                execvp(mkfs[0], mkfs);
        pid = fork();
        if (!pid) {
                execvp(mkfs[0], mkfs);
-               ERROR("Can't exec %s\n", mkfs[0]);
+               ERROR("Can't exec %s: %m\n", mkfs[0]);
                exit(-1);
        } else if (pid <= 0) {
                exit(-1);
        } else if (pid <= 0) {
-               ERROR("Can't exec %s\n", mkfs[0]);
+               ERROR("Can't exec %s: %m\n", mkfs[0]);
                return -1;
        } else {
                waitpid(pid, NULL, 0);
                return -1;
        } else {
                waitpid(pid, NULL, 0);
index c27c3241f4e1b359eb69e7177f7ac633de7d5441..55554b944d74f36068afe03f7ab64140da8564dc 100644 (file)
--- a/inittab.c
+++ b/inittab.c
@@ -104,7 +104,7 @@ static void fork_worker(struct init_action *a)
                tcsetpgrp(STDIN_FILENO, p);
 
                execvp(a->argv[0], a->argv);
                tcsetpgrp(STDIN_FILENO, p);
 
                execvp(a->argv[0], a->argv);
-               ERROR("Failed to execute %s\n", a->argv[0]);
+               ERROR("Failed to execute %s: %m\n", a->argv[0]);
                exit(-1);
        }
 
                exit(-1);
        }
 
@@ -278,7 +278,7 @@ void procd_inittab(void)
        char *line;
 
        if (!fp) {
        char *line;
 
        if (!fp) {
-               ERROR("Failed to open %s\n", tab);
+               ERROR("Failed to open %s: %m\n", tab);
                return;
        }
 
                return;
        }
 
index 81e6c61309956d655e24cc77bb4a339d1b467c8c..8cc47d32f2b768b7fca9a0ddb511a0a5f718fe3e 100644 (file)
--- a/jail/fs.c
+++ b/jail/fs.c
@@ -153,7 +153,7 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib)
 
        map = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (map == MAP_FAILED) {
 
        map = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (map == MAP_FAILED) {
-               ERROR("failed to mmap %s\n", path);
+               ERROR("failed to mmap %s: %m\n", path);
                ret = -1;
                goto out;
        }
                ret = -1;
                goto out;
        }
index 5fcb9a333200d5d32fad5f7f98d8359f05c4fc6b..c6a89c30a6fc2e11539f7643d4fde41c12bbbf62 100644 (file)
@@ -54,12 +54,12 @@ void procd_coldplug(void)
        udevtrigger.pid = fork();
        if (!udevtrigger.pid) {
                execvp(argv[0], argv);
        udevtrigger.pid = fork();
        if (!udevtrigger.pid) {
                execvp(argv[0], argv);
-               ERROR("Failed to start coldplug\n");
+               ERROR("Failed to start coldplug: %m\n");
                exit(-1);
        }
 
        if (udevtrigger.pid <= 0) {
                exit(-1);
        }
 
        if (udevtrigger.pid <= 0) {
-               ERROR("Failed to start new coldplug instance\n");
+               ERROR("Failed to start new coldplug instance: %m\n");
                return;
        }
 
                return;
        }
 
index d09af620c887872c2fb6972b39a6e57b7d4def31..80e6e4db9e734b708f62d4f41a695486f654188f 100644 (file)
@@ -238,7 +238,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data)
        sprintf(path, "%s/%s", dir, file);
 
        if (stat(path, &s)) {
        sprintf(path, "%s/%s", dir, file);
 
        if (stat(path, &s)) {
-               ERROR("Could not find firmware %s\n", path);
+               ERROR("Could not find firmware %s: %m\n", path);
                src = -1;
                s.st_size = 0;
                goto send_to_kernel;
                src = -1;
                s.st_size = 0;
                goto send_to_kernel;
@@ -246,7 +246,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data)
 
        src = open(path, O_RDONLY);
        if (src < 0) {
 
        src = open(path, O_RDONLY);
        if (src < 0) {
-               ERROR("Failed to open %s\n", path);
+               ERROR("Failed to open %s: %m\n", path);
                s.st_size = 0;
                goto send_to_kernel;
        }
                s.st_size = 0;
                goto send_to_kernel;
        }
@@ -255,11 +255,11 @@ send_to_kernel:
        snprintf(loadpath, sizeof(loadpath), "/sys/%s/loading", dev);
        load = open(loadpath, O_WRONLY);
        if (!load) {
        snprintf(loadpath, sizeof(loadpath), "/sys/%s/loading", dev);
        load = open(loadpath, O_WRONLY);
        if (!load) {
-               ERROR("Failed to open %s\n", loadpath);
+               ERROR("Failed to open %s: %m\n", loadpath);
                exit(-1);
        }
        if (write(load, "1", 1) == -1) {
                exit(-1);
        }
        if (write(load, "1", 1) == -1) {
-               ERROR("Failed to write to %s\n", loadpath);
+               ERROR("Failed to write to %s: %m\n", loadpath);
                exit(-1);
        }
        close(load);
                exit(-1);
        }
        close(load);
@@ -267,7 +267,7 @@ send_to_kernel:
        snprintf(syspath, sizeof(syspath), "/sys/%s/data", dev);
        fw = open(syspath, O_WRONLY);
        if (fw < 0) {
        snprintf(syspath, sizeof(syspath), "/sys/%s/data", dev);
        fw = open(syspath, O_WRONLY);
        if (fw < 0) {
-               ERROR("Failed to open %s\n", syspath);
+               ERROR("Failed to open %s: %m\n", syspath);
                exit(-1);
        }
 
                exit(-1);
        }
 
@@ -278,7 +278,7 @@ send_to_kernel:
                        break;
 
                if (write(fw, buf, len) == -1) {
                        break;
 
                if (write(fw, buf, len) == -1) {
-                       ERROR("failed to write firmware file %s/%s to %s\n", dir, file, dev);
+                       ERROR("failed to write firmware file %s/%s to %s: %m\n", dir, file, dev);
                        break;
                }
        }
                        break;
                }
        }
@@ -289,7 +289,7 @@ send_to_kernel:
 
        load = open(loadpath, O_WRONLY);
        if (write(load, "0", 1) == -1)
 
        load = open(loadpath, O_WRONLY);
        if (write(load, "0", 1) == -1)
-               ERROR("failed to write to %s\n", loadpath);
+               ERROR("failed to write to %s: %m\n", loadpath);
        close(load);
 
        DEBUG(2, "Done loading %s\n", path);
        close(load);
 
        DEBUG(2, "Done loading %s\n", path);
diff --git a/rcS.c b/rcS.c
index b1202bf96613d19ee076ee700ad234e6cfcc9db6..dd3b76d22a60c594eb2199fbea6f1cfd8dbbc839 100644 (file)
--- a/rcS.c
+++ b/rcS.c
@@ -72,7 +72,7 @@ static void q_initd_run(struct runqueue *q, struct runqueue_task *t)
 
        DEBUG(2, "start %s %s \n", s->file, s->param);
        if (pipe(pipefd) == -1) {
 
        DEBUG(2, "start %s %s \n", s->file, s->param);
        if (pipe(pipefd) == -1) {
-               ERROR("Failed to create pipe\n");
+               ERROR("Failed to create pipe: %m\n");
                return;
        }
 
                return;
        }
 
index 7447bad37deda68772c47be5b4fb5e98856a0a6c..12c2efe2b2cc467d1ff6ac9174d5a3b870a9631d 100644 (file)
@@ -241,8 +241,7 @@ instance_removepid(struct service_instance *in) {
        if (!in->pidfile)
                return 0;
        if (unlink(in->pidfile)) {
        if (!in->pidfile)
                return 0;
        if (unlink(in->pidfile)) {
-               ERROR("Failed to removed pidfile: %s: %m\n",
-                       in->pidfile);
+               ERROR("Failed to removed pidfile: %s: %m\n", in->pidfile);
                return 1;
        }
        return 0;
                return 1;
        }
        return 0;
@@ -258,19 +257,16 @@ instance_writepid(struct service_instance *in)
        }
        _pidfile = fopen(in->pidfile, "w");
        if (_pidfile == NULL) {
        }
        _pidfile = fopen(in->pidfile, "w");
        if (_pidfile == NULL) {
-               ERROR("failed to open pidfile for writing: %s: %m",
-                       in->pidfile);
+               ERROR("failed to open pidfile for writing: %s: %m", in->pidfile);
                return 1;
        }
        if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) {
                return 1;
        }
        if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) {
-               ERROR("failed to write pidfile: %s: %m",
-                       in->pidfile);
+               ERROR("failed to write pidfile: %s: %m", in->pidfile);
                fclose(_pidfile);
                return 2;
        }
        if (fclose(_pidfile)) {
                fclose(_pidfile);
                return 2;
        }
        if (fclose(_pidfile)) {
-               ERROR("failed to close pidfile: %s: %m",
-                       in->pidfile);
+               ERROR("failed to close pidfile: %s: %m", in->pidfile);
                return 3;
        }
 
                return 3;
        }
 
diff --git a/state.c b/state.c
index 3b56bd0b75f81851b12b2fb5cb32d52ef16fb2d7..ccf410454711880c1f3639f4a84bb8ea42e9a05c 100644 (file)
--- a/state.c
+++ b/state.c
@@ -48,7 +48,7 @@ static void set_stdio(const char* tty)
            !freopen(tty, "w", stdout) ||
            !freopen(tty, "w", stderr) ||
            chdir("/"))
            !freopen(tty, "w", stdout) ||
            !freopen(tty, "w", stderr) ||
            chdir("/"))
-               ERROR("failed to set stdio\n");
+               ERROR("failed to set stdio: %m\n");
        else
                fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
 }
        else
                fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
 }
@@ -73,7 +73,7 @@ static void set_console(void)
        }
 
        if (chdir("/dev")) {
        }
 
        if (chdir("/dev")) {
-               ERROR("failed to change dir to /dev\n");
+               ERROR("failed to change dir to /dev: %m\n");
                return;
        }
        while (tty!=NULL) {
                return;
        }
        while (tty!=NULL) {
@@ -87,7 +87,7 @@ static void set_console(void)
                i++;
        }
        if (chdir("/"))
                i++;
        }
        if (chdir("/"))
-               ERROR("failed to change dir to /\n");
+               ERROR("failed to change dir to /: %m\n");
 
        if (tty != NULL)
                set_stdio(tty);
 
        if (tty != NULL)
                set_stdio(tty);