Unverified Commit 68002881 by Serge Hallyn Committed by GitHub

Merge pull request #2175 from brauner/2018-02-17/coding_style_fixes

tree-wide: coding style + fixes
parents f6a248c0 49beb65e
...@@ -92,7 +92,6 @@ liblxc_la_SOURCES = \ ...@@ -92,7 +92,6 @@ liblxc_la_SOURCES = \
storage/rsync.c storage/rsync.h \ storage/rsync.c storage/rsync.h \
storage/zfs.c storage/zfs.h \ storage/zfs.c storage/zfs.h \
storage/storage_utils.c storage/storage_utils.h \ storage/storage_utils.c storage/storage_utils.h \
cgroups/cgfs.c \
cgroups/cgfsng.c \ cgroups/cgfsng.c \
cgroups/cgroup_utils.c cgroups/cgroup_utils.h \ cgroups/cgroup_utils.c cgroups/cgroup_utils.h \
cgroups/cgroup.c cgroups/cgroup.h \ cgroups/cgroup.c cgroups/cgroup.h \
......
...@@ -34,27 +34,19 @@ lxc_log_define(lxc_cgroup, lxc); ...@@ -34,27 +34,19 @@ lxc_log_define(lxc_cgroup, lxc);
static struct cgroup_ops *ops = NULL; static struct cgroup_ops *ops = NULL;
extern struct cgroup_ops *cgfs_ops_init(void);
extern struct cgroup_ops *cgfsng_ops_init(void); extern struct cgroup_ops *cgfsng_ops_init(void);
extern struct cgroup_ops *cgm_ops_init(void);
__attribute__((constructor)) void cgroup_ops_init(void) __attribute__((constructor)) void cgroup_ops_init(void)
{ {
if (ops) { if (ops) {
INFO("cgroup driver %s", ops->name); INFO("Running with %s in version %s", ops->driver, ops->version);
return; return;
} }
DEBUG("cgroup_init"); DEBUG("cgroup_init");
#if HAVE_CGMANAGER ops = cgfsng_ops_init();
ops = cgm_ops_init();
#endif
if (!ops)
ops = cgfsng_ops_init();
if (!ops)
ops = cgfs_ops_init();
if (ops) if (ops)
INFO("Initialized cgroup driver %s", ops->name); INFO("Initialized cgroup driver %s", ops->driver);
} }
bool cgroup_init(struct lxc_handler *handler) bool cgroup_init(struct lxc_handler *handler)
...@@ -65,7 +57,7 @@ bool cgroup_init(struct lxc_handler *handler) ...@@ -65,7 +57,7 @@ bool cgroup_init(struct lxc_handler *handler)
} }
if (ops) { if (ops) {
INFO("cgroup driver %s initing for %s", ops->name, handler->name); INFO("cgroup driver %s initing for %s", ops->driver, handler->name);
handler->cgroup_data = ops->init(handler); handler->cgroup_data = ops->init(handler);
} }
...@@ -178,7 +170,7 @@ int cgroup_nrtasks(struct lxc_handler *handler) ...@@ -178,7 +170,7 @@ int cgroup_nrtasks(struct lxc_handler *handler)
if (ops->nrtasks) if (ops->nrtasks)
return ops->nrtasks(handler->cgroup_data); return ops->nrtasks(handler->cgroup_data);
else else
WARN("cgroup driver \"%s\" doesn't implement nrtasks", ops->name); WARN("cgroup driver \"%s\" doesn't implement nrtasks", ops->driver);
} }
return -1; return -1;
...@@ -216,11 +208,6 @@ void cgroup_disconnect(void) ...@@ -216,11 +208,6 @@ void cgroup_disconnect(void)
ops->disconnect(); ops->disconnect();
} }
cgroup_driver_t cgroup_driver(void)
{
return ops->driver;
}
#define INIT_SCOPE "/init.scope" #define INIT_SCOPE "/init.scope"
void prune_init_scope(char *cg) void prune_init_scope(char *cg)
{ {
......
...@@ -39,14 +39,9 @@ typedef enum { ...@@ -39,14 +39,9 @@ typedef enum {
CGROUP_LAYOUT_UNIFIED = 2, CGROUP_LAYOUT_UNIFIED = 2,
} cgroup_layout_t; } cgroup_layout_t;
typedef enum {
CGFS,
CGMANAGER,
CGFSNG,
} cgroup_driver_t;
struct cgroup_ops { struct cgroup_ops {
const char *name; const char *driver;
const char *version;
void *(*init)(struct lxc_handler *handler); void *(*init)(struct lxc_handler *handler);
void (*destroy)(void *hdata, struct lxc_conf *conf); void (*destroy)(void *hdata, struct lxc_conf *conf);
...@@ -66,7 +61,6 @@ struct cgroup_ops { ...@@ -66,7 +61,6 @@ struct cgroup_ops {
bool (*mount_cgroup)(void *hdata, const char *root, int type); bool (*mount_cgroup)(void *hdata, const char *root, int type);
int (*nrtasks)(void *hdata); int (*nrtasks)(void *hdata);
void (*disconnect)(void); void (*disconnect)(void);
cgroup_driver_t driver;
}; };
extern bool cgroup_attach(const char *name, const char *lxcpath, pid_t pid); extern bool cgroup_attach(const char *name, const char *lxcpath, pid_t pid);
...@@ -87,7 +81,6 @@ extern int cgroup_num_hierarchies(); ...@@ -87,7 +81,6 @@ extern int cgroup_num_hierarchies();
extern bool cgroup_get_hierarchies(int i, char ***out); extern bool cgroup_get_hierarchies(int i, char ***out);
extern bool cgroup_unfreeze(struct lxc_handler *handler); extern bool cgroup_unfreeze(struct lxc_handler *handler);
extern void cgroup_disconnect(void); extern void cgroup_disconnect(void);
extern cgroup_driver_t cgroup_driver(void);
extern void prune_init_scope(char *cg); extern void prune_init_scope(char *cg);
extern bool is_crucial_cgroup_subsystem(const char *s); extern bool is_crucial_cgroup_subsystem(const char *s);
......
...@@ -421,7 +421,7 @@ int lxc_cmd_get_clone_flags(const char *name, const char *lxcpath) ...@@ -421,7 +421,7 @@ int lxc_cmd_get_clone_flags(const char *name, const char *lxcpath)
static int lxc_cmd_get_clone_flags_callback(int fd, struct lxc_cmd_req *req, static int lxc_cmd_get_clone_flags_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler) struct lxc_handler *handler)
{ {
struct lxc_cmd_rsp rsp = { .data = INT_TO_PTR(handler->clone_flags) }; struct lxc_cmd_rsp rsp = { .data = INT_TO_PTR(handler->ns_clone_flags) };
return lxc_cmd_rsp_send(fd, &rsp); return lxc_cmd_rsp_send(fd, &rsp);
} }
...@@ -1156,8 +1156,8 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler, ...@@ -1156,8 +1156,8 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
continue; continue;
/* kick client from list */ /* kick client from list */
close(client->clientfd);
lxc_list_del(cur); lxc_list_del(cur);
close(client->clientfd);
free(cur->elem); free(cur->elem);
free(cur); free(cur);
/* No need to walk the whole list. If we found the state client /* No need to walk the whole list. If we found the state client
......
...@@ -948,10 +948,8 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf) ...@@ -948,10 +948,8 @@ int lxc_allocate_ttys(const char *name, struct lxc_conf *conf)
for (i = 0; i < conf->tty; i++) { for (i = 0; i < conf->tty; i++) {
struct lxc_pty_info *pty_info = &tty_info->pty_info[i]; struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
process_lock();
ret = openpty(&pty_info->master, &pty_info->slave, ret = openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL); pty_info->name, NULL, NULL);
process_unlock();
if (ret) { if (ret) {
SYSERROR("failed to create pty device number %d", i); SYSERROR("failed to create pty device number %d", i);
tty_info->nbtty = i; tty_info->nbtty = i;
......
...@@ -1706,25 +1706,29 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1706,25 +1706,29 @@ static int set_config_mount_auto(const char *key, const char *value,
int mask; int mask;
int flag; int flag;
} allowed_auto_mounts[] = { } allowed_auto_mounts[] = {
{ "proc", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_MIXED }, { "proc", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_MIXED },
{ "proc:mixed", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_MIXED }, { "proc:mixed", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_MIXED },
{ "proc:rw", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_RW }, { "proc:rw", LXC_AUTO_PROC_MASK, LXC_AUTO_PROC_RW },
{ "sys", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_MIXED }, { "sys", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_MIXED },
{ "sys:ro", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_RO }, { "sys:ro", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_RO },
{ "sys:mixed", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_MIXED }, { "sys:mixed", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_MIXED },
{ "sys:rw", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_RW }, { "sys:rw", LXC_AUTO_SYS_MASK, LXC_AUTO_SYS_RW },
{ "cgroup", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC }, { "cgroup", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC },
{ "cgroup:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED }, { "cgroup:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED },
{ "cgroup:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO }, { "cgroup:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO },
{ "cgroup:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW }, { "cgroup:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW },
{ "cgroup:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC | LXC_AUTO_CGROUP_FORCE }, { "cgroup:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC | LXC_AUTO_CGROUP_FORCE },
{ "cgroup:mixed:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED | LXC_AUTO_CGROUP_FORCE }, { "cgroup:mixed:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED | LXC_AUTO_CGROUP_FORCE },
{ "cgroup:ro:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO | LXC_AUTO_CGROUP_FORCE }, { "cgroup:ro:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO | LXC_AUTO_CGROUP_FORCE },
{ "cgroup:rw:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW | LXC_AUTO_CGROUP_FORCE }, { "cgroup:rw:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW | LXC_AUTO_CGROUP_FORCE },
{ "cgroup-full", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_NOSPEC }, { "cgroup-full", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_NOSPEC },
{ "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED }, { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED },
{ "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO }, { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO },
{ "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW }, { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW },
{ "cgroup-full:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_NOSPEC | LXC_AUTO_CGROUP_FORCE },
{ "cgroup-full:mixed:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED | LXC_AUTO_CGROUP_FORCE },
{ "cgroup-full:ro:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO | LXC_AUTO_CGROUP_FORCE },
{ "cgroup-full:rw:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW | LXC_AUTO_CGROUP_FORCE },
/* For adding anything that is just a single on/off, but has no /* For adding anything that is just a single on/off, but has no
* options: keep mask and flag identical and just define the enum * options: keep mask and flag identical and just define the enum
* value as an unused bit so far * value as an unused bit so far
......
...@@ -709,11 +709,9 @@ int lxc_pty_create(struct lxc_console *console) ...@@ -709,11 +709,9 @@ int lxc_pty_create(struct lxc_console *console)
{ {
int ret, saved_errno; int ret, saved_errno;
process_lock();
ret = openpty(&console->master, &console->slave, console->name, NULL, ret = openpty(&console->master, &console->slave, console->name, NULL,
NULL); NULL);
saved_errno = errno; saved_errno = errno;
process_unlock();
if (ret < 0) { if (ret < 0) {
ERROR("%s - Failed to allocate a pty", strerror(saved_errno)); ERROR("%s - Failed to allocate a pty", strerror(saved_errno));
return -1; return -1;
......
...@@ -746,7 +746,7 @@ again: ...@@ -746,7 +746,7 @@ again:
static bool wait_on_daemonized_start(struct lxc_handler *handler, int pid) static bool wait_on_daemonized_start(struct lxc_handler *handler, int pid)
{ {
int state, status; int ret, state;
/* Close write end of the socket pair. */ /* Close write end of the socket pair. */
close(handler->state_socket_pair[1]); close(handler->state_socket_pair[1]);
...@@ -761,12 +761,11 @@ static bool wait_on_daemonized_start(struct lxc_handler *handler, int pid) ...@@ -761,12 +761,11 @@ static bool wait_on_daemonized_start(struct lxc_handler *handler, int pid)
/* The first child is going to fork() again and then exits. So we reap /* The first child is going to fork() again and then exits. So we reap
* the first child here. * the first child here.
*/ */
if (waitpid(pid, &status, 0) < 0) ret = wait_for_pid(pid);
DEBUG("Failed waiting on first child"); if (ret < 0)
else if (!WIFEXITED(status)) DEBUG("Failed waiting on first child %d", pid);
DEBUG("Failed to retrieve exit status of first child"); else
else if (WEXITSTATUS(status) != 0) DEBUG("First child %d exited", pid);
DEBUG("First child exited with: %d", WEXITSTATUS(status));
if (state < 0) { if (state < 0) {
SYSERROR("Failed to receive the container state"); SYSERROR("Failed to receive the container state");
......
...@@ -37,14 +37,32 @@ ...@@ -37,14 +37,32 @@
#include "state.h" #include "state.h"
struct lxc_handler { struct lxc_handler {
/* The clone flags that were requested. */ /* Record the clone for namespaces flags that the container requested.
int clone_flags; *
* @ns_clone_flags
/* The clone flags to actually use when calling lxc_clone(). They may * - All clone flags that were requested.
* differ from clone_flags because of ordering requirements (e.g. *
* CLONE_NEWNET and CLONE_NEWUSER). * @ns_on_clone_flags
* - The clone flags for namespaces to actually use when calling
* lxc_clone(): After the container has started ns_on_clone_flags will
* list the clone flags that were unshare()ed rather then clone()ed
* because of ordering requirements (e.g. e.g. CLONE_NEWNET and
* CLONE_NEWUSER) or implementation details.
*
* @ns_keep_flags;
* - The clone flags for the namespaces that the container will inherit
* from the parent. They are not recorded in the handler itself but
* are present in the container's config.
*
* @ns_share_flags;
* - The clone flags for the namespaces that the container will share
* with another process. They are not recorded in the handler itself
* but are present in the container's config.
*/ */
int on_clone_flags; struct /* lxc_ns */ {
int ns_clone_flags;
int ns_on_clone_flags;
};
/* File descriptor to pin the rootfs for privileged containers. */ /* File descriptor to pin the rootfs for privileged containers. */
int pinfd; int pinfd;
......
...@@ -2510,3 +2510,29 @@ uint64_t lxc_find_next_power2(uint64_t n) ...@@ -2510,3 +2510,29 @@ uint64_t lxc_find_next_power2(uint64_t n)
n = n << 1; n = n << 1;
return n; return n;
} }
int lxc_set_death_signal(int signal)
{
int ret;
pid_t ppid;
ret = prctl(PR_SET_PDEATHSIG, signal, 0, 0, 0);
/* Check whether we have been orphaned. */
ppid = (pid_t)syscall(SYS_getppid);
if (ppid == 1) {
pid_t self;
self = lxc_raw_getpid();
ret = kill(self, SIGKILL);
if (ret < 0)
return -1;
}
if (ret < 0) {
SYSERROR("Failed to set PR_SET_PDEATHSIG to %d", signal);
return -1;
}
return 0;
}
...@@ -589,4 +589,7 @@ static inline pid_t lxc_raw_gettid(void) ...@@ -589,4 +589,7 @@ static inline pid_t lxc_raw_gettid(void)
#endif #endif
} }
/* Set a signal the child process will receive after the parent has died. */
extern int lxc_set_death_signal(int signal);
#endif /* __LXC_UTILS_H */ #endif /* __LXC_UTILS_H */
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