Commit b3a39ba6 by David Ward Committed by Stéphane Graber

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: 's avatarDavid Ward <david.ward@ll.mit.edu> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 89d556d8
...@@ -277,6 +277,21 @@ int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx) ...@@ -277,6 +277,21 @@ int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx)
return 0; 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) char *lxc_attach_getpwshell(uid_t uid)
{ {
/* local variables */ /* local variables */
......
...@@ -37,6 +37,7 @@ extern struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid); ...@@ -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_to_ns(pid_t other_pid, int which);
extern int lxc_attach_remount_sys_proc(); extern int lxc_attach_remount_sys_proc();
extern int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx); 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); extern char *lxc_attach_getpwshell(uid_t uid);
......
...@@ -411,6 +411,11 @@ int main(int argc, char *argv[]) ...@@ -411,6 +411,11 @@ int main(int argc, char *argv[])
return -1; 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 /* tell parent we are done setting up the container and wait
* until we have been put in the container's cgroup, if * until we have been put in the container's cgroup, if
* applicable */ * applicable */
......
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