[lxc-devel] [PATCH 2/1] proc update - don't assume we are pid 1
Stéphane Graber
stgraber at ubuntu.com
Tue May 26 17:06:30 UTC 2015
On Sun, May 17, 2015 at 08:14:13PM +0000, Serge Hallyn wrote:
> (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: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/utils.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
> index 0588fdd..e56f4a3 100644
> --- a/src/lxc/utils.c
> +++ b/src/lxc/utils.c
> @@ -1679,6 +1679,7 @@ int mount_proc_if_needed(const char *rootfs)
> char path[MAXPATHLEN];
> char link[20];
> int linklen, ret;
> + int mypid;
>
> ret = snprintf(path, MAXPATHLEN, "%s/proc/self", rootfs);
> if (ret < 0 || ret >= MAXPATHLEN) {
> @@ -1687,12 +1688,12 @@ int mount_proc_if_needed(const char *rootfs)
> }
> memset(link, 0, 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);
> if (linklen < 0) /* /proc not mounted */
> goto domount;
> - /* can't be longer than rootfs/proc/1 */
> - if (strncmp(link, "1", linklen) != 0) {
> + if (atoi(link) != mypid) {
> /* wrong /procs mounted */
> umount2(path, MNT_DETACH); /* ignore failure */
> goto domount;
> --
> 2.1.4
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150526/acf7b94b/attachment.sig>
More information about the lxc-devel
mailing list