]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
change to the same directory when attaching
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 8 Apr 2010 07:44:23 +0000 (09:44 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 8 Apr 2010 07:44:23 +0000 (09:44 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/lxc_attach.c

index bae76ed4e15cc44a48d8592416f02373130c8c8a..13e1518f2af2736c12f88c0a38ffc8d68fa88fae 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define _GNU_SOURCE
 #include <unistd.h>
 #include <errno.h>
-#include <sys/param.h>
 #include <pwd.h>
+#include <stdlib.h>
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -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) {