Saves 1496 bytes from compiled size under glibc. No functional difference.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
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;
}
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));
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;
}
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;
}
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 {
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;
}
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;
}
int fd;
if (stat(path, &s)) {
- ERROR("stat(%s) failed: %s\n", path, strerror(errno));
+ ERROR("stat(%s) failed: %m\n", path);
return 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;
}
{
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;
}
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;
}
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);
}
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);
}
int ch, i;
if (uid) {
- ERROR("not root, aborting: %s\n", strerror(errno));
+ ERROR("not root, aborting: %m\n");
return EXIT_FAILURE;
}
/* 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;
}
}
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;
}
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;
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;
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);
}
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;
}
_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;
}
}
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);
}
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;
}
}
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);
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;
}
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)
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);
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;
}
}
{
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)
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;
}