From: Daniel Lezcano Date: Thu, 8 Apr 2010 07:44:23 +0000 (+0200) Subject: change to the same directory when attaching X-Git-Tag: lxc-0.7.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b30b861579107f638d0c5b6ce22dbedf99fa4b7;p=thirdparty%2Flxc.git change to the same directory when attaching This patch will try to change the default "/" directory to the directory we were before attaching. In order to work correctly, the path has to exist in the container, that makes sense with a shared file system without rootfs. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c index bae76ed4e..13e1518f2 100644 --- a/src/lxc/lxc_attach.c +++ b/src/lxc/lxc_attach.c @@ -21,10 +21,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define _GNU_SOURCE #include #include -#include #include +#include +#include #include #include @@ -87,6 +89,7 @@ int main(int argc, char *argv[], char *envp[]) pid_t pid; struct passwd *passwd; uid_t uid; + char *curdir; ret = lxc_arguments_parse(&my_args, argc, argv); if (ret) @@ -103,12 +106,19 @@ int main(int argc, char *argv[], char *envp[]) return -1; } + curdir = get_current_dir_name(); + ret = lxc_attach(pid); if (ret < 0) { ERROR("failed to enter the namespace"); return -1; } + if (curdir && chdir(curdir)) + WARN("could not change directory to '%s'", curdir); + + free(curdir); + pid = fork(); if (pid < 0) {