[lxc-devel] [PATCH] lxc-attach: Clear environment and set container=lxc
Serge Hallyn
serge.hallyn at ubuntu.com
Wed Mar 20 17:31:58 UTC 2013
Quoting David Ward (david.ward at ll.mit.edu):
> 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 at ll.mit.edu>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> ---
> src/lxc/attach.c | 15 +++++++++++++++
> src/lxc/attach.h | 1 +
> src/lxc/lxc_attach.c | 5 +++++
> 3 files changed, 21 insertions(+), 0 deletions(-)
>
> diff --git a/src/lxc/attach.c b/src/lxc/attach.c
> index 2f32025..12adadb 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 6bbfb42..404ff4c 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 678b76d..7fd76ee 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 */
> --
> 1.7.1
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
More information about the lxc-devel
mailing list