Commit 9123e471 by Serge Hallyn Committed by Stéphane Graber

lxc_monitor_open: prepend lxcpath

This is needed for lxc_wait and lxc_monitor to handle lxcpath. However, the full path name is limited to 108 bytes. Should we use a md5sum of the lxcpath instead of the path itself? In any case, with this patch, lxc-wait and lxc-monitor work right with respect to multiple lxcpaths. The lxcpath is added to the lxc_handler to make it available most of the places we need it. I also remove function prototypes in monitor.h for two functions which are not defined or used anywhere. TODO: make cgroups tolerate multiple same-named containers. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent fbf5de31
......@@ -40,7 +40,7 @@
lxc_log_define(lxc_freezer, lxc);
static int freeze_unfreeze(const char *name, int freeze)
static int freeze_unfreeze(const char *name, int freeze, const char *lxcpath)
{
char *nsgroup;
char freezer[MAXPATHLEN], *f;
......@@ -98,7 +98,7 @@ static int freeze_unfreeze(const char *name, int freeze)
ret = strncmp(f, tmpf, strlen(f));
if (!ret)
{
lxc_monitor_send_state(name, freeze ? FROZEN : THAWED);
lxc_monitor_send_state(name, freeze ? FROZEN : THAWED, lxcpath);
break; /* Success */
}
......@@ -122,14 +122,14 @@ out:
return ret;
}
int lxc_freeze(const char *name)
int lxc_freeze(const char *name, const char *lxcpath)
{
lxc_monitor_send_state(name, FREEZING);
return freeze_unfreeze(name, 1);
lxc_monitor_send_state(name, FREEZING, lxcpath);
return freeze_unfreeze(name, 1, lxcpath);
}
int lxc_unfreeze(const char *name)
int lxc_unfreeze(const char *name, const char *lxcpath)
{
return freeze_unfreeze(name, 0);
return freeze_unfreeze(name, 0, lxcpath);
}
......@@ -74,7 +74,7 @@ extern int lxc_execute(const char *name, char *const argv[], int quiet,
* The function will return an fd corresponding to the events
* Returns a file descriptor on success, < 0 otherwise
*/
extern int lxc_monitor_open(void);
extern int lxc_monitor_open(const char *lxcpath);
/*
* Read the state of the container if this one has changed
......@@ -108,14 +108,14 @@ extern int lxc_console(const char *name, int ttynum, int *fd, const char *lxcpat
* @name : the container name
* Returns 0 on success, < 0 otherwise
*/
extern int lxc_freeze(const char *name);
extern int lxc_freeze(const char *name, const char *lxcpath);
/*
* Unfreeze all previously frozen tasks.
* @name : the name of the container
* Return 0 on sucess, < 0 otherwise
*/
extern int lxc_unfreeze(const char *name);
extern int lxc_unfreeze(const char *name, const char *lxcpath);
/*
* Retrieve the container state
......
......@@ -58,6 +58,6 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet))
return -1;
return lxc_freeze(my_args.name);
return lxc_freeze(my_args.name, my_args.lxcpath);
}
......@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
return -1;
}
fd = lxc_monitor_open();
fd = lxc_monitor_open(my_args.lxcpath);
if (fd < 0)
return -1;
......
......@@ -57,6 +57,6 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet))
return -1;
return lxc_unfreeze(my_args.name);
return lxc_unfreeze(my_args.name, my_args.lxcpath);
}
......@@ -195,7 +195,7 @@ static bool lxcapi_freeze(struct lxc_container *c)
if (lxclock(c->slock, 0))
return false;
ret = lxc_freeze(c->name);
ret = lxc_freeze(c->name, c->config_path);
lxcunlock(c->slock);
if (ret)
return false;
......@@ -210,7 +210,7 @@ static bool lxcapi_unfreeze(struct lxc_container *c)
if (lxclock(c->slock, 0))
return false;
ret = lxc_unfreeze(c->name);
ret = lxc_unfreeze(c->name, c->config_path);
lxcunlock(c->slock);
if (ret)
return false;
......
......@@ -47,13 +47,23 @@ lxc_log_define(lxc_monitor, lxc);
#define UNIX_PATH_MAX 108
#endif
static void lxc_monitor_send(struct lxc_msg *msg)
static void lxc_monitor_send(struct lxc_msg *msg, const char *lxcpath)
{
int fd;
struct sockaddr_un addr = { .sun_family = AF_UNIX };
char *offset = &addr.sun_path[1];
strcpy(offset, "lxc-monitor");
size_t ret, len;
/*
* addr.sun_path is only 108 bytes.
* should we take a hash of lxcpath? a subset of it?
*/
len = sizeof(addr.sun_path) - 1;
ret = snprintf(offset, len, "%s/lxc-monitor", lxcpath);
if (ret < 0 || ret >= len) {
ERROR("lxcpath too long to open monitor");
return;
}
fd = socket(PF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
......@@ -65,23 +75,33 @@ static void lxc_monitor_send(struct lxc_msg *msg)
close(fd);
}
void lxc_monitor_send_state(const char *name, lxc_state_t state)
void lxc_monitor_send_state(const char *name, lxc_state_t state, const char *lxcpath)
{
struct lxc_msg msg = { .type = lxc_msg_state,
.value = state };
strncpy(msg.name, name, sizeof(msg.name));
msg.name[sizeof(msg.name) - 1] = 0;
lxc_monitor_send(&msg);
lxc_monitor_send(&msg, lxcpath);
}
int lxc_monitor_open(void)
int lxc_monitor_open(const char *lxcpath)
{
struct sockaddr_un addr = { .sun_family = AF_UNIX };
char *offset = &addr.sun_path[1];
int fd;
strcpy(offset, "lxc-monitor");
size_t ret, len;
/*
* addr.sun_path is only 108 bytes.
* should we take a hash of lxcpath? a subset of it?
*/
len = sizeof(addr.sun_path) - 1;
ret = snprintf(offset, len, "%s/lxc-monitor", lxcpath);
if (ret < 0 || ret >= len) {
ERROR("lxcpath too long to open monitor");
return -1;
}
fd = socket(PF_UNIX, SOCK_DGRAM, 0);
if (fd < 0) {
......
......@@ -36,8 +36,7 @@ struct lxc_msg {
int value;
};
void lxc_monitor_send_state(const char *name, lxc_state_t state);
void lxc_monitor_send_priority(const char *name, int priority);
void lxc_monitor_cleanup(const char *name);
void lxc_monitor_send_state(const char *name, lxc_state_t state,
const char *lxcpath);
#endif
......@@ -311,7 +311,7 @@ int lxc_clone_flags_callback(int fd, struct lxc_request *request,
int lxc_set_state(const char *name, struct lxc_handler *handler, lxc_state_t state)
{
handler->state = state;
lxc_monitor_send_state(name, state);
lxc_monitor_send_state(name, state, handler->lxcpath);
return 0;
}
......@@ -379,6 +379,7 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char
memset(handler, 0, sizeof(*handler));
handler->conf = conf;
handler->lxcpath = lxcpath;
apparmor_handler_init(handler);
handler->name = strdup(name);
......
......@@ -50,6 +50,7 @@ struct lxc_handler {
int aa_enabled;
#endif
int pinfd;
const char *lxcpath;
};
extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *, const char *);
......
......@@ -200,7 +200,7 @@ extern int lxc_wait(const char *lxcname, const char *states, int timeout, const
if (fillwaitedstates(states, s))
return -1;
fd = lxc_monitor_open();
fd = lxc_monitor_open(lxcpath);
if (fd < 0)
return -1;
......
......@@ -85,7 +85,7 @@ extern int lxc_stop_callback(int fd, struct lxc_request *request,
answer.ret = kill(handler->pid, SIGKILL);
if (!answer.ret) {
ret = lxc_unfreeze(handler->name);
ret = lxc_unfreeze(handler->name, handler->lxcpath);
if (!ret)
return 0;
......
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