diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c index 002f944ce..86f1fe9fd 100644 --- a/src/lxc/af_unix.c +++ b/src/lxc/af_unix.c @@ -40,7 +40,7 @@ #include "include/strlcpy.h" #endif -lxc_log_define(lxc_af_unix, lxc); +lxc_log_define(af_unix, lxc); int lxc_abstract_unix_open(const char *path, int type, int flags) { diff --git a/src/lxc/attach.c b/src/lxc/attach.c index bc98f67c5..afb4e0bc0 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -87,7 +87,7 @@ #define MS_SLAVE (1 << 19) #endif -lxc_log_define(lxc_attach, lxc); +lxc_log_define(attach, lxc); /* /proc/pid-to-str/status\0 = (5 + 21 + 7 + 1) */ #define __PROC_STATUS_LEN (5 + (LXC_NUMSTRLEN64) + 7 + 1) diff --git a/src/lxc/caps.c b/src/lxc/caps.c index 7b1848f63..ae5d7ef16 100644 --- a/src/lxc/caps.c +++ b/src/lxc/caps.c @@ -34,7 +34,7 @@ #include "caps.h" #include "log.h" -lxc_log_define(lxc_caps, lxc); +lxc_log_define(caps, lxc); #if HAVE_LIBCAP diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index 3cc9f9f62..935b868b9 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -66,7 +66,7 @@ #include "include/strlcat.h" #endif -lxc_log_define(lxc_cgfsng, lxc); +lxc_log_define(cgfsng, cgroup); static void free_string_list(char **clist) { @@ -695,8 +695,7 @@ static bool controller_found(struct hierarchy **hlist, char *entry) */ static bool all_controllers_found(struct cgroup_ops *ops) { - char *p; - char *saveptr = NULL; + char **cur; struct hierarchy **hlist = ops->hierarchies; if (!controller_found(hlist, "freezer")) { @@ -707,9 +706,9 @@ static bool all_controllers_found(struct cgroup_ops *ops) if (!ops->cgroup_use) return true; - for (; (p = strtok_r(ops->cgroup_use, ",", &saveptr)); ops->cgroup_use = NULL) - if (!controller_found(hlist, p)) { - ERROR("No %s controller mountpoint found", p); + for (cur = ops->cgroup_use; cur && *cur; cur++) + if (!controller_found(hlist, *cur)) { + ERROR("No %s controller mountpoint found", *cur); return false; } @@ -2251,6 +2250,34 @@ static bool cgfsng_setup_limits(struct cgroup_ops *ops, struct lxc_conf *conf, return __cg_unified_setup_limits(ops, &conf->cgroup2); } +static bool cgroup_use_wants_controllers(const struct cgroup_ops *ops, + char **controllers) +{ + char **cur_ctrl, **cur_use; + + if (!ops->cgroup_use) + return true; + + for (cur_ctrl = controllers; cur_ctrl && *cur_ctrl; cur_ctrl++) { + bool found = false; + + for (cur_use = ops->cgroup_use; cur_use && *cur_use; cur_use++) { + if (strcmp(*cur_use, *cur_ctrl) != 0) + continue; + + found = true; + break; + } + + if (found) + continue; + + return false; + } + + return true; +} + /* At startup, parse_hierarchies finds all the info we need about cgroup * mountpoints and current cgroups, and stores it in @d. */ @@ -2366,6 +2393,10 @@ static bool cg_hybrid_init(struct cgroup_ops *ops) } } + /* Exclude all controllers that cgroup use does not want. */ + if (!cgroup_use_wants_controllers(ops, controller_list)) + goto next; + new = add_hierarchy(&ops->hierarchies, controller_list, mountpoint, base_cgroup, type); if (type == CGROUP2_SUPER_MAGIC && !ops->unified) ops->unified = new; @@ -2498,8 +2529,18 @@ static bool cg_init(struct cgroup_ops *ops) const char *tmp; tmp = lxc_global_config_value("lxc.cgroup.use"); - if (tmp) - ops->cgroup_use = must_copy_string(tmp); + if (tmp) { + char *chop, *cur, *pin; + char *saveptr = NULL; + + pin = must_copy_string(tmp); + chop = pin; + + for (; (cur = strtok_r(chop, ",", &saveptr)); chop = NULL) + must_append_string(&ops->cgroup_use, cur); + + free(pin); + } ret = cg_unified_init(ops); if (ret < 0) diff --git a/src/lxc/cgroups/cgroup.c b/src/lxc/cgroups/cgroup.c index cd67c3c5d..f86bd9be8 100644 --- a/src/lxc/cgroups/cgroup.c +++ b/src/lxc/cgroups/cgroup.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include @@ -30,7 +31,7 @@ #include "log.h" #include "start.h" -lxc_log_define(lxc_cgroup, lxc); +lxc_log_define(cgroup, lxc); extern struct cgroup_ops *cgfsng_ops_init(void); @@ -63,12 +64,15 @@ struct cgroup_ops *cgroup_init(struct lxc_handler *handler) void cgroup_exit(struct cgroup_ops *ops) { + char **cur; struct hierarchy **it; if (!ops) return; - free(ops->cgroup_use); + for (cur = ops->cgroup_use; cur && *cur; cur++) + free(*cur); + free(ops->cgroup_pattern); free(ops->container_cgroup); @@ -108,33 +112,3 @@ void prune_init_scope(char *cg) *point = '\0'; } } - -/* Return true if this is a subsystem which we cannot do without. - * - * systemd is questionable here. The way callers currently use this, if systemd - * is not mounted then it will be ignored. But if systemd is mounted, then it - * must be setup so that lxc can create cgroups in it, else containers will - * fail. - * - * cgroups listed in lxc.cgroup.use are also treated as crucial - * - */ -bool is_crucial_cgroup_subsystem(const char *s) -{ - const char *cgroup_use; - - if (strcmp(s, "systemd") == 0) - return true; - - if (strcmp(s, "name=systemd") == 0) - return true; - - if (strcmp(s, "freezer") == 0) - return true; - - cgroup_use = lxc_global_config_value("lxc.cgroup.use"); - if (cgroup_use && strstr(cgroup_use, s)) - return true; - - return false; -} diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h index ae910be8b..8f4af06c1 100644 --- a/src/lxc/cgroups/cgroup.h +++ b/src/lxc/cgroups/cgroup.h @@ -89,7 +89,7 @@ struct cgroup_ops { const char *version; /* What controllers is the container supposed to use. */ - char *cgroup_use; + char **cgroup_use; char *cgroup_pattern; char *container_cgroup; @@ -149,6 +149,5 @@ extern struct cgroup_ops *cgroup_init(struct lxc_handler *handler); extern void cgroup_exit(struct cgroup_ops *ops); extern void prune_init_scope(char *cg); -extern bool is_crucial_cgroup_subsystem(const char *s); #endif diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 22275277b..618b3089d 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -76,7 +76,7 @@ * container. */ -lxc_log_define(lxc_commands, lxc); +lxc_log_define(commands, lxc); static const char *lxc_cmd_str(lxc_cmd_t cmd) { diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c index 03e481f09..f27880032 100644 --- a/src/lxc/commands_utils.c +++ b/src/lxc/commands_utils.c @@ -38,7 +38,7 @@ #include "state.h" #include "utils.h" -lxc_log_define(lxc_commands_utils, lxc); +lxc_log_define(commands_utils, lxc); int lxc_cmd_sock_rcv_state(int state_client_fd, int timeout) { diff --git a/src/lxc/conf.c b/src/lxc/conf.c index bb483522d..48a5c7b6d 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -118,7 +118,7 @@ #define MS_LAZYTIME (1<<25) #endif -lxc_log_define(lxc_conf, lxc); +lxc_log_define(conf, lxc); /* The lxc_conf of the container currently being worked on in an API call. * This is used in the error calls. @@ -892,13 +892,11 @@ static int lxc_setup_ttys(struct lxc_conf *conf) if (ret < 0 || (size_t)ret >= sizeof(lxcpath)) return -1; - ret = creat(lxcpath, 0660); + ret = mknod(path, S_IFREG, 0); if (ret < 0 && errno != EEXIST) { SYSERROR("Failed to create \"%s\"", lxcpath); return -1; } - if (ret >= 0) - close(ret); ret = unlink(path); if (ret < 0 && errno != ENOENT) { @@ -971,25 +969,32 @@ int lxc_allocate_ttys(struct lxc_conf *conf) tty->master = -EBADF; tty->slave = -EBADF; - ret = openpty(&tty->master, &tty->slave, - tty->name, NULL, NULL); - if (ret) { + ret = openpty(&tty->master, &tty->slave, NULL, NULL, NULL); + if (ret < 0) { SYSERROR("Failed to create tty %d", i); ttys->max = i; lxc_delete_tty(ttys); return -ENOTTY; } + ret = ttyname_r(tty->slave, tty->name, sizeof(tty->name)); + if (ret < 0) { + SYSERROR("Failed to retrieve name of tty %d slave", i); + ttys->max = i; + lxc_delete_tty(ttys); + return -ENOTTY; + } + DEBUG("Created tty \"%s\" with master fd %d and slave fd %d", tty->name, tty->master, tty->slave); /* Prevent leaking the file descriptors to the container */ - ret = fcntl(tty->master, F_SETFD, FD_CLOEXEC); + ret = fd_cloexec(tty->master, true); if (ret < 0) 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); + ret = fd_cloexec(tty->slave, true); if (ret < 0) SYSWARN("Failed to set FD_CLOEXEC flag on slave fd %d of " "tty device \"%s\"", tty->slave, tty->name); diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 7cb1fbb16..4365264e9 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -73,7 +73,7 @@ #include "include/strlcat.h" #endif -lxc_log_define(lxc_confile, lxc); +lxc_log_define(confile, lxc); #define lxc_config_define(name) \ static int set_config_##name(const char *, const char *, \ diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index a68c6ffd0..8100cf741 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -40,7 +40,7 @@ #include "include/strlcpy.h" #endif -lxc_log_define(lxc_confile_utils, lxc); +lxc_log_define(confile_utils, lxc); int parse_idmaps(const char *idmap, char *type, unsigned long *nsid, unsigned long *hostid, unsigned long *range) diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 41b0c027f..c36421627 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -63,7 +63,7 @@ #define CRIU_IN_FLIGHT_SUPPORT "2.4" #define CRIU_EXTERNAL_NOT_VETH "2.8" -lxc_log_define(lxc_criu, lxc); +lxc_log_define(criu, lxc); struct criu_opts { /* the thing to hook to stdout and stderr for logging */ diff --git a/src/lxc/error.c b/src/lxc/error.c index 9147a6afb..769dedc40 100644 --- a/src/lxc/error.c +++ b/src/lxc/error.c @@ -28,7 +28,7 @@ #include "error.h" #include "log.h" -lxc_log_define(lxc_error, lxc); +lxc_log_define(error, lxc); /*---------------------------------------------------------------------------*/ /* lxc_error_set_and_log diff --git a/src/lxc/execute.c b/src/lxc/execute.c index 1a87b2321..d01df6b2e 100644 --- a/src/lxc/execute.c +++ b/src/lxc/execute.c @@ -34,7 +34,7 @@ #include "start.h" #include "utils.h" -lxc_log_define(lxc_execute, lxc_start); +lxc_log_define(execute, start); static int execute_start(struct lxc_handler *handler, void* data) { diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c index 5665aee8e..2103b50b9 100644 --- a/src/lxc/freezer.c +++ b/src/lxc/freezer.c @@ -40,7 +40,7 @@ #include "parse.h" #include "state.h" -lxc_log_define(lxc_freezer, lxc); +lxc_log_define(freezer, lxc); static int do_freeze_thaw(bool freeze, const char *name, const char *lxcpath) { diff --git a/src/lxc/initutils.c b/src/lxc/initutils.c index 4ca2ce197..6ab39a7da 100644 --- a/src/lxc/initutils.c +++ b/src/lxc/initutils.c @@ -31,7 +31,7 @@ #include "include/strlcpy.h" #endif -lxc_log_define(lxc_initutils, lxc); +lxc_log_define(initutils, lxc); static char *copy_global_config_value(char *p) { diff --git a/src/lxc/log.c b/src/lxc/log.c index e1af6067c..dafda1b95 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -66,7 +66,7 @@ static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc"; static char *log_fname = NULL; static char *log_vmname = NULL; -lxc_log_define(lxc_log, lxc); +lxc_log_define(log, lxc); static int lxc_log_priority_to_syslog(int priority) { diff --git a/src/lxc/log.h b/src/lxc/log.h index cfbfd0cf4..448867752 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -72,9 +72,9 @@ enum lxc_loglevel { /* location information of the logging event */ struct lxc_log_locinfo { - const char *file; - const char *func; - int line; + const char *file; + const char *func; + int line; }; #define LXC_LOG_LOCINFO_INIT \ @@ -82,31 +82,31 @@ struct lxc_log_locinfo { /* brief logging event object */ struct lxc_log_event { - const char* category; - int priority; - struct timespec timestamp; - struct lxc_log_locinfo *locinfo; - const char *fmt; - va_list *vap; + const char *category; + int priority; + struct timespec timestamp; + struct lxc_log_locinfo *locinfo; + const char *fmt; + va_list *vap; }; /* log appender object */ struct lxc_log_appender { - const char* name; + const char *name; int (*append)(const struct lxc_log_appender *, struct lxc_log_event *); /* * appenders can be stacked */ - struct lxc_log_appender *next; + struct lxc_log_appender *next; }; /* log category object */ struct lxc_log_category { - const char *name; - int priority; - struct lxc_log_appender *appender; - const struct lxc_log_category *parent; + const char *name; + int priority; + struct lxc_log_appender *appender; + const struct lxc_log_category *parent; }; #ifndef NO_LXC_CONF @@ -117,18 +117,16 @@ extern int lxc_log_use_global_fd; * Returns true if the chained priority is equal to or higher than * given priority. */ -static inline int -lxc_log_priority_is_enabled(const struct lxc_log_category* category, - int priority) +static inline int lxc_log_priority_is_enabled(const struct lxc_log_category *category, + int priority) { - while (category->priority == LXC_LOG_LEVEL_NOTSET && - category->parent) + while (category->priority == LXC_LOG_LEVEL_NOTSET && category->parent) category = category->parent; int cmp_prio = category->priority; #ifndef NO_LXC_CONF if (!lxc_log_use_global_fd && current_config && - current_config->loglevel != LXC_LOG_LEVEL_NOTSET) + current_config->loglevel != LXC_LOG_LEVEL_NOTSET) cmp_prio = current_config->loglevel; #endif @@ -138,79 +136,114 @@ lxc_log_priority_is_enabled(const struct lxc_log_category* category, /* * converts a priority to a literal string */ -static inline const char* lxc_log_priority_to_string(int priority) +static inline const char *lxc_log_priority_to_string(int priority) { switch (priority) { - case LXC_LOG_LEVEL_TRACE: return "TRACE"; - case LXC_LOG_LEVEL_DEBUG: return "DEBUG"; - case LXC_LOG_LEVEL_INFO: return "INFO"; - case LXC_LOG_LEVEL_NOTICE: return "NOTICE"; - case LXC_LOG_LEVEL_WARN: return "WARN"; - case LXC_LOG_LEVEL_ERROR: return "ERROR"; - case LXC_LOG_LEVEL_CRIT: return "CRIT"; - case LXC_LOG_LEVEL_ALERT: return "ALERT"; - case LXC_LOG_LEVEL_FATAL: return "FATAL"; - default: - return "NOTSET"; + case LXC_LOG_LEVEL_TRACE: + return "TRACE"; + case LXC_LOG_LEVEL_DEBUG: + return "DEBUG"; + case LXC_LOG_LEVEL_INFO: + return "INFO"; + case LXC_LOG_LEVEL_NOTICE: + return "NOTICE"; + case LXC_LOG_LEVEL_WARN: + return "WARN"; + case LXC_LOG_LEVEL_ERROR: + return "ERROR"; + case LXC_LOG_LEVEL_CRIT: + return "CRIT"; + case LXC_LOG_LEVEL_ALERT: + return "ALERT"; + case LXC_LOG_LEVEL_FATAL: + return "FATAL"; } + + return "NOTSET"; } -static inline const char* lxc_syslog_priority_to_string(int priority) +static inline const char *lxc_syslog_priority_to_string(int priority) { switch (priority) { - case LOG_DAEMON: return "daemon"; - case LOG_LOCAL0: return "local0"; - case LOG_LOCAL1: return "local1"; - case LOG_LOCAL2: return "local2"; - case LOG_LOCAL3: return "local3"; - case LOG_LOCAL4: return "local4"; - case LOG_LOCAL5: return "local5"; - case LOG_LOCAL6: return "local6"; - case LOG_LOCAL7: return "local7"; - default: - return "NOTSET"; + case LOG_DAEMON: + return "daemon"; + case LOG_LOCAL0: + return "local0"; + case LOG_LOCAL1: + return "local1"; + case LOG_LOCAL2: + return "local2"; + case LOG_LOCAL3: + return "local3"; + case LOG_LOCAL4: + return "local4"; + case LOG_LOCAL5: + return "local5"; + case LOG_LOCAL6: + return "local6"; + case LOG_LOCAL7: + return "local7"; } + + return "NOTSET"; } /* * converts a literal priority to an int */ -static inline int lxc_log_priority_to_int(const char* name) +static inline int lxc_log_priority_to_int(const char *name) { - if (!strcasecmp("TRACE", name)) return LXC_LOG_LEVEL_TRACE; - if (!strcasecmp("DEBUG", name)) return LXC_LOG_LEVEL_DEBUG; - if (!strcasecmp("INFO", name)) return LXC_LOG_LEVEL_INFO; - if (!strcasecmp("NOTICE", name)) return LXC_LOG_LEVEL_NOTICE; - if (!strcasecmp("WARN", name)) return LXC_LOG_LEVEL_WARN; - if (!strcasecmp("ERROR", name)) return LXC_LOG_LEVEL_ERROR; - if (!strcasecmp("CRIT", name)) return LXC_LOG_LEVEL_CRIT; - if (!strcasecmp("ALERT", name)) return LXC_LOG_LEVEL_ALERT; - if (!strcasecmp("FATAL", name)) return LXC_LOG_LEVEL_FATAL; + if (strcasecmp("TRACE", name) == 0) + return LXC_LOG_LEVEL_TRACE; + if (strcasecmp("DEBUG", name) == 0) + return LXC_LOG_LEVEL_DEBUG; + if (strcasecmp("INFO", name) == 0) + return LXC_LOG_LEVEL_INFO; + if (strcasecmp("NOTICE", name) == 0) + return LXC_LOG_LEVEL_NOTICE; + if (strcasecmp("WARN", name) == 0) + return LXC_LOG_LEVEL_WARN; + if (strcasecmp("ERROR", name) == 0) + return LXC_LOG_LEVEL_ERROR; + if (strcasecmp("CRIT", name) == 0) + return LXC_LOG_LEVEL_CRIT; + if (strcasecmp("ALERT", name) == 0) + return LXC_LOG_LEVEL_ALERT; + if (strcasecmp("FATAL", name) == 0) + return LXC_LOG_LEVEL_FATAL; return LXC_LOG_LEVEL_NOTSET; } -static inline int lxc_syslog_priority_to_int(const char* name) +static inline int lxc_syslog_priority_to_int(const char *name) { - if (!strcasecmp("daemon", name)) return LOG_DAEMON; - if (!strcasecmp("local0", name)) return LOG_LOCAL0; - if (!strcasecmp("local1", name)) return LOG_LOCAL1; - if (!strcasecmp("local2", name)) return LOG_LOCAL2; - if (!strcasecmp("local3", name)) return LOG_LOCAL3; - if (!strcasecmp("local4", name)) return LOG_LOCAL4; - if (!strcasecmp("local5", name)) return LOG_LOCAL5; - if (!strcasecmp("local6", name)) return LOG_LOCAL6; - if (!strcasecmp("local7", name)) return LOG_LOCAL7; + if (strcasecmp("daemon", name) == 0) + return LOG_DAEMON; + if (strcasecmp("local0", name) == 0) + return LOG_LOCAL0; + if (strcasecmp("local1", name) == 0) + return LOG_LOCAL1; + if (strcasecmp("local2", name) == 0) + return LOG_LOCAL2; + if (strcasecmp("local3", name) == 0) + return LOG_LOCAL3; + if (strcasecmp("local4", name) == 0) + return LOG_LOCAL4; + if (strcasecmp("local5", name) == 0) + return LOG_LOCAL5; + if (strcasecmp("local6", name) == 0) + return LOG_LOCAL6; + if (strcasecmp("local7", name) == 0) + return LOG_LOCAL7; return -EINVAL; } -static inline void -__lxc_log_append(const struct lxc_log_appender *appender, - struct lxc_log_event* event) +static inline void __lxc_log_append(const struct lxc_log_appender *appender, + struct lxc_log_event *event) { - va_list va, *va_keep; - va_keep = event->vap; + va_list va; + va_list *va_keep = event->vap; while (appender) { va_copy(va, *va_keep); @@ -221,9 +254,8 @@ __lxc_log_append(const struct lxc_log_appender *appender, } } -static inline void -__lxc_log(const struct lxc_log_category* category, - struct lxc_log_event* event) +static inline void __lxc_log(const struct lxc_log_category *category, + struct lxc_log_event *event) { while (category) { __lxc_log_append(category->appender, event); @@ -234,34 +266,34 @@ __lxc_log(const struct lxc_log_category* category, /* * Helper macro to define log functions. */ -#define lxc_log_priority_define(acategory, LEVEL) \ - \ -ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo *, \ - const char *, ...) __attribute__ ((format (printf, 2, 3))); \ - \ +#define lxc_log_priority_define(acategory, LEVEL) \ + \ +ATTR_UNUSED __attribute__ ((format (printf, 2, 3))) \ +static inline void LXC_##LEVEL(struct lxc_log_locinfo *, const char *, ...); \ + \ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \ - const char* format, ...) \ -{ \ - if (lxc_log_priority_is_enabled(acategory, \ - LXC_LOG_LEVEL_##LEVEL)) { \ - struct lxc_log_event evt = { \ - .category = (acategory)->name, \ - .priority = LXC_LOG_LEVEL_##LEVEL, \ - .fmt = format, \ - .locinfo = locinfo \ - }; \ - va_list va_ref; \ - \ - /* clock_gettime() is explicitly marked as MT-Safe \ - * without restrictions. So let's use it for our \ - * logging stamps. */ \ - clock_gettime(CLOCK_REALTIME, &evt.timestamp); \ - \ - va_start(va_ref, format); \ - evt.vap = &va_ref; \ - __lxc_log(acategory, &evt); \ - va_end(va_ref); \ - } \ + const char* format, ...) \ +{ \ + if (lxc_log_priority_is_enabled(acategory, LXC_LOG_LEVEL_##LEVEL)) { \ + va_list va_ref; \ + struct lxc_log_event evt = { \ + .category = (acategory)->name, \ + .priority = LXC_LOG_LEVEL_##LEVEL, \ + .fmt = format, \ + .locinfo = locinfo \ + }; \ + \ + /* clock_gettime() is explicitly marked as MT-Safe \ + * without restrictions. So let's use it for our \ + * logging stamps. \ + */ \ + (void)clock_gettime(CLOCK_REALTIME, &evt.timestamp); \ + \ + va_start(va_ref, format); \ + evt.vap = &va_ref; \ + __lxc_log(acategory, &evt); \ + va_end(va_ref); \ + } \ } /* @@ -271,7 +303,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \ extern struct lxc_log_category lxc_log_category_##parent; \ struct lxc_log_category lxc_log_category_##name = { \ #name, \ - LXC_LOG_LEVEL_NOTSET, \ + LXC_LOG_LEVEL_NOTSET, \ NULL, \ &lxc_log_category_##parent \ }; diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 793d13f76..1507917c8 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -33,7 +33,7 @@ #include "conf.h" #include "utils.h" -lxc_log_define(lxc_apparmor, lxc); +lxc_log_define(apparmor, lsm); /* set by lsm_apparmor_drv_init if true */ static int aa_enabled = 0; diff --git a/src/lxc/lsm/lsm.c b/src/lxc/lsm/lsm.c index 3f71cdd73..f4500ae20 100644 --- a/src/lxc/lsm/lsm.c +++ b/src/lxc/lsm/lsm.c @@ -32,7 +32,7 @@ #include "log.h" #include "lsm.h" -lxc_log_define(lxc_lsm, lxc); +lxc_log_define(lsm, lxc); static struct lsm_drv *drv = NULL; diff --git a/src/lxc/lsm/selinux.c b/src/lxc/lsm/selinux.c index 1d8ce4cba..c88c18e3d 100644 --- a/src/lxc/lsm/selinux.c +++ b/src/lxc/lsm/selinux.c @@ -36,7 +36,7 @@ #define DEFAULT_LABEL "unconfined_t" -lxc_log_define(lxc_lsm_selinux, lxc); +lxc_log_define(selinux, lsm); /* * selinux_process_label_get: Get SELinux context of a process diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index c5ea78770..ce01f13e9 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -104,7 +104,7 @@ static int faccessat(int __fd, const char *__file, int __type, int __flag) } #endif -lxc_log_define(lxc_container, lxc); +lxc_log_define(lxccontainer, lxc); static bool do_lxcapi_destroy(struct lxc_container *c); static const char *lxcapi_get_config_path(struct lxc_container *c); diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c index 08c96e0b1..29675fb59 100644 --- a/src/lxc/lxclock.c +++ b/src/lxc/lxclock.c @@ -40,7 +40,7 @@ #define MAX_STACKDEPTH 25 -lxc_log_define(lxc_lock, lxc); +lxc_log_define(lxclock, lxc); #ifdef MUTEX_DEBUGGING static pthread_mutex_t thread_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 4bbf679db..d9f10c40b 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -54,7 +54,7 @@ #include "include/strlcpy.h" #endif -lxc_log_define(lxc_monitor, lxc); +lxc_log_define(monitor, lxc); /* routines used by monitor publishers (containers) */ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path_sz, diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c index a169f83de..2459c9d2e 100644 --- a/src/lxc/namespace.c +++ b/src/lxc/namespace.c @@ -37,7 +37,7 @@ #include "namespace.h" #include "utils.h" -lxc_log_define(lxc_namespace, lxc); +lxc_log_define(namespace, lxc); struct clone_arg { int (*fn)(void *); diff --git a/src/lxc/network.c b/src/lxc/network.c index e59b85d62..c9497afa4 100644 --- a/src/lxc/network.c +++ b/src/lxc/network.c @@ -95,7 +95,7 @@ #define IFLA_MACVLAN_MODE 1 #endif -lxc_log_define(lxc_network, lxc); +lxc_log_define(network, lxc); typedef int (*instantiate_cb)(struct lxc_handler *, struct lxc_netdev *); diff --git a/src/lxc/parse.c b/src/lxc/parse.c index a1025c5af..bc209347c 100644 --- a/src/lxc/parse.c +++ b/src/lxc/parse.c @@ -35,7 +35,7 @@ #include "utils.h" #include "log.h" -lxc_log_define(lxc_parse, lxc); +lxc_log_define(parse, lxc); void *lxc_strmmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) diff --git a/src/lxc/seccomp.c b/src/lxc/seccomp.c index 81abf62ee..c8f2b3f3b 100644 --- a/src/lxc/seccomp.c +++ b/src/lxc/seccomp.c @@ -42,7 +42,7 @@ #define MIPS_ARCH_N64 lxc_seccomp_arch_mips64 #endif -lxc_log_define(lxc_seccomp, lxc); +lxc_log_define(seccomp, lxc); static int parse_config_v1(FILE *f, char *line, size_t *line_bufsz, struct lxc_conf *conf) { diff --git a/src/lxc/start.c b/src/lxc/start.c index a0bcd80bb..953722261 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -94,7 +94,7 @@ #include "include/strlcpy.h" #endif -lxc_log_define(lxc_start, lxc); +lxc_log_define(start, lxc); extern void mod_all_rdeps(struct lxc_container *c, bool inc); static bool do_destroy_container(struct lxc_handler *handler); diff --git a/src/lxc/state.c b/src/lxc/state.c index 12fd65386..3ccbe583a 100644 --- a/src/lxc/state.c +++ b/src/lxc/state.c @@ -44,7 +44,7 @@ #include "monitor.h" #include "start.h" -lxc_log_define(lxc_state, lxc); +lxc_log_define(state, lxc); static const char *const strstate[] = { "STOPPED", "STARTING", "RUNNING", "STOPPING", diff --git a/src/lxc/sync.c b/src/lxc/sync.c index 62512eec7..53fae06c0 100644 --- a/src/lxc/sync.c +++ b/src/lxc/sync.c @@ -32,7 +32,7 @@ #include "log.h" #include "start.h" -lxc_log_define(lxc_sync, lxc); +lxc_log_define(sync, lxc); static int __sync_wait(int fd, int sequence) { diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c index 5e2387a9e..daff4d816 100644 --- a/src/lxc/tools/arguments.c +++ b/src/lxc/tools/arguments.c @@ -38,6 +38,7 @@ #include "arguments.h" #include "namespace.h" +#include "initutils.h" static int build_shortopts(const struct option *a_options, char *a_shortopts, size_t a_size) @@ -186,13 +187,6 @@ static int lxc_arguments_lxcpath_add(struct lxc_arguments *args, return 0; } -void remove_trailing_slashes(char *p) -{ - int l = strlen(p); - while (--l >= 0 && (p[l] == '/' || p[l] == '\n')) - p[l] = '\0'; -} - extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, char *const argv[]) { diff --git a/src/lxc/utils.c b/src/lxc/utils.c index e2ee8229d..6bb05df00 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -67,7 +67,7 @@ #define O_NOFOLLOW 00400000 #endif -lxc_log_define(lxc_utils, lxc); +lxc_log_define(utils, lxc); /* * if path is btrfs, tries to remove it and any subvolumes beneath it