Commit fe447886 by Serge Hallyn Committed by Stéphane Graber

proc update - don't assume we are pid 1

(I erred in the first patch, causing every lxc-attach to unmount the container-'s /proc) Since we now use mount_proc_if_needed() from attach, as opposed to only from start, we cannot assume we are pid 1. So fix the check for whether to mount a new proc. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent ced03a01
...@@ -1417,6 +1417,7 @@ int mount_proc_if_needed(const char *rootfs) ...@@ -1417,6 +1417,7 @@ int mount_proc_if_needed(const char *rootfs)
char path[MAXPATHLEN]; char path[MAXPATHLEN];
char link[20]; char link[20];
int linklen, ret; int linklen, ret;
int mypid;
ret = snprintf(path, MAXPATHLEN, "%s/proc/self", rootfs); ret = snprintf(path, MAXPATHLEN, "%s/proc/self", rootfs);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= MAXPATHLEN) {
...@@ -1425,12 +1426,12 @@ int mount_proc_if_needed(const char *rootfs) ...@@ -1425,12 +1426,12 @@ int mount_proc_if_needed(const char *rootfs)
} }
memset(link, 0, 20); memset(link, 0, 20);
linklen = readlink(path, link, 20); linklen = readlink(path, link, 20);
INFO("I am %d, /proc/self points to '%s'", getpid(), link); mypid = (int)getpid();
INFO("I am %d, /proc/self points to '%s'", mypid, link);
ret = snprintf(path, MAXPATHLEN, "%s/proc", rootfs); ret = snprintf(path, MAXPATHLEN, "%s/proc", rootfs);
if (linklen < 0) /* /proc not mounted */ if (linklen < 0) /* /proc not mounted */
goto domount; goto domount;
/* can't be longer than rootfs/proc/1 */ if (atoi(link) != mypid) {
if (strncmp(link, "1", linklen) != 0) {
/* wrong /procs mounted */ /* wrong /procs mounted */
umount2(path, MNT_DETACH); /* ignore failure */ umount2(path, MNT_DETACH); /* ignore failure */
goto domount; goto domount;
......
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