[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 76/98: utils/settrans: fix the teardown of chrooted environments
From: |
Samuel Thibault |
Subject: |
[hurd] 76/98: utils/settrans: fix the teardown of chrooted environments |
Date: |
Tue, 14 Jan 2014 02:00:03 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 77ba38a61492799cc3c615f0f622f34fc10de826
Author: Justus Winter <address@hidden>
Date: Tue Dec 10 15:31:36 2013 +0100
utils/settrans: fix the teardown of chrooted environments
Previously, settrans --chroot would just exec the target. Create a
new process for that purpose. Wait for its completion, then ask the
translator (nicely by default) to go away. If it refuses with EBUSY,
it might be because some process has daemonized inside the chrooted
environment.
This fixes the following bug when settrans is used with fakeroot:
% fakeroot-hurd /bin/true 2>&1 | tee
<hangs>
Here, fakeroot-hurd execs settrans with --chroot, settrans execs
/hurd/fakeauth which will eventually exec the target /bin/true. When
true terminates, it will close its stdout and stderr. But
/hurd/fakeroot's stderr is also connected to tee's stdin, preventing
tee from exiting.
* utils/settrans.c (main): Fix the teardown of chrooted environments.
---
utils/settrans.c | 69 ++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 44 insertions(+), 25 deletions(-)
diff --git a/utils/settrans.c b/utils/settrans.c
index d13e7c4..ecc6d75 100644
--- a/utils/settrans.c
+++ b/utils/settrans.c
@@ -25,6 +25,7 @@
#include <error.h>
#include <fcntl.h>
#include <unistd.h>
+#include <sys/wait.h>
#include <error.h>
#include <argz.h>
@@ -279,33 +280,51 @@ main(int argc, char *argv[])
if (chroot_command)
{
- /* We will act as the parent filesystem would for a lookup
- of the active translator's root node, then use this port
- as our root directory while we exec the command. */
-
- char retry_name[1024]; /* XXX */
- retry_type do_retry;
- mach_port_t root;
- err = fsys_getroot (active_control,
- MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND,
- NULL, 0, NULL, 0, 0, &do_retry, retry_name, &root);
- mach_port_deallocate (mach_task_self (), active_control);
- if (err)
- error (6, err, "fsys_getroot");
- err = hurd_file_name_lookup_retry (&_hurd_ports_use, &getdport, 0,
- do_retry, retry_name, 0, 0,
- &root);
- if (err)
- error (6, err, "cannot resolve root port");
+ pid_t pid;
+ switch ((pid = fork ()))
+ {
+ case -1:
+ error (6, errno, "fork");
+
+ case 0:; /* Child. */
+ /* We will act as the parent filesystem would for a lookup
+ of the active translator's root node, then use this port
+ as our root directory while we exec the command. */
+
+ char retry_name[1024]; /* XXX */
+ retry_type do_retry;
+ mach_port_t root;
+ err = fsys_getroot (active_control,
+ MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND,
+ NULL, 0, NULL, 0, 0,
+ &do_retry, retry_name, &root);
+ mach_port_deallocate (mach_task_self (), active_control);
+ if (err)
+ error (6, err, "fsys_getroot");
+ err = hurd_file_name_lookup_retry (&_hurd_ports_use, &getdport, 0,
+ do_retry, retry_name, 0, 0,
+ &root);
+ if (err)
+ error (6, err, "cannot resolve root port");
+
+ if (setcrdir (root))
+ error (7, errno, "cannot install root port");
+ mach_port_deallocate (mach_task_self (), root);
+ if (chdir ("/"))
+ error (8, errno, "cannot chdir to new root");
+
+ execvp (chroot_command[0], chroot_command);
+ error (8, errno, "cannot execute %s", chroot_command[0]);
+ break;
- if (setcrdir (root))
- error (7, errno, "cannot install root port");
- mach_port_deallocate (mach_task_self (), root);
- if (chdir ("/"))
- error (8, errno, "cannot chdir to new root");
+ default: /* Parent. */
+ if (waitpid (pid, NULL, 0) == -1)
+ error (8, errno, "waitpid");
- execvp (chroot_command[0], chroot_command);
- error (8, errno, "cannot execute %s", chroot_command[0]);
+ err = fsys_goaway (active_control, goaway_flags);
+ if (err && err != EBUSY)
+ error (9, err, "fsys_goaway");
+ }
}
return 0;
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 15/98: mach-defpager: include errno.h, (continued)
- [hurd] 15/98: mach-defpager: include errno.h, Samuel Thibault, 2014/01/13
- [hurd] 91/98: trans/mtab: remove the loop detection logic, Samuel Thibault, 2014/01/13
- [hurd] 97/98: libnetfs: register passive translator startups, Samuel Thibault, 2014/01/13
- [hurd] 19/98: libdiskfs: fix error handling, Samuel Thibault, 2014/01/13
- [hurd] 11/98: mach-defpager: turn dealloc_direct into a normal function, Samuel Thibault, 2014/01/13
- [hurd] 23/98: mach-defpager: do not remove -Wall from CFLAGS, Samuel Thibault, 2014/01/13
- [hurd] 94/98: trans/mtab: do not include non-filesystem translators by default, Samuel Thibault, 2014/01/13
- [hurd] 96/98: libdiskfs: register passive translator startups, Samuel Thibault, 2014/01/13
- [hurd] 92/98: trans/mtab: properly lock mtab objects, Samuel Thibault, 2014/01/13
- [hurd] 03/98: libports: fix the thread counts in case the thread creation fails, Samuel Thibault, 2014/01/13
- [hurd] 76/98: utils/settrans: fix the teardown of chrooted environments,
Samuel Thibault <=
- [hurd] 16/98: libshouldbeinlibc: fix reference counting in port_name_xlator_create, Samuel Thibault, 2014/01/13
- [hurd] 95/98: libfshelp: fix the api of fshelp_set_active_translator, Samuel Thibault, 2014/01/13
- [hurd] 98/98: Merge remote-tracking branch 'upstream/master' into upstream, Samuel Thibault, 2014/01/13
- [hurd] 17/98: utils: implement portinfo --search, Samuel Thibault, 2014/01/13
- [hurd] 10/98: auth: fix use of uninitialized variable err, Samuel Thibault, 2014/01/13
- [hurd] 61/98: trans: fix transparent reauthentication in fakeroot, Samuel Thibault, 2014/01/13
- [hurd] 01/98: pfinet: fix emission on the loopback device, Samuel Thibault, 2014/01/13
- [hurd] 63/98: libfshelp: use a hash table in get-identity.c, Samuel Thibault, 2014/01/13
- [hurd] 90/98: trans/mtab: populate mtab objects on demand, Samuel Thibault, 2014/01/13
- [hurd] 09/98: init: fix memory leak, Samuel Thibault, 2014/01/13