From fa5ce1c2b4fe3fa6bb4bbc6697961655b952d8d4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 25 Dec 2017 14:14:44 -0800 Subject: [PATCH] procd: Replace strerror(errno) with %m. Saves 1496 bytes from compiled size under glibc. No functional difference. Signed-off-by: Rosen Penev --- initd/zram.c | 8 ++++---- jail/capabilities.c | 2 +- jail/fs.c | 2 +- jail/jail.c | 32 ++++++++++++++++---------------- jail/seccomp.c | 4 ++-- plug/hotplug.c | 6 +++--- plug/udevtrigger.c | 4 ++-- service/instance.c | 24 ++++++++++++------------ trace/trace.c | 8 ++++---- upgraded/upgraded.c | 6 +++--- utils/utils.c | 4 ++-- watchdog.c | 6 +++--- 12 files changed, 53 insertions(+), 53 deletions(-) diff --git a/initd/zram.c b/initd/zram.c index da1795a..d438372 100644 --- a/initd/zram.c +++ b/initd/zram.c @@ -30,7 +30,7 @@ proc_meminfo(void) fp = fopen("/proc/meminfo", "r"); if (fp == NULL) { - ERROR("Can't open /proc/meminfo: %s\n", strerror(errno)); + ERROR("Can't open /proc/meminfo: %m\n"); return errno; } @@ -98,7 +98,7 @@ mount_zram_on_tmp(void) zramsize = proc_meminfo() / 2; fp = fopen("/sys/block/zram0/disksize", "r+"); if (fp == NULL) { - ERROR("Can't open /sys/block/zram0/disksize: %s\n", strerror(errno)); + ERROR("Can't open /sys/block/zram0/disksize: %m\n"); return errno; } fprintf(fp, "%ld", KB(zramsize)); @@ -118,7 +118,7 @@ mount_zram_on_tmp(void) ret = mount("/dev/zram0", "/tmp", "ext4", MS_NOSUID | MS_NODEV | MS_NOATIME, "errors=continue,noquota"); if (ret < 0) { - ERROR("Can't mount /dev/zram0 on /tmp: %s\n", strerror(errno)); + ERROR("Can't mount /dev/zram0 on /tmp: %m\n"); return errno; } @@ -126,7 +126,7 @@ mount_zram_on_tmp(void) ret = chmod("/tmp", 01777); if (ret < 0) { - ERROR("Can't set /tmp mode to 1777: %s\n", strerror(errno)); + ERROR("Can't set /tmp mode to 1777: %m\n"); return errno; } diff --git a/jail/capabilities.c b/jail/capabilities.c index b5ea965..76e06a6 100644 --- a/jail/capabilities.c +++ b/jail/capabilities.c @@ -104,7 +104,7 @@ int drop_capabilities(const char *file) if ( (capdrop & (1LLU << cap)) == 0) { DEBUG("dropping capability %s (%d)\n", capabilities_names[cap], cap); if (prctl(PR_CAPBSET_DROP, cap, 0, 0, 0)) { - ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s\n", cap, strerror(errno)); + ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %m\n", cap); return errno; } } else { diff --git a/jail/fs.c b/jail/fs.c index c4cdcc9..81e6c61 100644 --- a/jail/fs.c +++ b/jail/fs.c @@ -135,7 +135,7 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib) struct stat s; if (fstat(fd, &s) == -1) { - ERROR("fstat(%s) failed: %s\n", path, strerror(errno)); + ERROR("fstat(%s) failed: %m\n", path); ret = error; goto out; } diff --git a/jail/jail.c b/jail/jail.c index 9d7483c..54e7841 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -77,7 +77,7 @@ static int mkdir_p(char *dir, mode_t mask) return 0; if (ret) - ERROR("mkdir(%s, %d) failed: %s\n", dir, mask, strerror(errno)); + ERROR("mkdir(%s, %d) failed: %m\n", dir, mask); return ret; } @@ -89,7 +89,7 @@ int mount_bind(const char *root, const char *path, int readonly, int error) int fd; if (stat(path, &s)) { - ERROR("stat(%s) failed: %s\n", path, strerror(errno)); + ERROR("stat(%s) failed: %m\n", path); return error; } @@ -101,19 +101,19 @@ int mount_bind(const char *root, const char *path, int readonly, int error) snprintf(new, sizeof(new), "%s%s", root, path); fd = creat(new, 0644); if (fd == -1) { - ERROR("creat(%s) failed: %s\n", new, strerror(errno)); + ERROR("creat(%s) failed: %m\n", new); return -1; } close(fd); } if (mount(path, new, NULL, MS_BIND, NULL)) { - ERROR("failed to mount -B %s %s: %s\n", path, new, strerror(errno)); + ERROR("failed to mount -B %s %s: %m\n", path, new); return -1; } if (readonly && mount(NULL, new, NULL, MS_BIND | MS_REMOUNT | MS_RDONLY, NULL)) { - ERROR("failed to remount ro %s: %s\n", new, strerror(errno)); + ERROR("failed to remount ro %s: %m\n", new); return -1; } @@ -126,23 +126,23 @@ static int build_jail_fs(void) { char jail_root[] = "/tmp/ujail-XXXXXX"; if (mkdtemp(jail_root) == NULL) { - ERROR("mkdtemp(%s) failed: %s\n", jail_root, strerror(errno)); + ERROR("mkdtemp(%s) failed: %m\n", jail_root); return -1; } /* oldroot can't be MS_SHARED else pivot_root() fails */ if (mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL)) { - ERROR("private mount failed %s\n", strerror(errno)); + ERROR("private mount failed %m\n"); return -1; } if (mount("tmpfs", jail_root, "tmpfs", MS_NOATIME, "mode=0755")) { - ERROR("tmpfs mount failed %s\n", strerror(errno)); + ERROR("tmpfs mount failed %m\n"); return -1; } if (chdir(jail_root)) { - ERROR("chdir(%s) (jail_root) failed: %s\n", jail_root, strerror(errno)); + ERROR("chdir(%s) (jail_root) failed: %m\n", jail_root); return -1; } @@ -156,11 +156,11 @@ static int build_jail_fs(void) mkdir(dirbuf, 0755); if (pivot_root(jail_root, dirbuf) == -1) { - ERROR("pivot_root(%s, %s) failed: %s\n", jail_root, dirbuf, strerror(errno)); + ERROR("pivot_root(%s, %s) failed: %m\n", jail_root, dirbuf); return -1; } if (chdir("/")) { - ERROR("chdir(/) (after pivot_root) failed: %s\n", strerror(errno)); + ERROR("chdir(/) (after pivot_root) failed: %m\n"); return -1; } @@ -241,13 +241,13 @@ static int exec_jail(void *_notused) exit(EXIT_FAILURE); if (opts.no_new_privs && prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { - ERROR("prctl(PR_SET_NO_NEW_PRIVS) failed: %s\n", strerror(errno)); + ERROR("prctl(PR_SET_NO_NEW_PRIVS) failed: %m\n"); exit(EXIT_FAILURE); } if (opts.namespace && opts.hostname && strlen(opts.hostname) > 0 && sethostname(opts.hostname, strlen(opts.hostname))) { - ERROR("sethostname(%s) failed: %s\n", opts.hostname, strerror(errno)); + ERROR("sethostname(%s) failed: %m\n", opts.hostname); exit(EXIT_FAILURE); } @@ -263,7 +263,7 @@ static int exec_jail(void *_notused) INFO("exec-ing %s\n", *opts.jail_argv); execve(*opts.jail_argv, opts.jail_argv, envp); /* we get there only if execve fails */ - ERROR("failed to execve %s: %s\n", *opts.jail_argv, strerror(errno)); + ERROR("failed to execve %s: %m\n", *opts.jail_argv); exit(EXIT_FAILURE); } @@ -314,7 +314,7 @@ int main(int argc, char **argv) int ch, i; if (uid) { - ERROR("not root, aborting: %s\n", strerror(errno)); + ERROR("not root, aborting: %m\n"); return EXIT_FAILURE; } @@ -449,7 +449,7 @@ int main(int argc, char **argv) /* fork child process */ return exec_jail(NULL); } else { - ERROR("failed to clone/fork: %s\n", strerror(errno)); + ERROR("failed to clone/fork: %m\n"); return EXIT_FAILURE; } } diff --git a/jail/seccomp.c b/jail/seccomp.c index eeb5781..fae08f9 100644 --- a/jail/seccomp.c +++ b/jail/seccomp.c @@ -125,7 +125,7 @@ int install_syscall_filter(const char *argv, const char *file) set_filter(&filter[idx], BPF_RET + BPF_K, 0, 0, SECCOMP_RET_KILL); if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { - ERROR("%s: prctl(PR_SET_NO_NEW_PRIVS) failed: %s\n", argv, strerror(errno)); + ERROR("%s: prctl(PR_SET_NO_NEW_PRIVS) failed: %m\n", argv); return errno; } @@ -133,7 +133,7 @@ int install_syscall_filter(const char *argv, const char *file) prog.filter = filter; if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { - ERROR("%s: prctl(PR_SET_SECCOMP) failed: %s\n", argv, strerror(errno)); + ERROR("%s: prctl(PR_SET_SECCOMP) failed: %m\n", argv); return errno; } return 0; diff --git a/plug/hotplug.c b/plug/hotplug.c index 0905e4e..d09af62 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -591,16 +591,16 @@ void hotplug(char *rules) nls.nl_groups = -1; if ((hotplug_fd.fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT)) == -1) { - ERROR("Failed to open hotplug socket: %s\n", strerror(errno)); + ERROR("Failed to open hotplug socket: %m\n"); exit(1); } if (bind(hotplug_fd.fd, (void *)&nls, sizeof(struct sockaddr_nl))) { - ERROR("Failed to bind hotplug socket: %s\n", strerror(errno)); + ERROR("Failed to bind hotplug socket: %m\n"); exit(1); } if (setsockopt(hotplug_fd.fd, SOL_SOCKET, SO_RCVBUFFORCE, &nlbufsize, sizeof(nlbufsize))) - ERROR("Failed to resize receive buffer: %s\n", strerror(errno)); + ERROR("Failed to resize receive buffer: %m\n"); json_script_init(&jctx); queue_proc.cb = queue_proc_cb; diff --git a/plug/udevtrigger.c b/plug/udevtrigger.c index 6bb3453..f87a95e 100644 --- a/plug/udevtrigger.c +++ b/plug/udevtrigger.c @@ -94,12 +94,12 @@ static void trigger_uevent(const char *devpath) fd = open(filename, O_WRONLY); if (fd < 0) { - dbg("error on opening %s: %s\n", filename, strerror(errno)); + dbg("error on opening %s: %m\n", filename); return; } if (write(fd, "add", 3) < 0) - info("error on triggering %s: %s\n", filename, strerror(errno)); + info("error on triggering %s: %m\n", filename); close(fd); } diff --git a/service/instance.c b/service/instance.c index 35804de..25735ab 100644 --- a/service/instance.c +++ b/service/instance.c @@ -241,8 +241,8 @@ instance_removepid(struct service_instance *in) { if (!in->pidfile) return 0; if (unlink(in->pidfile)) { - ERROR("Failed to removed pidfile: %s: %d - %s\n", - in->pidfile, errno, strerror(errno)); + ERROR("Failed to removed pidfile: %s: %d - %m\n", + in->pidfile, errno); return 1; } return 0; @@ -258,19 +258,19 @@ instance_writepid(struct service_instance *in) } _pidfile = fopen(in->pidfile, "w"); if (_pidfile == NULL) { - ERROR("failed to open pidfile for writing: %s: %d (%s)", - in->pidfile, errno, strerror(errno)); + ERROR("failed to open pidfile for writing: %s: %d (%m)", + in->pidfile, errno); return 1; } if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) { - ERROR("failed to write pidfile: %s: %d (%s)", - in->pidfile, errno, strerror(errno)); + ERROR("failed to write pidfile: %s: %d (%m)", + in->pidfile, errno); fclose(_pidfile); return 2; } if (fclose(_pidfile)) { - ERROR("failed to close pidfile: %s: %d (%s)", - in->pidfile, errno, strerror(errno)); + ERROR("failed to close pidfile: %s: %d (%m)", + in->pidfile, errno); return 3; } @@ -353,11 +353,11 @@ instance_run(struct service_instance *in, int _stdout, int _stderr) } if (in->gid && setgid(in->gid)) { - ERROR("failed to set group id %d: %d (%s)\n", in->gid, errno, strerror(errno)); + ERROR("failed to set group id %d: %d (%m)\n", in->gid, errno); exit(127); } if (in->uid && setuid(in->uid)) { - ERROR("failed to set user id %d: %d (%s)\n", in->uid, errno, strerror(errno)); + ERROR("failed to set user id %d: %d (%m)\n", in->uid, errno); exit(127); } @@ -407,14 +407,14 @@ instance_start(struct service_instance *in) instance_free_stdio(in); if (in->_stdout.fd.fd > -2) { if (pipe(opipe)) { - ULOG_WARN("pipe() failed: %d (%s)\n", errno, strerror(errno)); + ULOG_WARN("pipe() failed: %d (%m)\n", errno); opipe[0] = opipe[1] = -1; } } if (in->_stderr.fd.fd > -2) { if (pipe(epipe)) { - ULOG_WARN("pipe() failed: %d (%s)\n", errno, strerror(errno)); + ULOG_WARN("pipe() failed: %d (%m)\n", errno); epipe[0] = epipe[1] = -1; } } diff --git a/trace/trace.c b/trace/trace.c index 76b6b7f..b156e2a 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -326,7 +326,7 @@ int main(int argc, char **argv, char **envp) memcpy(&_envp[newenv], envp, envc * sizeof(char *)); ret = execve(_argv[0], _argv, _envp); - ULOG_ERR("failed to exec %s: %s\n", _argv[0], strerror(errno)); + ULOG_ERR("failed to exec %s: %m\n", _argv[0]); free(_argv); free(_envp); @@ -357,11 +357,11 @@ int main(int argc, char **argv, char **envp) break; } if (ptrace(PTRACE_SEIZE, child, 0, ptrace_options) == -1) { - ULOG_ERR("PTRACE_SEIZE: %s\n", strerror(errno)); + ULOG_ERR("PTRACE_SEIZE: %m\n"); return -1; } if (ptrace(ptrace_restart, child, 0, SIGCONT) == -1) { - ULOG_ERR("ptrace_restart: %s\n", strerror(errno)); + ULOG_ERR("ptrace_restart: %m\n"); return -1; } @@ -377,7 +377,7 @@ int main(int argc, char **argv, char **envp) case UTRACE: if (!json) if (asprintf(&json, "/tmp/%s.%u.json", basename(*argv), child) < 0) - ULOG_ERR("failed to allocate output path: %s\n", strerror(errno)); + ULOG_ERR("failed to allocate output path: %m\n"); break; case SECCOMP_TRACE: if (!violation_count) diff --git a/upgraded/upgraded.c b/upgraded/upgraded.c index 220da79..0b82f20 100644 --- a/upgraded/upgraded.c +++ b/upgraded/upgraded.c @@ -74,17 +74,17 @@ int main(int argc, char **argv) int fd = open("/", O_DIRECTORY|O_PATH); if (fd < 0) { - fprintf(stderr, "unable to open prefix directory: %s\n", strerror(errno)); + fprintf(stderr, "unable to open prefix directory: %m\n"); return 1; } if (chroot(".") < 0) { - fprintf(stderr, "failed to chroot: %s\n", strerror(errno)); + fprintf(stderr, "failed to chroot: %m\n"); return 1; } if (fchdir(fd) == -1) { - fprintf(stderr, "failed to chdir to prefix directory: %s\n", strerror(errno)); + fprintf(stderr, "failed to chdir to prefix directory: %m\n"); return 1; } close(fd); diff --git a/utils/utils.c b/utils/utils.c index e239eda..57c82eb 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -203,8 +203,8 @@ int patch_stdio(const char *device) for (fd = STDIN_FILENO; fd <= STDERR_FILENO; fd++) { if (patch_fd(device, fd, fd ? O_WRONLY : O_RDONLY)) { - ERROR("Failed to redirect %s to %s: %d (%s)\n", - fdname[fd], device, errno, strerror(errno)); + ERROR("Failed to redirect %s to %s: %d (%m)\n", + fdname[fd], device, errno); rv = -1; } } diff --git a/watchdog.c b/watchdog.c index 97c8337..ec10ba6 100644 --- a/watchdog.c +++ b/watchdog.c @@ -37,7 +37,7 @@ void watchdog_ping(void) { DEBUG(4, "Ping\n"); if (wdt_fd >= 0 && write(wdt_fd, "X", 1) < 0) - ERROR("WDT failed to write: %s\n", strerror(errno)); + ERROR("WDT failed to write: %m\n"); } static void watchdog_timeout_cb(struct uloop_timeout *t) @@ -76,10 +76,10 @@ static void watchdog_close(void) return; if (write(wdt_fd, "V", 1) < 0) - ERROR("WDT failed to write release: %s\n", strerror(errno)); + ERROR("WDT failed to write release: %m\n"); if (close(wdt_fd) == -1) - ERROR("WDT failed to close watchdog: %s\n", strerror(errno)); + ERROR("WDT failed to close watchdog: %m\n"); wdt_fd = -1; } -- 2.30.2