Unverified Commit 28f71800 by 2xsec Committed by Christian Brauner

log: change ERROR macro using sterror to SYSERROR

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent 17e5707e
...@@ -75,19 +75,19 @@ int lxc_caps_down(void) ...@@ -75,19 +75,19 @@ int lxc_caps_down(void)
caps = cap_get_proc(); caps = cap_get_proc();
if (!caps) { if (!caps) {
ERROR("failed to cap_get_proc: %s", strerror(errno)); SYSERROR("Failed to cap_get_proc");
return -1; return -1;
} }
ret = cap_clear_flag(caps, CAP_EFFECTIVE); ret = cap_clear_flag(caps, CAP_EFFECTIVE);
if (ret) { if (ret) {
ERROR("failed to cap_clear_flag: %s", strerror(errno)); SYSERROR("Failed to cap_clear_flag");
goto out; goto out;
} }
ret = cap_set_proc(caps); ret = cap_set_proc(caps);
if (ret) { if (ret) {
ERROR("failed to cap_set_proc: %s", strerror(errno)); SYSERROR("Failed to cap_set_proc");
goto out; goto out;
} }
...@@ -109,7 +109,7 @@ int lxc_caps_up(void) ...@@ -109,7 +109,7 @@ int lxc_caps_up(void)
caps = cap_get_proc(); caps = cap_get_proc();
if (!caps) { if (!caps) {
ERROR("failed to cap_get_proc: %s", strerror(errno)); SYSERROR("Failed to cap_get_proc");
return -1; return -1;
} }
...@@ -123,22 +123,21 @@ int lxc_caps_up(void) ...@@ -123,22 +123,21 @@ int lxc_caps_up(void)
INFO("Last supported cap was %d", cap-1); INFO("Last supported cap was %d", cap-1);
break; break;
} else { } else {
ERROR("failed to cap_get_flag: %s", SYSERROR("Failed to cap_get_flag");
strerror(errno));
goto out; goto out;
} }
} }
ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, flag); ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, flag);
if (ret) { if (ret) {
ERROR("failed to cap_set_flag: %s", strerror(errno)); SYSERROR("Failed to cap_set_flag");
goto out; goto out;
} }
} }
ret = cap_set_proc(caps); ret = cap_set_proc(caps);
if (ret) { if (ret) {
ERROR("failed to cap_set_proc: %s", strerror(errno)); SYSERROR("Failed to cap_set_proc");
goto out; goto out;
} }
...@@ -270,26 +269,22 @@ int lxc_caps_init(void) ...@@ -270,26 +269,22 @@ int lxc_caps_init(void)
INFO("command is run as setuid root (uid : %d)", uid); INFO("command is run as setuid root (uid : %d)", uid);
if (prctl(PR_SET_KEEPCAPS, 1)) { if (prctl(PR_SET_KEEPCAPS, 1)) {
ERROR("failed to 'PR_SET_KEEPCAPS': %s", SYSERROR("Failed to 'PR_SET_KEEPCAPS'");
strerror(errno));
return -1; return -1;
} }
if (setresgid(gid, gid, gid)) { if (setresgid(gid, gid, gid)) {
ERROR("failed to change gid to '%d': %s", gid, SYSERROR("Failed to change gid to '%d'", gid);
strerror(errno));
return -1; return -1;
} }
if (setresuid(uid, uid, uid)) { if (setresuid(uid, uid, uid)) {
ERROR("failed to change uid to '%d': %s", uid, SYSERROR("Failed to change uid to '%d'", uid);
strerror(errno));
return -1; return -1;
} }
if (lxc_caps_up()) { if (lxc_caps_up()) {
ERROR("failed to restore capabilities: %s", SYSERROR("Failed to restore capabilities");
strerror(errno));
return -1; return -1;
} }
} }
...@@ -350,7 +345,7 @@ static bool lxc_cap_is_set(cap_t caps, cap_value_t cap, cap_flag_t flag) ...@@ -350,7 +345,7 @@ static bool lxc_cap_is_set(cap_t caps, cap_value_t cap, cap_flag_t flag)
ret = cap_get_flag(caps, cap, flag, &flagval); ret = cap_get_flag(caps, cap, flag, &flagval);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to perform cap_get_flag(): %s.", strerror(errno)); SYSERROR("Failed to perform cap_get_flag()");
return false; return false;
} }
...@@ -371,7 +366,8 @@ bool lxc_file_cap_is_set(const char *path, cap_value_t cap, cap_flag_t flag) ...@@ -371,7 +366,8 @@ bool lxc_file_cap_is_set(const char *path, cap_value_t cap, cap_flag_t flag)
* case errno will be set to ENODATA. * case errno will be set to ENODATA.
*/ */
if (errno != ENODATA) if (errno != ENODATA)
ERROR("Failed to perform cap_get_file(): %s.\n", strerror(errno)); SYSERROR("Failed to perform cap_get_file()");
return false; return false;
} }
...@@ -391,7 +387,7 @@ bool lxc_proc_cap_is_set(cap_value_t cap, cap_flag_t flag) ...@@ -391,7 +387,7 @@ bool lxc_proc_cap_is_set(cap_value_t cap, cap_flag_t flag)
caps = cap_get_proc(); caps = cap_get_proc();
if (!caps) { if (!caps) {
ERROR("Failed to perform cap_get_proc(): %s.\n", strerror(errno)); SYSERROR("Failed to perform cap_get_proc()");
return false; return false;
} }
......
...@@ -356,7 +356,7 @@ int main(int argc, char *argv[]) ...@@ -356,7 +356,7 @@ int main(int argc, char *argv[])
NOTICE("Exec'ing \"%s\"", my_args.argv[0]); NOTICE("Exec'ing \"%s\"", my_args.argv[0]);
ret = execvp(my_args.argv[0], my_args.argv); ret = execvp(my_args.argv[0], my_args.argv);
ERROR("%s - Failed to exec \"%s\"", strerror(errno), my_args.argv[0]); SYSERROR("Failed to exec \"%s\"", my_args.argv[0]);
exit(ret); exit(ret);
} }
...@@ -443,8 +443,7 @@ int main(int argc, char *argv[]) ...@@ -443,8 +443,7 @@ int main(int argc, char *argv[])
if (errno == EINTR) if (errno == EINTR)
continue; continue;
ERROR("%s - Failed to wait on child %d", SYSERROR("Failed to wait on child %d", pid);
strerror(errno), pid);
goto out; goto out;
} }
......
...@@ -241,7 +241,7 @@ static int lxc_monitord_sock_create(struct lxc_monitor *mon) ...@@ -241,7 +241,7 @@ static int lxc_monitord_sock_create(struct lxc_monitor *mon)
fd = lxc_abstract_unix_open(addr.sun_path, SOCK_STREAM, O_TRUNC); fd = lxc_abstract_unix_open(addr.sun_path, SOCK_STREAM, O_TRUNC);
if (fd < 0) { if (fd < 0) {
ERROR("Failed to open unix socket: %s.", strerror(errno)); SYSERROR("Failed to open unix socket");
return -1; return -1;
} }
...@@ -307,8 +307,8 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data, ...@@ -307,8 +307,8 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
for (i = 0; i < mon->clientfds_cnt; i++) { for (i = 0; i < mon->clientfds_cnt; i++) {
ret = write(mon->clientfds[i], &msglxc, sizeof(msglxc)); ret = write(mon->clientfds[i], &msglxc, sizeof(msglxc));
if (ret < 0) if (ret < 0)
ERROR("Failed to send message to client file descriptor %d: %s.", SYSERROR("Failed to send message to client file descriptor %d",
mon->clientfds[i], strerror(errno)); mon->clientfds[i]);
} }
return LXC_MAINLOOP_CONTINUE; return LXC_MAINLOOP_CONTINUE;
......
...@@ -165,9 +165,8 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) ...@@ -165,9 +165,8 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd)
if ((rsp->datalen > LXC_CMD_DATA_MAX) && if ((rsp->datalen > LXC_CMD_DATA_MAX) &&
(cmd->req.cmd != LXC_CMD_CONSOLE_LOG)) { (cmd->req.cmd != LXC_CMD_CONSOLE_LOG)) {
errno = EFBIG; errno = EFBIG;
ERROR("%s - Response data for command \"%s\" is too long: %d " SYSERROR("Response data for command \"%s\" is too long: %d bytes > %d",
"bytes > %d", strerror(errno), lxc_cmd_str(cmd->req.cmd), lxc_cmd_str(cmd->req.cmd), rsp->datalen, LXC_CMD_DATA_MAX);
rsp->datalen, LXC_CMD_DATA_MAX);
return -EFBIG; return -EFBIG;
} }
...@@ -179,15 +178,15 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) ...@@ -179,15 +178,15 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd)
} }
if (!rsp->data) { if (!rsp->data) {
errno = ENOMEM; errno = ENOMEM;
ERROR("%s - Failed to allocate response buffer for command " SYSERROR("Failed to allocate response buffer for command \"%s\"",
"\"%s\"", strerror(errno), lxc_cmd_str(cmd->req.cmd)); lxc_cmd_str(cmd->req.cmd));
return -ENOMEM; return -ENOMEM;
} }
ret = recv(sock, rsp->data, rsp->datalen, 0); ret = recv(sock, rsp->data, rsp->datalen, 0);
if (ret != rsp->datalen) { if (ret != rsp->datalen) {
ERROR("%s - Failed to receive response data for command \"%s\"", SYSERROR("Failed to receive response data for command \"%s\"",
lxc_cmd_str(cmd->req.cmd), strerror(errno)); lxc_cmd_str(cmd->req.cmd));
if (ret >= 0) if (ret >= 0)
ret = -1; ret = -1;
} }
...@@ -209,8 +208,7 @@ static int lxc_cmd_rsp_send(int fd, struct lxc_cmd_rsp *rsp) ...@@ -209,8 +208,7 @@ static int lxc_cmd_rsp_send(int fd, struct lxc_cmd_rsp *rsp)
ret = send(fd, rsp, sizeof(*rsp), 0); ret = send(fd, rsp, sizeof(*rsp), 0);
if (ret < 0 || (size_t)ret != sizeof(*rsp)) { if (ret < 0 || (size_t)ret != sizeof(*rsp)) {
ERROR("%s - Failed to send command response %zd", SYSERROR("Failed to send command response %zd", ret);
strerror(errno), ret);
return -1; return -1;
} }
...@@ -621,8 +619,8 @@ int lxc_cmd_stop(const char *name, const char *lxcpath) ...@@ -621,8 +619,8 @@ int lxc_cmd_stop(const char *name, const char *lxcpath)
* closed. * closed.
*/ */
if (ret > 0) { if (ret > 0) {
ERROR("%s - Failed to stop container \"%s\"", errno = -cmd.rsp.ret;
strerror(-cmd.rsp.ret), name); SYSERROR("Failed to stop container \"%s\"", name);
return -1; return -1;
} }
...@@ -713,7 +711,8 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath) ...@@ -713,7 +711,8 @@ int lxc_cmd_console(const char *name, int *ttynum, int *fd, const char *lxcpath)
return ret; return ret;
if (cmd.rsp.ret < 0) { if (cmd.rsp.ret < 0) {
ERROR("%s - Denied access to tty", strerror(-cmd.rsp.ret)); errno = -cmd.rsp.ret;
SYSERROR("Denied access to tty");
ret = -1; ret = -1;
goto out; goto out;
} }
...@@ -865,7 +864,8 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath, ...@@ -865,7 +864,8 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath,
if (ret < 0) { if (ret < 0) {
if (errno != ECONNREFUSED) if (errno != ECONNREFUSED)
ERROR("%s - Failed to execute command", strerror(errno)); SYSERROR("Failed to execute command");
return -1; return -1;
} }
...@@ -873,7 +873,8 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath, ...@@ -873,7 +873,8 @@ int lxc_cmd_add_state_client(const char *name, const char *lxcpath,
* function. * function.
*/ */
if (cmd.rsp.ret < 0) { if (cmd.rsp.ret < 0) {
ERROR("%s - Failed to receive socket fd", strerror(-cmd.rsp.ret)); errno = -cmd.rsp.ret;
SYSERROR("Failed to receive socket fd");
return -1; return -1;
} }
...@@ -1012,7 +1013,7 @@ int lxc_cmd_serve_state_clients(const char *name, const char *lxcpath, ...@@ -1012,7 +1013,7 @@ int lxc_cmd_serve_state_clients(const char *name, const char *lxcpath,
ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL); ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to execute command", strerror(errno)); SYSERROR("Failed to execute command");
return -1; return -1;
} }
...@@ -1246,10 +1247,10 @@ int lxc_cmd_init(const char *name, const char *lxcpath, const char *suffix) ...@@ -1246,10 +1247,10 @@ int lxc_cmd_init(const char *name, const char *lxcpath, const char *suffix)
fd = lxc_abstract_unix_open(path, SOCK_STREAM, 0); fd = lxc_abstract_unix_open(path, SOCK_STREAM, 0);
if (fd < 0) { if (fd < 0) {
ERROR("%s - Failed to create command socket %s", SYSERROR("Failed to create command socket %s", offset);
strerror(errno), offset);
if (errno == EADDRINUSE) if (errno == EADDRINUSE)
ERROR("Container \"%s\" appears to be already running", name); ERROR("Container \"%s\" appears to be already running", name);
return -1; return -1;
} }
......
...@@ -69,7 +69,7 @@ again: ...@@ -69,7 +69,7 @@ again:
goto again; goto again;
} }
ERROR("Failed to receive message: %s", strerror(errno)); SYSERROR("Failed to receive message");
return -1; return -1;
} }
......
...@@ -932,7 +932,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf) ...@@ -932,7 +932,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
*/ */
ret = mknod(path, S_IFREG | 0000, 0); ret = mknod(path, S_IFREG | 0000, 0);
if (ret < 0) /* this isn't fatal, continue */ if (ret < 0) /* this isn't fatal, continue */
ERROR("%s - Failed to create \"%s\"", strerror(errno), path); SYSERROR("Failed to create \"%s\"", path);
ret = mount(tty->name, path, "none", MS_BIND, 0); ret = mount(tty->name, path, "none", MS_BIND, 0);
if (ret < 0) { if (ret < 0) {
...@@ -1053,8 +1053,7 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler) ...@@ -1053,8 +1053,7 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
} }
if (ret < 0) if (ret < 0)
ERROR("Failed to send %zu ttys to parent: %s", ttys->max, SYSERROR("Failed to send %zu ttys to parent", ttys->max);
strerror(errno));
else else
TRACE("Sent %zu ttys to parent", ttys->max); TRACE("Sent %zu ttys to parent", ttys->max);
...@@ -1659,7 +1658,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, ...@@ -1659,7 +1658,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
if (file_exists(path)) { if (file_exists(path)) {
ret = lxc_unstack_mountpoint(path, false); ret = lxc_unstack_mountpoint(path, false);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to unmount \"%s\": %s", path, strerror(errno)); SYSERROR("Failed to unmount \"%s\"", path);
return -ret; return -ret;
} else { } else {
DEBUG("Cleared all (%d) mounts from \"%s\"", ret, path); DEBUG("Cleared all (%d) mounts from \"%s\"", ret, path);
...@@ -1738,7 +1737,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs, ...@@ -1738,7 +1737,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
if (file_exists(path)) { if (file_exists(path)) {
ret = lxc_unstack_mountpoint(path, false); ret = lxc_unstack_mountpoint(path, false);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to unmount \"%s\"", strerror(errno), path); SYSERROR("Failed to unmount \"%s\"", path);
return -ret; return -ret;
} else { } else {
DEBUG("Cleared all (%d) mounts from \"%s\"", ret, path); DEBUG("Cleared all (%d) mounts from \"%s\"", ret, path);
...@@ -2529,8 +2528,7 @@ int setup_resource_limits(struct lxc_list *limits, pid_t pid) ...@@ -2529,8 +2528,7 @@ int setup_resource_limits(struct lxc_list *limits, pid_t pid)
#if HAVE_PRLIMIT || HAVE_PRLIMIT64 #if HAVE_PRLIMIT || HAVE_PRLIMIT64
if (prlimit(pid, resid, &lim->limit, NULL) != 0) { if (prlimit(pid, resid, &lim->limit, NULL) != 0) {
ERROR("Failed to set limit %s: %s", lim->resource, SYSERROR("Failed to set limit %s", lim->resource);
strerror(errno));
return -1; return -1;
} }
#else #else
......
...@@ -2208,8 +2208,9 @@ static int set_config_namespace_clone(const char *key, const char *value, ...@@ -2208,8 +2208,9 @@ static int set_config_namespace_clone(const char *key, const char *value,
return clr_config_namespace_clone(key, lxc_conf, data); return clr_config_namespace_clone(key, lxc_conf, data);
if (lxc_conf->ns_keep != 0) { if (lxc_conf->ns_keep != 0) {
ERROR("%s - Cannot set both \"lxc.namespace.clone\" and " errno = EINVAL;
"\"lxc.namespace.keep\"", strerror(EINVAL)); SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
"\"lxc.namespace.keep\"");
return -EINVAL; return -EINVAL;
} }
...@@ -2244,8 +2245,9 @@ static int set_config_namespace_keep(const char *key, const char *value, ...@@ -2244,8 +2245,9 @@ static int set_config_namespace_keep(const char *key, const char *value,
return clr_config_namespace_keep(key, lxc_conf, data); return clr_config_namespace_keep(key, lxc_conf, data);
if (lxc_conf->ns_clone != 0) { if (lxc_conf->ns_clone != 0) {
ERROR("%s - Cannot set both \"lxc.namespace.clone\" and " errno = EINVAL;
"\"lxc.namespace.keep\"", strerror(EINVAL)); SYSERROR("Cannot set both \"lxc.namespace.clone\" and "
"\"lxc.namespace.keep\"");
return -EINVAL; return -EINVAL;
} }
...@@ -4139,8 +4141,9 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -4139,8 +4141,9 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* parse current index */ /* parse current index */
ret = lxc_safe_uint((idx_start + 1), &tmpidx); ret = lxc_safe_uint((idx_start + 1), &tmpidx);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to parse usigned integer from string \"%s\": %s", errno = -ret;
idx_start + 1, strerror(-ret)); SYSERROR("Failed to parse usigned integer from string \"%s\"",
idx_start + 1);
*idx = ret; *idx = ret;
goto on_error; goto on_error;
} }
......
...@@ -743,8 +743,7 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid, ...@@ -743,8 +743,7 @@ static int lxc_container_name_to_pid(const char *lxcname_or_pid,
ret = kill(pid, 0); ret = kill(pid, 0);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to send signal to pid %d", strerror(errno), SYSERROR("Failed to send signal to pid %d", (int)pid);
(int)pid);
return -EPERM; return -EPERM;
} }
......
...@@ -983,7 +983,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -983,7 +983,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
ret = resolve_clone_flags(handler); ret = resolve_clone_flags(handler);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Unsupported clone flag specified", strerror(errno)); SYSERROR("Unsupported clone flag specified");
goto out_fini_handler; goto out_fini_handler;
} }
......
...@@ -416,8 +416,7 @@ static int log_open(const char *name) ...@@ -416,8 +416,7 @@ static int log_open(const char *name)
fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY | fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY |
O_APPEND | O_CLOEXEC, 0666)); O_APPEND | O_CLOEXEC, 0666));
if (fd == -1) { if (fd == -1) {
ERROR("failed to open log file \"%s\" : %s", name, SYSERROR("Failed to open log file \"%s\"", name);
strerror(errno));
return -1; return -1;
} }
...@@ -426,7 +425,7 @@ static int log_open(const char *name) ...@@ -426,7 +425,7 @@ static int log_open(const char *name)
newfd = fcntl(fd, F_DUPFD_CLOEXEC, 3); newfd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (newfd == -1) if (newfd == -1)
ERROR("failed to dup log fd %d : %s", fd, strerror(errno)); SYSERROR("Failed to dup log fd %d", fd);
close(fd); close(fd);
return newfd; return newfd;
...@@ -528,8 +527,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs) ...@@ -528,8 +527,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs)
if (create_dirs) if (create_dirs)
#endif #endif
if (build_dir(fname)) { if (build_dir(fname)) {
ERROR("failed to create dir for log file \"%s\" : %s", fname, SYSERROR("Failed to create dir for log file \"%s\"", fname);
strerror(errno));
return -1; return -1;
} }
...@@ -704,8 +702,7 @@ extern int lxc_log_set_file(int *fd, const char *fname) ...@@ -704,8 +702,7 @@ extern int lxc_log_set_file(int *fd, const char *fname)
} }
if (build_dir(fname)) { if (build_dir(fname)) {
ERROR("failed to create dir for log file \"%s\" : %s", fname, SYSERROR("Failed to create dir for log file \"%s\"", fname);
strerror(errno));
return -1; return -1;
} }
......
...@@ -2628,21 +2628,24 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc ...@@ -2628,21 +2628,24 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
if (n == 1 && v == 0) { if (n == 1 && v == 0) {
ret = remove(path); ret = remove(path);
if (ret < 0) if (ret < 0)
ERROR("%s - Failed to remove \"%s\"", SYSERROR("Failed to remove \"%s\"", path);
strerror(errno), path);
n = 0; n = 0;
} }
} }
if (n == 1) { if (n == 1) {
v += inc ? 1 : -1; v += inc ? 1 : -1;
f1 = fopen(path, "w"); f1 = fopen(path, "w");
if (!f1) if (!f1)
goto out; goto out;
if (fprintf(f1, "%d\n", v) < 0) { if (fprintf(f1, "%d\n", v) < 0) {
ERROR("Error writing new snapshots value"); ERROR("Error writing new snapshots value");
fclose(f1); fclose(f1);
goto out; goto out;
} }
ret = fclose(f1); ret = fclose(f1);
if (ret != 0) { if (ret != 0) {
SYSERROR("Error writing to or closing snapshots file"); SYSERROR("Error writing to or closing snapshots file");
...@@ -2679,7 +2682,6 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc ...@@ -2679,7 +2682,6 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
} }
if (fbuf.st_size != 0) { if (fbuf.st_size != 0) {
buf = lxc_strmmap(NULL, fbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); buf = lxc_strmmap(NULL, fbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buf == MAP_FAILED) { if (buf == MAP_FAILED) {
SYSERROR("Failed to create mapping %s", path); SYSERROR("Failed to create mapping %s", path);
...@@ -2706,11 +2708,11 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc ...@@ -2706,11 +2708,11 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
/* If the lxc-snapshot file is empty, remove it. */ /* If the lxc-snapshot file is empty, remove it. */
if (stat(path, &fbuf) < 0) if (stat(path, &fbuf) < 0)
goto out; goto out;
if (!fbuf.st_size) { if (!fbuf.st_size) {
ret = remove(path); ret = remove(path);
if (ret < 0) if (ret < 0)
SYSERROR("Failed to remove \"%s\"", path); SYSERROR("Failed to remove \"%s\"", path);
} }
} }
...@@ -4415,7 +4417,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add, ...@@ -4415,7 +4417,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
if(ret == 0) { if(ret == 0) {
ret = unlink(path); ret = unlink(path);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to remove \"%s\"", strerror(errno), path); SYSERROR("Failed to remove \"%s\"", path);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
} }
...@@ -4431,7 +4433,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add, ...@@ -4431,7 +4433,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
directory_path = dirname(tmp); directory_path = dirname(tmp);
ret = mkdir_p(directory_path, 0755); ret = mkdir_p(directory_path, 0755);
if (ret < 0 && errno != EEXIST) { if (ret < 0 && errno != EEXIST) {
ERROR("%s - Failed to create path \"%s\"", strerror(errno), directory_path); SYSERROR("Failed to create path \"%s\"", directory_path);
free(tmp); free(tmp);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
...@@ -4440,7 +4442,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add, ...@@ -4440,7 +4442,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
ret = mknod(path, st->st_mode, st->st_rdev); ret = mknod(path, st->st_mode, st->st_rdev);
free(tmp); free(tmp);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to create device node at \"%s\"", strerror(errno), path); SYSERROR("Failed to create device node at \"%s\"", path);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
......
...@@ -221,7 +221,7 @@ int lxc_monitor_open(const char *lxcpath) ...@@ -221,7 +221,7 @@ int lxc_monitor_open(const char *lxcpath)
DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len); DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len);
if (len >= sizeof(addr.sun_path) - 1) { if (len >= sizeof(addr.sun_path) - 1) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
ERROR("name of monitor socket too long (%zu bytes): %s", len, strerror(errno)); SYSERROR("The name of monitor socket too long (%zu bytes)", len);
return -1; return -1;
} }
...@@ -229,12 +229,13 @@ int lxc_monitor_open(const char *lxcpath) ...@@ -229,12 +229,13 @@ int lxc_monitor_open(const char *lxcpath)
fd = lxc_abstract_unix_connect(addr.sun_path); fd = lxc_abstract_unix_connect(addr.sun_path);
if (fd != -1 || errno != ECONNREFUSED) if (fd != -1 || errno != ECONNREFUSED)
break; break;
ERROR("Failed to connect to monitor socket. Retrying in %d ms: %s", backoff_ms[retry], strerror(errno));
SYSERROR("Failed to connect to monitor socket. Retrying in %d ms", backoff_ms[retry]);
usleep(backoff_ms[retry] * 1000); usleep(backoff_ms[retry] * 1000);
} }
if (fd < 0) { if (fd < 0) {
ERROR("Failed to connect to monitor socket: %s.", strerror(errno)); SYSERROR("Failed to connect to monitor socket");
return -1; return -1;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define _GNU_SOURCE
#include <alloca.h> #include <alloca.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -66,7 +67,7 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags) ...@@ -66,7 +67,7 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg); ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg);
#endif #endif
if (ret < 0) if (ret < 0)
ERROR("Failed to clone (%#x): %s.", flags, strerror(errno)); SYSERROR("Failed to clone (%#x)", flags);
return ret; return ret;
} }
......
...@@ -133,8 +133,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -133,8 +133,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
err = lxc_veth_create(veth1, veth2); err = lxc_veth_create(veth1, veth2);
if (err) { if (err) {
ERROR("Failed to create veth pair \"%s\" and \"%s\": %s", veth1, errno = -err;
veth2, strerror(-err)); SYSERROR("Failed to create veth pair \"%s\" and \"%s\"", veth1, veth2);
goto out_delete; goto out_delete;
} }
...@@ -143,8 +143,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -143,8 +143,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
* of a container */ * of a container */
err = setup_private_host_hw_addr(veth1); err = setup_private_host_hw_addr(veth1);
if (err) { if (err) {
ERROR("Failed to change mac address of host interface \"%s\": %s", errno = -err;
veth1, strerror(-err)); SYSERROR("Failed to change mac address of host interface \"%s\"", veth1);
goto out_delete; goto out_delete;
} }
...@@ -186,10 +186,11 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -186,10 +186,11 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
err = lxc_netdev_set_mtu(veth1, mtu); err = lxc_netdev_set_mtu(veth1, mtu);
if (!err) if (!err)
err = lxc_netdev_set_mtu(veth2, mtu); err = lxc_netdev_set_mtu(veth2, mtu);
if (err) { if (err) {
ERROR("Failed to set mtu \"%d\" for veth pair \"%s\" " errno = -err;
"and \"%s\": %s", SYSERROR("Failed to set mtu \"%d\" for veth pair \"%s\" "
mtu, veth1, veth2, strerror(-err)); "and \"%s\"", mtu, veth1, veth2);
goto out_delete; goto out_delete;
} }
} }
...@@ -197,8 +198,9 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -197,8 +198,9 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
if (netdev->link[0] != '\0') { if (netdev->link[0] != '\0') {
err = lxc_bridge_attach(netdev->link, veth1); err = lxc_bridge_attach(netdev->link, veth1);
if (err) { if (err) {
ERROR("Failed to attach \"%s\" to bridge \"%s\": %s", errno = -err;
veth1, netdev->link, strerror(-err)); SYSERROR("Failed to attach \"%s\" to bridge \"%s\"",
veth1, netdev->link);
goto out_delete; goto out_delete;
} }
INFO("Attached \"%s\" to bridge \"%s\"", veth1, netdev->link); INFO("Attached \"%s\" to bridge \"%s\"", veth1, netdev->link);
...@@ -206,7 +208,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -206,7 +208,8 @@ static int instantiate_veth(struct lxc_handler *handler, struct lxc_netdev *netd
err = lxc_netdev_up(veth1); err = lxc_netdev_up(veth1);
if (err) { if (err) {
ERROR("Failed to set \"%s\" up: %s", veth1, strerror(-err)); errno = -err;
SYSERROR("Failed to set \"%s\" up", veth1);
goto out_delete; goto out_delete;
} }
...@@ -257,8 +260,9 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n ...@@ -257,8 +260,9 @@ static int instantiate_macvlan(struct lxc_handler *handler, struct lxc_netdev *n
err = lxc_macvlan_create(netdev->link, peer, err = lxc_macvlan_create(netdev->link, peer,
netdev->priv.macvlan_attr.mode); netdev->priv.macvlan_attr.mode);
if (err) { if (err) {
ERROR("Failed to create macvlan interface \"%s\" on \"%s\": %s", errno = -err;
peer, netdev->link, strerror(-err)); SYSERROR("Failed to create macvlan interface \"%s\" on \"%s\"",
peer, netdev->link);
goto on_error; goto on_error;
} }
...@@ -310,8 +314,9 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -310,8 +314,9 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
err = lxc_vlan_create(netdev->link, peer, netdev->priv.vlan_attr.vid); err = lxc_vlan_create(netdev->link, peer, netdev->priv.vlan_attr.vid);
if (err) { if (err) {
ERROR("Failed to create vlan interface \"%s\" on \"%s\": %s", errno = -err;
peer, netdev->link, strerror(-err)); SYSERROR("Failed to create vlan interface \"%s\" on \"%s\"",
peer, netdev->link);
return -1; return -1;
} }
...@@ -331,10 +336,12 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd ...@@ -331,10 +336,12 @@ static int instantiate_vlan(struct lxc_handler *handler, struct lxc_netdev *netd
netdev->name[0] != '\0' ? netdev->name : "(null)"); netdev->name[0] != '\0' ? netdev->name : "(null)");
return -1; return -1;
} }
err = lxc_netdev_set_mtu(peer, mtu); err = lxc_netdev_set_mtu(peer, mtu);
if (err) { if (err) {
ERROR("Failed to set mtu \"%s\" for \"%s\": %s", errno = -err;
netdev->mtu, peer, strerror(-err)); SYSERROR("Failed to set mtu \"%s\" for \"%s\"",
netdev->mtu, peer);
lxc_netdev_delete_by_name(peer); lxc_netdev_delete_by_name(peer);
return -1; return -1;
} }
...@@ -1971,7 +1978,7 @@ char *lxc_mkifname(char *template) ...@@ -1971,7 +1978,7 @@ char *lxc_mkifname(char *template)
/* Get all the network interfaces. */ /* Get all the network interfaces. */
ret = getifaddrs(&ifaddr); ret = getifaddrs(&ifaddr);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to get network interfaces", strerror(errno)); SYSERROR("Failed to get network interfaces");
return NULL; return NULL;
} }
...@@ -2215,8 +2222,8 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna ...@@ -2215,8 +2222,8 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
ret = lxc_safe_int(token, &netdev->ifindex); ret = lxc_safe_int(token, &netdev->ifindex);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to convert string \"%s\" to integer", errno = -ret;
strerror(-ret), token); SYSERROR("Failed to convert string \"%s\" to integer", token);
return -1; return -1;
} }
...@@ -2243,8 +2250,8 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna ...@@ -2243,8 +2250,8 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
ret = lxc_safe_int(token, &netdev->priv.veth_attr.ifindex); ret = lxc_safe_int(token, &netdev->priv.veth_attr.ifindex);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to convert string \"%s\" to integer", errno = -ret;
strerror(-ret), token); SYSERROR("Failed to convert string \"%s\" to integer", token);
return -1; return -1;
} }
...@@ -2504,9 +2511,9 @@ int lxc_network_move_created_netdev_priv(const char *lxcpath, const char *lxcnam ...@@ -2504,9 +2511,9 @@ int lxc_network_move_created_netdev_priv(const char *lxcpath, const char *lxcnam
ret = lxc_netdev_move_by_name(ifname, pid, NULL); ret = lxc_netdev_move_by_name(ifname, pid, NULL);
if (ret) { if (ret) {
ERROR("Failed to move network device \"%s\" to " errno = -ret;
"network namespace %d: %s", ifname, pid, SYSERROR("Failed to move network device \"%s\" to "
strerror(-ret)); "network namespace %d", ifname, pid);
return -1; return -1;
} }
...@@ -2756,12 +2763,12 @@ static int setup_hw_addr(char *hwaddr, const char *ifname) ...@@ -2756,12 +2763,12 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
{ {
struct sockaddr sockaddr; struct sockaddr sockaddr;
struct ifreq ifr; struct ifreq ifr;
int ret, fd, saved_errno; int ret, fd;
ret = lxc_convert_mac(hwaddr, &sockaddr); ret = lxc_convert_mac(hwaddr, &sockaddr);
if (ret) { if (ret) {
ERROR("Mac address \"%s\" conversion failed: %s", hwaddr, errno = -ret;
strerror(-ret)); SYSERROR("Mac address \"%s\" conversion failed", hwaddr);
return -1; return -1;
} }
...@@ -2774,10 +2781,10 @@ static int setup_hw_addr(char *hwaddr, const char *ifname) ...@@ -2774,10 +2781,10 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
return -1; return -1;
ret = ioctl(fd, SIOCSIFHWADDR, &ifr); ret = ioctl(fd, SIOCSIFHWADDR, &ifr);
saved_errno = errno;
close(fd);
if (ret) if (ret)
ERROR("Failed to perform ioctl: %s", strerror(saved_errno)); SYSERROR("Failed to perform ioctl");
close(fd);
DEBUG("Mac address \"%s\" on \"%s\" has been setup", hwaddr, DEBUG("Mac address \"%s\" on \"%s\" has been setup", hwaddr,
ifr.ifr_name); ifr.ifr_name);
...@@ -2796,8 +2803,9 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex) ...@@ -2796,8 +2803,9 @@ static int setup_ipv4_addr(struct lxc_list *ip, int ifindex)
err = lxc_ipv4_addr_add(ifindex, &inetdev->addr, err = lxc_ipv4_addr_add(ifindex, &inetdev->addr,
&inetdev->bcast, inetdev->prefix); &inetdev->bcast, inetdev->prefix);
if (err) { if (err) {
ERROR("Failed to setup ipv4 address for network device " errno = -err;
"with eifindex %d: %s", ifindex, strerror(-err)); SYSERROR("Failed to setup ipv4 address for network device "
"with eifindex %d", ifindex);
return -1; return -1;
} }
} }
...@@ -2817,8 +2825,9 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex) ...@@ -2817,8 +2825,9 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex)
&inet6dev->mcast, &inet6dev->acast, &inet6dev->mcast, &inet6dev->acast,
inet6dev->prefix); inet6dev->prefix);
if (err) { if (err) {
ERROR("Failed to setup ipv6 address for network device " errno = -err;
"with eifindex %d: %s", ifindex, strerror(-err)); SYSERROR("Failed to setup ipv6 address for network device "
"with eifindex %d", ifindex);
return -1; return -1;
} }
} }
...@@ -2838,9 +2847,8 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) ...@@ -2838,9 +2847,8 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
if (netdev->flags & IFF_UP) { if (netdev->flags & IFF_UP) {
err = lxc_netdev_up("lo"); err = lxc_netdev_up("lo");
if (err) { if (err) {
ERROR("Failed to set the loopback network " errno = -err;
"device up: %s", SYSERROR("Failed to set the loopback network device up");
strerror(-err));
return -1; return -1;
} }
} }
...@@ -2893,8 +2901,9 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) ...@@ -2893,8 +2901,9 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
if (strcmp(ifname, netdev->name) != 0) { if (strcmp(ifname, netdev->name) != 0) {
err = lxc_netdev_rename_by_name(ifname, netdev->name); err = lxc_netdev_rename_by_name(ifname, netdev->name);
if (err) { if (err) {
ERROR("Failed to rename network device \"%s\" to " errno = -err;
"\"%s\": %s", ifname, netdev->name, strerror(-err)); SYSERROR("Failed to rename network device \"%s\" to \"%s\"",
ifname, netdev->name);
return -1; return -1;
} }
} }
...@@ -2943,16 +2952,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) ...@@ -2943,16 +2952,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
err = lxc_netdev_up(current_ifname); err = lxc_netdev_up(current_ifname);
if (err) { if (err) {
ERROR("Failed to set network device \"%s\" up: %s", errno = -err;
current_ifname, strerror(-err)); SYSERROR("Failed to set network device \"%s\" up",
current_ifname);
return -1; return -1;
} }
/* the network is up, make the loopback up too */ /* the network is up, make the loopback up too */
err = lxc_netdev_up("lo"); err = lxc_netdev_up("lo");
if (err) { if (err) {
ERROR("Failed to set the loopback network device up: %s", errno = -err;
strerror(-err)); SYSERROR("Failed to set the loopback network device up");
return -1; return -1;
} }
} }
...@@ -2980,15 +2990,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) ...@@ -2980,15 +2990,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
if (err) { if (err) {
err = lxc_ipv4_dest_add(netdev->ifindex, netdev->ipv4_gateway); err = lxc_ipv4_dest_add(netdev->ifindex, netdev->ipv4_gateway);
if (err) { if (err) {
ERROR("Failed to add ipv4 dest for network " errno = -err;
"device \"%s\": %s", ifname, strerror(-err)); SYSERROR("Failed to add ipv4 dest for network device \"%s\"",
ifname);
} }
err = lxc_ipv4_gateway_add(netdev->ifindex, netdev->ipv4_gateway); err = lxc_ipv4_gateway_add(netdev->ifindex, netdev->ipv4_gateway);
if (err) { if (err) {
ERROR("Failed to setup ipv4 gateway for " errno = -err;
"network device \"%s\": %s", SYSERROR("Failed to setup ipv4 gateway for network device \"%s\"",
ifname, strerror(-err)); ifname);
if (netdev->ipv4_gateway_auto) { if (netdev->ipv4_gateway_auto) {
char buf[INET_ADDRSTRLEN]; char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, netdev->ipv4_gateway, buf, sizeof(buf)); inet_ntop(AF_INET, netdev->ipv4_gateway, buf, sizeof(buf));
...@@ -3017,15 +3029,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev) ...@@ -3017,15 +3029,17 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
if (err) { if (err) {
err = lxc_ipv6_dest_add(netdev->ifindex, netdev->ipv6_gateway); err = lxc_ipv6_dest_add(netdev->ifindex, netdev->ipv6_gateway);
if (err) { if (err) {
ERROR("Failed to add ipv6 dest for network " errno = -err;
"device \"%s\": %s", ifname, strerror(-err)); SYSERROR("Failed to add ipv6 dest for network device \"%s\"",
ifname);
} }
err = lxc_ipv6_gateway_add(netdev->ifindex, netdev->ipv6_gateway); err = lxc_ipv6_gateway_add(netdev->ifindex, netdev->ipv6_gateway);
if (err) { if (err) {
ERROR("Failed to setup ipv6 gateway for " errno = -err;
"network device \"%s\": %s", ifname, SYSERROR("Failed to setup ipv6 gateway for network device \"%s\"",
strerror(-err)); ifname);
if (netdev->ipv6_gateway_auto) { if (netdev->ipv6_gateway_auto) {
char buf[INET6_ADDRSTRLEN]; char buf[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, netdev->ipv6_gateway, buf, sizeof(buf)); inet_ntop(AF_INET6, netdev->ipv6_gateway, buf, sizeof(buf));
......
...@@ -420,7 +420,8 @@ scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch, ...@@ -420,7 +420,8 @@ scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch,
ret = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_NNP, 0); ret = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_NNP, 0);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to turn off no-new-privs", strerror(-ret)); errno = -ret;
SYSERROR("Failed to turn off no-new-privs");
seccomp_release(ctx); seccomp_release(ctx);
return NULL; return NULL;
} }
...@@ -436,17 +437,19 @@ scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch, ...@@ -436,17 +437,19 @@ scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch,
ret = seccomp_arch_exist(ctx, arch); ret = seccomp_arch_exist(ctx, arch);
if (ret < 0) { if (ret < 0) {
if (ret != -EEXIST) { if (ret != -EEXIST) {
ERROR("%s - Failed to determine whether arch %d is " errno = -ret;
"already present in the main seccomp context", SYSERROR("Failed to determine whether arch %d is "
strerror(-ret), (int)n_arch); "already present in the main seccomp context",
(int)n_arch);
seccomp_release(ctx); seccomp_release(ctx);
return NULL; return NULL;
} }
ret = seccomp_arch_add(ctx, arch); ret = seccomp_arch_add(ctx, arch);
if (ret != 0) { if (ret != 0) {
ERROR("%s - Failed to add arch %d to main seccomp context", errno = -ret;
strerror(-ret), (int)n_arch); SYSERROR("Failed to add arch %d to main seccomp context",
(int)n_arch);
seccomp_release(ctx); seccomp_release(ctx);
return NULL; return NULL;
} }
...@@ -477,7 +480,8 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx, ...@@ -477,7 +480,8 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx,
ret = seccomp_arch_exist(ctx, arch); ret = seccomp_arch_exist(ctx, arch);
if (arch && ret != 0) { if (arch && ret != 0) {
ERROR("%s - Seccomp: rule and context arch do not match (arch %d)", strerror(-ret), arch); errno = -ret;
SYSERROR("Seccomp: rule and context arch do not match (arch %d)", arch);
return false; return false;
} }
...@@ -491,7 +495,8 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx, ...@@ -491,7 +495,8 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx,
SCMP_SYS(umount2), 1, SCMP_SYS(umount2), 1,
SCMP_A1(SCMP_CMP_MASKED_EQ, MNT_FORCE, MNT_FORCE)); SCMP_A1(SCMP_CMP_MASKED_EQ, MNT_FORCE, MNT_FORCE));
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed loading rule to reject force umount", strerror(-ret)); errno = -ret;
SYSERROR("Failed loading rule to reject force umount");
return false; return false;
} }
...@@ -534,9 +539,9 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx, ...@@ -534,9 +539,9 @@ bool do_resolve_add_rule(uint32_t arch, char *line, scmp_filter_ctx ctx,
ret = seccomp_rule_add_exact_array(ctx, rule->action, nr, ret = seccomp_rule_add_exact_array(ctx, rule->action, nr,
rule->args_num, arg_cmp); rule->args_num, arg_cmp);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed loading rule for %s (nr %d action %d (%s))", errno = -ret;
strerror(-ret), line, nr, rule->action, SYSERROR("Failed loading rule for %s (nr %d action %d (%s))",
get_action_name(rule->action)); line, nr, rule->action, get_action_name(rule->action));
return false; return false;
} }
...@@ -726,7 +731,8 @@ static int parse_config_v2(FILE *f, char *line, size_t *line_bufsz, struct lxc_c ...@@ -726,7 +731,8 @@ static int parse_config_v2(FILE *f, char *line, size_t *line_bufsz, struct lxc_c
ret = seccomp_attr_set(conf->seccomp_ctx, SCMP_FLTATR_CTL_NNP, 0); ret = seccomp_attr_set(conf->seccomp_ctx, SCMP_FLTATR_CTL_NNP, 0);
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to turn off no-new-privs", strerror(-ret)); errno = -ret;
SYSERROR("Failed to turn off no-new-privs");
return -1; return -1;
} }
...@@ -1157,7 +1163,8 @@ int lxc_read_seccomp_config(struct lxc_conf *conf) ...@@ -1157,7 +1163,8 @@ int lxc_read_seccomp_config(struct lxc_conf *conf)
ret = seccomp_attr_set(SCMP_FLTATR_CTL_NNP, 0); ret = seccomp_attr_set(SCMP_FLTATR_CTL_NNP, 0);
#endif #endif
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to turn off no-new-privs", strerror(-ret)); errno = -ret;
SYSERROR("Failed to turn off no-new-privs");
return -1; return -1;
} }
...@@ -1197,7 +1204,8 @@ int lxc_seccomp_load(struct lxc_conf *conf) ...@@ -1197,7 +1204,8 @@ int lxc_seccomp_load(struct lxc_conf *conf)
ret = seccomp_load(); ret = seccomp_load();
#endif #endif
if (ret < 0) { if (ret < 0) {
ERROR("%s- Error loading the seccomp policy", strerror(-ret)); errno = -ret;
SYSERROR("Error loading the seccomp policy");
return -1; return -1;
} }
......
...@@ -458,8 +458,7 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler, ...@@ -458,8 +458,7 @@ int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
goto again; goto again;
} }
ERROR("%s - Failed to send message to client", SYSERROR("Failed to send message to client");
strerror(errno));
} }
/* kick client from list */ /* kick client from list */
...@@ -1416,9 +1415,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler) ...@@ -1416,9 +1415,9 @@ static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
TRACE("Received pty with master fd %d and slave fd %d from " TRACE("Received pty with master fd %d and slave fd %d from "
"parent", tty->master, tty->slave); "parent", tty->master, tty->slave);
} }
if (ret < 0) if (ret < 0)
ERROR("Failed to receive %zu ttys from child: %s", ttys->max, SYSERROR("Failed to receive %zu ttys from child", ttys->max);
strerror(errno));
else else
TRACE("Received %zu ttys from child", ttys->max); TRACE("Received %zu ttys from child", ttys->max);
...@@ -1686,7 +1685,7 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1686,7 +1685,7 @@ static int lxc_spawn(struct lxc_handler *handler)
ret = lxc_try_preserve_ns(handler->pid, "net"); ret = lxc_try_preserve_ns(handler->pid, "net");
if (ret < 0) { if (ret < 0) {
if (ret != -EOPNOTSUPP) { if (ret != -EOPNOTSUPP) {
ERROR("%s - Failed to preserve net namespace", strerror(errno)); SYSERROR("Failed to preserve net namespace");
goto out_delete_net; goto out_delete_net;
} }
} else { } else {
...@@ -1755,8 +1754,7 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1755,8 +1754,7 @@ static int lxc_spawn(struct lxc_handler *handler)
ret = lxc_try_preserve_ns(handler->pid, "cgroup"); ret = lxc_try_preserve_ns(handler->pid, "cgroup");
if (ret < 0) { if (ret < 0) {
if (ret != -EOPNOTSUPP) { if (ret != -EOPNOTSUPP) {
ERROR("%s - Failed to preserve cgroup namespace", SYSERROR("Failed to preserve cgroup namespace");
strerror(errno));
goto out_delete_net; goto out_delete_net;
} }
} else { } else {
......
...@@ -62,7 +62,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name, ...@@ -62,7 +62,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
int name_len) int name_len)
{ {
struct btrfs_ioctl_ino_lookup_args args; struct btrfs_ioctl_ino_lookup_args args;
int ret, e; int ret;
size_t len, retlen; size_t len, retlen;
char *retpath; char *retpath;
...@@ -71,12 +71,11 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name, ...@@ -71,12 +71,11 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
args.objectid = objid; args.objectid = objid;
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
e = errno;
if (ret) { if (ret) {
ERROR("Failed to lookup path for %llu %llu %s - %s\n", SYSERROR("Failed to lookup path for %llu %llu %s",
(unsigned long long) dir_id, (unsigned long long) dir_id,
(unsigned long long) objid, (unsigned long long) objid,
name, strerror(e)); name);
return NULL; return NULL;
} else } else
INFO("Got path for %llu %llu - %s\n", INFO("Got path for %llu %llu - %s\n",
......
...@@ -41,7 +41,7 @@ static int __sync_wait(int fd, int sequence) ...@@ -41,7 +41,7 @@ static int __sync_wait(int fd, int sequence)
ret = read(fd, &sync, sizeof(sync)); ret = read(fd, &sync, sizeof(sync));
if (ret < 0) { if (ret < 0) {
ERROR("sync wait failure : %s", strerror(errno)); SYSERROR("Sync wait failure");
return -1; return -1;
} }
...@@ -49,7 +49,7 @@ static int __sync_wait(int fd, int sequence) ...@@ -49,7 +49,7 @@ static int __sync_wait(int fd, int sequence)
return 0; return 0;
if ((size_t)ret != sizeof(sync)) { if ((size_t)ret != sizeof(sync)) {
ERROR("unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync)); ERROR("Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync));
return -1; return -1;
} }
...@@ -60,7 +60,7 @@ static int __sync_wait(int fd, int sequence) ...@@ -60,7 +60,7 @@ static int __sync_wait(int fd, int sequence)
} }
if (sync != sequence) { if (sync != sequence) {
ERROR("invalid sequence number %d. expected %d", ERROR("Invalid sequence number %d. expected %d",
sync, sequence); sync, sequence);
return -1; return -1;
} }
...@@ -72,7 +72,7 @@ static int __sync_wake(int fd, int sequence) ...@@ -72,7 +72,7 @@ static int __sync_wake(int fd, int sequence)
int sync = sequence; int sync = sequence;
if (write(fd, &sync, sizeof(sync)) < 0) { if (write(fd, &sync, sizeof(sync)) < 0) {
ERROR("sync wake failure : %s", strerror(errno)); SYSERROR("Sync wake failure");
return -1; return -1;
} }
return 0; return 0;
......
...@@ -685,8 +685,7 @@ static int lxc_terminal_peer_default(struct lxc_terminal *terminal) ...@@ -685,8 +685,7 @@ static int lxc_terminal_peer_default(struct lxc_terminal *terminal)
goto on_succes; goto on_succes;
} }
ERROR("%s - Failed to open proxy terminal \"%s\"", SYSERROR("Failed to open proxy terminal \"%s\"", path);
strerror(errno), path);
return -ENOTTY; return -ENOTTY;
} }
DEBUG("Using terminal \"%s\" as proxy", path); DEBUG("Using terminal \"%s\" as proxy", path);
......
...@@ -1030,8 +1030,10 @@ int lxc_read_from_file(const char *filename, void* buf, size_t count) ...@@ -1030,8 +1030,10 @@ int lxc_read_from_file(const char *filename, void* buf, size_t count)
if (!buf || !count) { if (!buf || !count) {
char buf2[100]; char buf2[100];
size_t count2 = 0; size_t count2 = 0;
while ((ret = read(fd, buf2, 100)) > 0) while ((ret = read(fd, buf2, 100)) > 0)
count2 += ret; count2 += ret;
if (ret >= 0) if (ret >= 0)
ret = count2; ret = count2;
} else { } else {
...@@ -1040,7 +1042,7 @@ int lxc_read_from_file(const char *filename, void* buf, size_t count) ...@@ -1040,7 +1042,7 @@ int lxc_read_from_file(const char *filename, void* buf, size_t count)
} }
if (ret < 0) if (ret < 0)
ERROR("read %s: %s", filename, strerror(errno)); SYSERROR("Read %s", filename);
saved_errno = errno; saved_errno = errno;
close(fd); close(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment