From: 2xsec Date: Tue, 26 Jun 2018 05:06:09 +0000 (+0900) Subject: log: change WARN macro using strerror to SYSWARN X-Git-Tag: lxc-3.1.0~230^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a24c5678a91b66d7a1c6ca0e5ed3a958e57cd17d;p=thirdparty%2Flxc.git log: change WARN macro using strerror to SYSWARN Signed-off-by: 2xsec --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 429a5d86c..7f1fb9f6b 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -380,7 +380,7 @@ static int lxc_attach_set_environment(struct lxc_proc_context_info *init_ctx, if (extra_keep_store[i]) { ret = setenv(extra_keep[i], extra_keep_store[i], 1); if (ret < 0) - WARN("%s - Failed to set environment variable", strerror(errno)); + SYSWARN("Failed to set environment variable"); } free(extra_keep_store[i]); } @@ -395,13 +395,13 @@ static int lxc_attach_set_environment(struct lxc_proc_context_info *init_ctx, if (!path_kept) { ret = setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 1); if (ret < 0) - WARN("%s - Failed to set environment variable", strerror(errno)); + SYSWARN("Failed to set environment variable"); } } ret = putenv("container=lxc"); if (ret < 0) { - WARN("%s - Failed to set environment variable", strerror(errno)); + SYSWARN("Failed to set environment variable"); return -1; } @@ -435,7 +435,7 @@ static int lxc_attach_set_environment(struct lxc_proc_context_info *init_ctx, ret = putenv(p); if (ret < 0) - WARN("%s - Failed to set environment variable", strerror(errno)); + SYSWARN("Failed to set environment variable"); } } diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 6665af217..9e6a08a9f 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -196,8 +196,7 @@ int lxc_ambient_caps_up(void) for (cap = 0; cap <= last_cap; cap++) { ret = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, cap, 0, 0); if (ret < 0) { - WARN("%s - Failed to raise ambient capability %d", - strerror(errno), cap); + SYSWARN("Failed to raise ambient capability %d", cap); goto out; } } diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index fedb9a063..b514a7bb6 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -1082,14 +1082,14 @@ static int recursive_destroy(char *dirname) ret = rmdir(dirname); if (ret < 0) { if (!r) - WARN("%s - Failed to delete \"%s\"", strerror(errno), dirname); + SYSWARN("Failed to delete \"%s\"", dirname); r = -1; } ret = closedir(dir); if (ret < 0) { if (!r) - WARN("%s - Failed to delete \"%s\"", strerror(errno), dirname); + SYSWARN("Failed to delete \"%s\"", dirname); r = -1; } @@ -1398,15 +1398,13 @@ static int chowmod(char *path, uid_t chown_uid, gid_t chown_gid, ret = chown(path, chown_uid, chown_gid); if (ret < 0) { - WARN("%s - Failed to chown(%s, %d, %d)", strerror(errno), path, - (int)chown_uid, (int)chown_gid); + SYSWARN("Failed to chown(%s, %d, %d)", path, (int)chown_uid, (int)chown_gid); return -1; } ret = chmod(path, chmod_mode); if (ret < 0) { - WARN("%s - Failed to chmod(%s, %d)", strerror(errno), path, - (int)chmod_mode); + SYSWARN("Failed to chmod(%s, %d)", path, (int)chmod_mode); return -1; } diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 8c1a03d58..ca77affd4 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -126,8 +126,9 @@ static int lxc_cmd_rsp_recv(int sock, struct lxc_cmd_rr *cmd) ret = lxc_abstract_unix_recv_fds(sock, &rspfd, 1, rsp, sizeof(*rsp)); if (ret < 0) { - WARN("%s - Failed to receive response for command \"%s\"", - strerror(errno), lxc_cmd_str(cmd->req.cmd)); + SYSWARN("Failed to receive response for command \"%s\"", + lxc_cmd_str(cmd->req.cmd)); + if (errno == ECONNRESET) return -ECONNRESET; @@ -218,8 +219,7 @@ static int lxc_cmd_rsp_send(int fd, struct lxc_cmd_rsp *rsp) ret = send(fd, rsp->data, rsp->datalen, 0); if (ret < 0 || ret != (ssize_t)rsp->datalen) { - WARN("%s - Failed to send command response data %zd", - strerror(errno), ret); + SYSWARN("Failed to send command response data %zd", ret); return -1; } diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 4e7dc379b..cc97ea9d1 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -986,15 +986,13 @@ int lxc_allocate_ttys(struct lxc_conf *conf) /* Prevent leaking the file descriptors to the container */ ret = fcntl(tty->master, F_SETFD, FD_CLOEXEC); if (ret < 0) - WARN("Failed to set FD_CLOEXEC flag on master fd %d of " - "tty device \"%s\": %s", - tty->master, tty->name, strerror(errno)); + SYSWARN("Failed to set FD_CLOEXEC flag on master fd %d of " + "tty device \"%s\"", tty->master, tty->name); ret = fcntl(tty->slave, F_SETFD, FD_CLOEXEC); if (ret < 0) - WARN("Failed to set FD_CLOEXEC flag on slave fd %d of " - "tty device \"%s\": %s", - tty->slave, tty->name, strerror(errno)); + SYSWARN("Failed to set FD_CLOEXEC flag on slave fd %d of " + "tty device \"%s\"", tty->slave, tty->name); tty->busy = 0; } @@ -1549,7 +1547,7 @@ static int lxc_setup_devpts(struct lxc_conf *conf) ret = umount2("/dev/pts", MNT_DETACH); if (ret < 0) - WARN("%s - Failed to unmount old devpts instance", strerror(errno)); + SYSWARN("Failed to unmount old devpts instance"); else DEBUG("Unmounted old devpts instance"); diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index ed223a5b2..5c866ae84 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -113,7 +113,7 @@ static void lxc_monitor_fifo_send(struct lxc_msg *msg, const char *lxcpath) if (errno == ENXIO || errno == ENOENT) return; - WARN("%s - Failed to open fifo to send message", strerror(errno)); + SYSWARN("Failed to open fifo to send message"); return; } diff --git a/src/lxc/network.c b/src/lxc/network.c index c147d10ba..3f15590b2 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -2599,10 +2599,10 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) netdev->name[0] != '\0' ? netdev->name : "(null)", netdev->ifindex); } else if (ret < 0) { - WARN("Failed to remove interface \"%s\" with " - "index %d: %s", - netdev->name[0] != '\0' ? netdev->name : "(null)", - netdev->ifindex, strerror(-ret)); + errno = -ret; + SYSWARN("Failed to remove interface \"%s\" with index %d", + netdev->name[0] != '\0' ? netdev->name : "(null)", + netdev->ifindex); goto clear_ifindices; } INFO("Removed interface \"%s\" with index %d", @@ -2624,8 +2624,9 @@ bool lxc_delete_network_priv(struct lxc_handler *handler) ret = lxc_netdev_delete_by_name(hostveth); if (ret < 0) { - WARN("Failed to remove interface \"%s\" from \"%s\": %s", - hostveth, netdev->link, strerror(-ret)); + errno = -ret; + SYSWARN("Failed to remove interface \"%s\" from \"%s\"", + hostveth, netdev->link); goto clear_ifindices; } INFO("Removed interface \"%s\" from \"%s\"", hostveth, netdev->link); diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index 1fbaa429b..80a7ef176 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -427,8 +427,10 @@ scmp_filter_ctx get_new_ctx(enum lxc_hostarch_t n_arch, #ifdef SCMP_FLTATR_ATL_TSKIP ret = seccomp_attr_set(ctx, SCMP_FLTATR_ATL_TSKIP, 1); - if (ret < 0) - WARN("%s - Failed to turn on seccomp nop-skip, continuing", strerror(-ret)); + if (ret < 0) { + errno = -ret; + SYSWARN("Failed to turn on seccomp nop-skip, continuing"); + } #endif ret = seccomp_arch_exist(ctx, arch); @@ -730,8 +732,10 @@ static int parse_config_v2(FILE *f, char *line, size_t *line_bufsz, struct lxc_c #ifdef SCMP_FLTATR_ATL_TSKIP ret = seccomp_attr_set(conf->seccomp_ctx, SCMP_FLTATR_ATL_TSKIP, 1); - if (ret < 0) - WARN("%s - Failed to turn on seccomp nop-skip, continuing", strerror(-ret)); + if (ret < 0) { + errno = -ret; + SYSWARN("Failed to turn on seccomp nop-skip, continuing"); + } #endif } @@ -1156,11 +1160,13 @@ int lxc_read_seccomp_config(struct lxc_conf *conf) ERROR("%s - Failed to turn off no-new-privs", strerror(-ret)); return -1; } + #ifdef SCMP_FLTATR_ATL_TSKIP ret = seccomp_attr_set(conf->seccomp_ctx, SCMP_FLTATR_ATL_TSKIP, 1); - if (ret < 0) - WARN("%s - Failed to turn on seccomp nop-skip, continuing", - strerror(-ret)); + if (ret < 0) { + errno = -ret; + SYSWARN("Failed to turn on seccomp nop-skip, continuing"); + } #endif f = fopen(conf->seccomp, "r"); @@ -1203,8 +1209,10 @@ int lxc_seccomp_load(struct lxc_conf *conf) lxc_log_fd >= 0) { ret = seccomp_export_pfc(conf->seccomp_ctx, lxc_log_fd); /* Just give an warning when export error */ - if (ret < 0) - WARN("%s - Failed to export seccomp filter to log file", strerror(-ret)); + if (ret < 0) { + errno = -ret; + SYSWARN("Failed to export seccomp filter to log file"); + } } #endif diff --git a/src/lxc/start.c b/src/lxc/start.c index 2dae6652a..8359d356a 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -160,8 +160,7 @@ static int lxc_try_preserve_ns(const int pid, const char *ns) return -EINVAL; } - WARN("%s - Kernel does not support preserving %s namespaces", - strerror(errno), ns); + SYSWARN("Kernel does not support preserving %s namespaces", ns); return -EOPNOTSUPP; } @@ -228,7 +227,7 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall, restart: dir = opendir("/proc/self/fd"); if (!dir) { - WARN("%s - Failed to open directory", strerror(errno)); + SYSWARN("Failed to open directory"); return -1; } @@ -987,7 +986,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler) /* Reset mask set by setup_signal_fd. */ ret = pthread_sigmask(SIG_SETMASK, &handler->oldmask, NULL); if (ret < 0) - WARN("%s - Failed to restore signal mask", strerror(errno)); + SYSWARN("Failed to restore signal mask"); lxc_terminal_delete(&handler->conf->console); lxc_delete_tty(&handler->conf->ttys); diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c index f30dc4703..ad5d51e7e 100644 --- a/src/lxc/storage/btrfs.c +++ b/src/lxc/storage/btrfs.c @@ -132,8 +132,7 @@ int btrfs_list_get_path_rootid(int fd, u64 *treeid) ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); if (ret < 0) { - WARN("Warning: can't perform the search -%s\n", - strerror(errno)); + SYSWARN("Warning: can't perform the search"); return ret; } *treeid = args.treeid; diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c index 7acb9eac1..0d1f81820 100644 --- a/src/lxc/storage/overlay.c +++ b/src/lxc/storage/overlay.c @@ -786,9 +786,9 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs, else if (!strncmp(upperdir, lxcpath, dirlen) && strncmp(upperdir, rootfs_dir, rootfslen)) ret = mkdir_p(upperdir, 0755); + if (ret < 0) - WARN("Failed to create directory \"%s\": %s", upperdir, - strerror(errno)); + SYSWARN("Failed to create directory \"%s\"", upperdir); } ret = 0; @@ -798,9 +798,9 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs, else if (!strncmp(workdir, lxcpath, dirlen) && strncmp(workdir, rootfs_dir, rootfslen)) ret = mkdir_p(workdir, 0755); + if (ret < 0) - WARN("Failed to create directory \"%s\": %s", workdir, - strerror(errno)); + SYSWARN("Failed to create directory \"%s\"", workdir); } fret = 0; diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index e1089acf3..b942e4921 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -209,7 +209,7 @@ void lxc_terminal_signal_fini(struct lxc_terminal_state *ts) close(ts->sigfd); if (pthread_sigmask(SIG_SETMASK, &ts->oldmask, NULL) < 0) - WARN("%s - Failed to restore signal mask", strerror(errno)); + SYSWARN("Failed to restore signal mask"); } if (isatty(ts->stdinfd)) @@ -771,7 +771,7 @@ void lxc_terminal_delete(struct lxc_terminal *terminal) if (terminal->tios && terminal->peer >= 0) { ret = tcsetattr(terminal->peer, TCSAFLUSH, terminal->tios); if (ret < 0) - WARN("%s - Failed to set old terminal settings", strerror(errno)); + SYSWARN("Failed to set old terminal settings"); } free(terminal->tios); terminal->tios = NULL; @@ -1106,8 +1106,7 @@ restore_tios: if (istty) { istty = tcsetattr(stdinfd, TCSAFLUSH, &oldtios); if (istty < 0) - WARN("%s - Failed to restore terminal properties", - strerror(errno)); + SYSWARN("Failed to restore terminal properties"); } close_mainloop: