From: 0x0916 Date: Fri, 23 Jun 2017 11:41:34 +0000 (+0800) Subject: Use strerror(errno) instead of %m X-Git-Tag: lxc-2.1.0~87^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1635%2Fhead;p=thirdparty%2Flxc.git Use strerror(errno) instead of %m Signed-off-by: 0x0916 --- diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c index 0d2b2031b..cb29482e4 100644 --- a/src/lxc/arguments.c +++ b/src/lxc/arguments.c @@ -259,7 +259,8 @@ int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str) errno = 0; val = strtol(str, &endptr, 10); if (errno) { - lxc_error(args, "invalid statefd '%s' : %m", str); + lxc_error(args, "invalid statefd '%s' : %s", str, + strerror(errno)); return -1; } diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 195707fa4..2d3261da0 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -54,19 +54,19 @@ int lxc_caps_down(void) caps = cap_get_proc(); if (!caps) { - ERROR("failed to cap_get_proc: %m"); + ERROR("failed to cap_get_proc: %s", strerror(errno)); return -1; } ret = cap_clear_flag(caps, CAP_EFFECTIVE); if (ret) { - ERROR("failed to cap_clear_flag: %m"); + ERROR("failed to cap_clear_flag: %s", strerror(errno)); goto out; } ret = cap_set_proc(caps); if (ret) { - ERROR("failed to cap_set_proc: %m"); + ERROR("failed to cap_set_proc: %s", strerror(errno)); goto out; } @@ -88,7 +88,7 @@ int lxc_caps_up(void) caps = cap_get_proc(); if (!caps) { - ERROR("failed to cap_get_proc: %m"); + ERROR("failed to cap_get_proc: %s", strerror(errno)); return -1; } @@ -102,21 +102,22 @@ int lxc_caps_up(void) INFO("Last supported cap was %d", cap-1); break; } else { - ERROR("failed to cap_get_flag: %m"); + ERROR("failed to cap_get_flag: %s", + strerror(errno)); goto out; } } ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, flag); if (ret) { - ERROR("failed to cap_set_flag: %m"); + ERROR("failed to cap_set_flag: %s", strerror(errno)); goto out; } } ret = cap_set_proc(caps); if (ret) { - ERROR("failed to cap_set_proc: %m"); + ERROR("failed to cap_set_proc: %s", strerror(errno)); goto out; } @@ -140,22 +141,26 @@ int lxc_caps_init(void) INFO("command is run as setuid root (uid : %d)", uid); if (prctl(PR_SET_KEEPCAPS, 1)) { - ERROR("failed to 'PR_SET_KEEPCAPS': %m"); + ERROR("failed to 'PR_SET_KEEPCAPS': %s", + strerror(errno)); return -1; } if (setresgid(gid, gid, gid)) { - ERROR("failed to change gid to '%d': %m", gid); + ERROR("failed to change gid to '%d': %s", gid, + strerror(errno)); return -1; } if (setresuid(uid, uid, uid)) { - ERROR("failed to change uid to '%d': %m", uid); + ERROR("failed to change uid to '%d': %s", uid, + strerror(errno)); return -1; } if (lxc_caps_up()) { - ERROR("failed to restore capabilities: %m"); + ERROR("failed to restore capabilities: %s", + strerror(errno)); return -1; } } diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index fd71c106d..b087f9410 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1254,13 +1254,13 @@ next: if (rmdir(dirname) < 0) { if (!r) - WARN("%s: failed to delete %s: %m", __func__, dirname); + WARN("failed to delete %s: %s", dirname, strerror(errno)); r = -1; } if (closedir(dir) < 0) { if (!r) - WARN("%s: failed to delete %s: %m", __func__, dirname); + WARN("failed to delete %s: %s", dirname, strerror(errno)); r = -1; } return r; @@ -1477,16 +1477,18 @@ static int chown_cgroup_wrapper(void *data) */ fullpath = must_make_path(path, "tasks", NULL); if (chown(fullpath, destuid, 0) < 0 && errno != ENOENT) - WARN("Failed chowning %s to %d: %m", fullpath, (int) destuid); + WARN("Failed chowning %s to %d: %s", fullpath, (int) destuid, + strerror(errno)); if (chmod(fullpath, 0664) < 0) - WARN("Error chmoding %s: %m", path); + WARN("Error chmoding %s: %s", path, strerror(errno)); free(fullpath); fullpath = must_make_path(path, "cgroup.procs", NULL); if (chown(fullpath, destuid, 0) < 0 && errno != ENOENT) - WARN("Failed chowning %s to %d: %m", fullpath, (int) destuid); + WARN("Failed chowning %s to %d: %s", fullpath, (int) destuid, + strerror(errno)); if (chmod(fullpath, 0664) < 0) - WARN("Error chmoding %s: %m", path); + WARN("Error chmoding %s: %s", path, strerror(errno)); free(fullpath); } @@ -1549,7 +1551,8 @@ static int mount_cgroup_full(int type, struct hierarchy *h, char *dest, char *source = must_make_path(h->mountpoint, h->base_cgroup, container_cgroup, NULL); char *rwpath = must_make_path(dest, h->base_cgroup, container_cgroup, NULL); if (mount(source, rwpath, "cgroup", MS_BIND, NULL) < 0) - WARN("Failed to mount %s read-write: %m", rwpath); + WARN("Failed to mount %s read-write: %s", rwpath, + strerror(errno)); INFO("Made %s read-write", rwpath); free(rwpath); free(source); diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 881a68829..8e9aa625d 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2638,9 +2638,9 @@ struct lxc_conf *lxc_conf_init(void) struct lxc_conf *new; int i; - new = malloc(sizeof(*new)); + new = malloc(sizeof(*new)); if (!new) { - ERROR("lxc_conf_init : %m"); + ERROR("lxc_conf_init : %s", strerror(errno)); return NULL; } memset(new, 0, sizeof(*new)); @@ -2662,7 +2662,7 @@ struct lxc_conf *lxc_conf_init(void) new->nbd_idx = -1; new->rootfs.mount = strdup(default_rootfs_mount); if (!new->rootfs.mount) { - ERROR("lxc_conf_init : %m"); + ERROR("lxc_conf_init : %s", strerror(errno)); free(new); return NULL; } diff --git a/src/lxc/start.c b/src/lxc/start.c index 11854f905..b7afc7bab 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -207,7 +207,7 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall, int fd_to_ignore) restart: dir = opendir("/proc/self/fd"); if (!dir) { - WARN("Failed to open directory: %m."); + WARN("Failed to open directory: %s.", strerror(errno)); return -1; } @@ -766,7 +766,7 @@ static int must_drop_cap_sys_boot(struct lxc_conf *conf) return -1; } if (wait(&status) < 0) { - SYSERROR("Unexpected wait error: %m."); + SYSERROR("Unexpected wait error: %s.", strerror(errno)); return -1; } diff --git a/src/lxc/sync.c b/src/lxc/sync.c index 7f23622eb..89cbf8a3b 100644 --- a/src/lxc/sync.c +++ b/src/lxc/sync.c @@ -40,7 +40,7 @@ static int __sync_wait(int fd, int sequence) ret = read(fd, &sync, sizeof(sync)); if (ret < 0) { - ERROR("sync wait failure : %m"); + ERROR("sync wait failure : %s", strerror(errno)); return -1; } @@ -71,7 +71,7 @@ static int __sync_wake(int fd, int sequence) int sync = sequence; if (write(fd, &sync, sizeof(sync)) < 0) { - ERROR("sync wake failure : %m"); + ERROR("sync wake failure : %s", strerror(errno)); return -1; } return 0; diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c index 9c5490e4e..07d8f1159 100644 --- a/src/lxc/tools/lxc_init.c +++ b/src/lxc/tools/lxc_init.c @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) NOTICE("about to exec '%s'", aargv[0]); execvp(aargv[0], aargv); - ERROR("failed to exec: '%s' : %m", aargv[0]); + ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno)); exit(err); } diff --git a/src/tests/reboot.c b/src/tests/reboot.c index 754984ef8..1f059e0d7 100644 --- a/src/tests/reboot.c +++ b/src/tests/reboot.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -38,7 +40,7 @@ static int do_reboot(void *arg) int *cmd = arg; if (reboot(*cmd)) - printf("failed to reboot(%d): %m\n", *cmd); + printf("failed to reboot(%d): %s\n", *cmd, strerror(errno)); return 0; } @@ -51,12 +53,12 @@ static int test_reboot(int cmd, int sig) ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd); if (ret < 0) { - printf("failed to clone: %m\n"); + printf("failed to clone: %s\n", strerror(errno)); return -1; } if (wait(&status) < 0) { - printf("unexpected wait error: %m\n"); + printf("unexpected wait error: %s\n", strerror(errno)); return -1; }