From a5954cf302fe46d8e29770c818336763112b9a6e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 25 Dec 2017 14:14:46 -0800 Subject: [PATCH] procd: Add %m to several functions that return errno. Might help with debugging. No size impact. Signed-off-by: Rosen Penev --- initd/early.c | 2 +- initd/init.c | 4 ++-- initd/preinit.c | 12 ++++++------ initd/zram.c | 8 ++++---- inittab.c | 4 ++-- jail/fs.c | 2 +- plug/coldplug.c | 4 ++-- plug/hotplug.c | 14 +++++++------- rcS.c | 2 +- service/instance.c | 12 ++++-------- state.c | 6 +++--- 11 files changed, 33 insertions(+), 37 deletions(-) diff --git a/initd/early.c b/initd/early.c index 7028ff8..00fd946 100644 --- a/initd/early.c +++ b/initd/early.c @@ -39,7 +39,7 @@ early_console(const char *dev) struct stat s; if (stat(dev, &s)) { - ERROR("Failed to stat %s\n", dev); + ERROR("Failed to stat %s: %m\n", dev); return; } diff --git a/initd/init.c b/initd/init.c index e453cff..0349e6e 100644 --- a/initd/init.c +++ b/initd/init.c @@ -90,11 +90,11 @@ main(int argc, char **argv) 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) { - ERROR("Failed to start kmodloader instance\n"); + ERROR("Failed to start kmodloader instance: %m\n"); } else { int i; diff --git a/initd/preinit.c b/initd/preinit.c index 09edb8f..fbb36df 100644 --- a/initd/preinit.c +++ b/initd/preinit.c @@ -42,7 +42,7 @@ check_dbglvl(void) 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"); @@ -134,11 +134,11 @@ preinit(void) 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) { - ERROR("Failed to start new plugd instance\n"); + ERROR("Failed to start new plugd instance: %m\n"); return; } uloop_process_add(&plugd_proc); @@ -148,7 +148,7 @@ preinit(void) 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); @@ -156,11 +156,11 @@ preinit(void) 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) { - ERROR("Failed to start new preinit instance\n"); + ERROR("Failed to start new preinit instance: %m\n"); return; } uloop_process_add(&preinit_proc); diff --git a/initd/zram.c b/initd/zram.c index d438372..b41bfd9 100644 --- a/initd/zram.c +++ b/initd/zram.c @@ -64,12 +64,12 @@ early_insmod(char *module) 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) { - ERROR("Can't exec %s\n", modprobe[0]); + ERROR("Can't exec %s: %m\n", modprobe[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); - ERROR("Can't exec %s\n", mkfs[0]); + ERROR("Can't exec %s: %m\n", mkfs[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); diff --git a/inittab.c b/inittab.c index c27c324..55554b9 100644 --- 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); - ERROR("Failed to execute %s\n", a->argv[0]); + ERROR("Failed to execute %s: %m\n", a->argv[0]); exit(-1); } @@ -278,7 +278,7 @@ void procd_inittab(void) char *line; if (!fp) { - ERROR("Failed to open %s\n", tab); + ERROR("Failed to open %s: %m\n", tab); return; } diff --git a/jail/fs.c b/jail/fs.c index 81e6c61..8cc47d3 100644 --- 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) { - ERROR("failed to mmap %s\n", path); + ERROR("failed to mmap %s: %m\n", path); ret = -1; goto out; } diff --git a/plug/coldplug.c b/plug/coldplug.c index 5fcb9a3..c6a89c3 100644 --- a/plug/coldplug.c +++ b/plug/coldplug.c @@ -54,12 +54,12 @@ void procd_coldplug(void) 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) { - ERROR("Failed to start new coldplug instance\n"); + ERROR("Failed to start new coldplug instance: %m\n"); return; } diff --git a/plug/hotplug.c b/plug/hotplug.c index d09af62..80e6e4d 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -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)) { - 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; @@ -246,7 +246,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data) 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; } @@ -255,11 +255,11 @@ send_to_kernel: 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) { - ERROR("Failed to write to %s\n", loadpath); + ERROR("Failed to write to %s: %m\n", loadpath); 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) { - ERROR("Failed to open %s\n", syspath); + ERROR("Failed to open %s: %m\n", syspath); exit(-1); } @@ -278,7 +278,7 @@ send_to_kernel: 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; } } @@ -289,7 +289,7 @@ send_to_kernel: 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); diff --git a/rcS.c b/rcS.c index b1202bf..dd3b76d 100644 --- 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) { - ERROR("Failed to create pipe\n"); + ERROR("Failed to create pipe: %m\n"); return; } diff --git a/service/instance.c b/service/instance.c index 7447bad..12c2efe 100644 --- a/service/instance.c +++ b/service/instance.c @@ -241,8 +241,7 @@ instance_removepid(struct service_instance *in) { 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; @@ -258,19 +257,16 @@ instance_writepid(struct service_instance *in) } _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) { - 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)) { - ERROR("failed to close pidfile: %s: %m", - in->pidfile); + ERROR("failed to close pidfile: %s: %m", in->pidfile); return 3; } diff --git a/state.c b/state.c index 3b56bd0..ccf4104 100644 --- 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("/")) - 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); } @@ -73,7 +73,7 @@ static void set_console(void) } if (chdir("/dev")) { - ERROR("failed to change dir to /dev\n"); + ERROR("failed to change dir to /dev: %m\n"); return; } while (tty!=NULL) { @@ -87,7 +87,7 @@ static void set_console(void) i++; } if (chdir("/")) - ERROR("failed to change dir to /\n"); + ERROR("failed to change dir to /: %m\n"); if (tty != NULL) set_stdio(tty); -- 2.30.2