Commit 59991679 by Daniel Lezcano Committed by Daniel Lezcano

Use container's proc to setup the utmp watching

The <rootfs>/var/run/utmp is located in: /proc/<containerinit>/root/var/run/utmp, let's use it. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 12297168
...@@ -82,8 +82,10 @@ static int utmp_handler(int fd, void *data, struct lxc_epoll_descr *descr) ...@@ -82,8 +82,10 @@ static int utmp_handler(int fd, void *data, struct lxc_epoll_descr *descr)
struct lxc_utmp *utmp_data = (struct lxc_utmp *)data; struct lxc_utmp *utmp_data = (struct lxc_utmp *)data;
/* we're monitoring a directory. ie->name is not included in sizeof(struct inotify_event) /*
* if we don't read it all at once, read gives us EINVAL, so we read and cast to struct ie * we're monitoring a directory. ie->name is not included in
* sizeof(struct inotify_event) if we don't read it all at once,
* read gives us EINVAL, so we read and cast to struct ie
*/ */
char buffer[MAXPATHLEN]; char buffer[MAXPATHLEN];
...@@ -100,7 +102,13 @@ static int utmp_handler(int fd, void *data, struct lxc_epoll_descr *descr) ...@@ -100,7 +102,13 @@ static int utmp_handler(int fd, void *data, struct lxc_epoll_descr *descr)
ie = (struct inotify_event *)buffer; ie = (struct inotify_event *)buffer;
if (ie->len <= 0) { if (ie->len <= 0) {
SYSERROR("inotify event with no name");
if (ie->mask & IN_UNMOUNT) {
DEBUG("watched directory removed");
goto out;
}
SYSERROR("inotify event with no name (mask %d)", ie->mask);
return -1; return -1;
} }
...@@ -161,10 +169,9 @@ static int utmp_get_runlevel(struct lxc_utmp *utmp_data) ...@@ -161,10 +169,9 @@ static int utmp_get_runlevel(struct lxc_utmp *utmp_data)
struct utmpx *utmpx; struct utmpx *utmpx;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
struct lxc_handler *handler = utmp_data->handler; struct lxc_handler *handler = utmp_data->handler;
struct lxc_conf *conf = handler->conf;
if (snprintf(path, MAXPATHLEN, "%s/var/run/utmp", conf->rootfs.path) > if (snprintf(path, MAXPATHLEN, "/proc/%d/root/var/run/utmp",
MAXPATHLEN) { handler->pid) > MAXPATHLEN) {
ERROR("path is too long"); ERROR("path is too long");
return -1; return -1;
} }
...@@ -211,19 +218,20 @@ static int utmp_get_ntasks(struct lxc_handler *handler) ...@@ -211,19 +218,20 @@ static int utmp_get_ntasks(struct lxc_handler *handler)
int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr, int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr,
struct lxc_handler *handler) struct lxc_handler *handler)
{ {
struct lxc_conf *conf = handler->conf;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
int fd, wd; int fd, wd;
struct lxc_utmp *utmp_data; struct lxc_utmp *utmp_data;
struct lxc_conf *conf = handler->conf;
if (!conf->rootfs.path) if (!conf->rootfs.path)
return 0; return 0;
/* We set up a watch for the /var/run directory. We're only interested in /* We set up a watch for the /var/run directory. We're only interested
* utmp at the moment, but want to watch for delete and create events as well. * in utmp at the moment, but want to watch for delete and create
* events as well.
*/ */
if (snprintf(path, MAXPATHLEN, "%s/var/run", conf->rootfs.path) > if (snprintf(path, MAXPATHLEN, "/proc/%d/root/var/run",
MAXPATHLEN) { handler->pid) > MAXPATHLEN) {
ERROR("path is too long"); ERROR("path is too long");
return -1; return -1;
} }
......
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