Skip to content

Commit

Permalink
re-open cgmanager socket after fork in daemonized start
Browse files Browse the repository at this point in the history
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
hallyn authored and stgraber committed Feb 15, 2014
1 parent 1d16785 commit 7eb4457
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lxc/cgmanager.c
Expand Up @@ -114,7 +114,8 @@ static bool cgm_dbus_connect(void)

static void cgm_dbus_disconnect(void)
{
nih_free(cgroup_manager);
if (cgroup_manager)
nih_free(cgroup_manager);
cgroup_manager = NULL;
}

Expand Down Expand Up @@ -886,5 +887,6 @@ static struct cgroup_ops cgmanager_ops = {
.attach = cgm_attach,
.mount_cgroup = cgm_mount_cgroup,
.nrtasks = cgm_get_nrtasks,
.disconnect = cgm_dbus_disconnect,
};
#endif
8 changes: 8 additions & 0 deletions src/lxc/cgroup.c
Expand Up @@ -167,3 +167,11 @@ int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *na
return ops->get(filename, value, len, name, lxcpath);
return -1;
}

void restart_cgroups(void)
{
if (ops && ops->disconnect)
ops->disconnect();
ops = NULL;
cgroup_ops_init();
}
2 changes: 2 additions & 0 deletions src/lxc/cgroup.h
Expand Up @@ -49,6 +49,7 @@ struct cgroup_ops {
bool (*attach)(const char *name, const char *lxcpath, pid_t pid);
bool (*mount_cgroup)(void *hdata, const char *root, int type);
int (*nrtasks)(void *hdata);
void (*disconnect)(void);
};

extern bool cgroup_attach(const char *name, const char *lxcpath, pid_t pid);
Expand All @@ -64,5 +65,6 @@ extern bool cgroup_create_legacy(struct lxc_handler *handler);
extern int cgroup_nrtasks(struct lxc_handler *handler);
extern const char *cgroup_get_cgroup(struct lxc_handler *handler, const char *subsystem);
extern bool cgroup_unfreeze(struct lxc_handler *handler);
extern void restart_cgroups(void);

#endif
1 change: 1 addition & 0 deletions src/lxc/lxccontainer.c
Expand Up @@ -637,6 +637,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
open("/dev/null", O_RDWR);
open("/dev/null", O_RDWR);
setsid();
restart_cgroups();
} else {
if (!am_single_threaded()) {
ERROR("Cannot start non-daemonized container when threaded");
Expand Down

0 comments on commit 7eb4457

Please sign in to comment.