From: David Ward Date: Wed, 20 Mar 2013 16:08:29 +0000 (-0400) Subject: lxc-attach: Clear environment and set container=lxc X-Git-Tag: lxc-0.9.0~1^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3a39ba6bd4c3c3739006775ecef6207f9dcba31;p=thirdparty%2Flxc.git lxc-attach: Clear environment and set container=lxc 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 Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 2f3202539..12adadb56 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -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 */ diff --git a/src/lxc/attach.h b/src/lxc/attach.h index 6bbfb425d..404ff4c22 100644 --- a/src/lxc/attach.h +++ b/src/lxc/attach.h @@ -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); diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c index 678b76d53..7fd76ee21 100644 --- a/src/lxc/lxc_attach.c +++ b/src/lxc/lxc_attach.c @@ -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 */