]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-attach: Clear environment and set container=lxc
authorDavid Ward <david.ward@ll.mit.edu>
Wed, 20 Mar 2013 16:08:29 +0000 (12:08 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 21 Mar 2013 15:12:03 +0000 (11:12 -0400)
The child process's environment should be manipulated the same way
by lxc-attach as it would be by lxc-start or lxc-execute.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/attach.c
src/lxc/attach.h
src/lxc/lxc_attach.c

index 2f3202539201f7240aaaff31898068f767abd0e8..12adadb56a9ede83d8a833a75099540667106a5a 100644 (file)
@@ -277,6 +277,21 @@ int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx)
        return 0;
 }
 
+int lxc_attach_set_environment()
+{
+       if (clearenv()) {
+               SYSERROR("failed to clear environment");
+               /* don't error out though */
+       }
+
+       if (putenv("container=lxc")) {
+               SYSERROR("failed to set environment variable");
+               return -1;
+       }
+
+       return 0;
+}
+
 char *lxc_attach_getpwshell(uid_t uid)
 {
        /* local variables */
index 6bbfb425d46011131d6582feeeaf4c7f126cb865..404ff4c2233e8ff64aab721731e3b43bc98aea08 100644 (file)
@@ -37,6 +37,7 @@ extern struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid);
 extern int lxc_attach_to_ns(pid_t other_pid, int which);
 extern int lxc_attach_remount_sys_proc();
 extern int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx);
+extern int lxc_attach_set_environment();
 
 extern char *lxc_attach_getpwshell(uid_t uid);
 
index 678b76d53ed856ba46eb7b24389d3a3eb4566d66..7fd76ee21e1ec53ec4c5bf8245f27ea08705e019 100644 (file)
@@ -411,6 +411,11 @@ int main(int argc, char *argv[])
                        return -1;
                }
 
+               if (lxc_attach_set_environment()) {
+                       ERROR("could not set environment");
+                       return -1;
+               }
+
                /* tell parent we are done setting up the container and wait
                 * until we have been put in the container's cgroup, if
                 * applicable */