aboutsummaryrefslogtreecommitdiff
path: root/init/init.c
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2007-09-24 18:30:38 +0200
committerWilly Tarreau <w@1wt.eu>2007-09-24 18:30:38 +0200
commit9eaf3615faefd295b6929ee02f2ae147d4099b88 (patch)
treec22357ea0f0637e088e475e9ce352a8c253b6f5d /init/init.c
parentbuild.cfg: added the tar_src command. (diff)
downloadflxutils-9eaf3615faefd295b6929ee02f2ae147d4099b88.tar.xz
init: set controlling TTY when executing programs
With this add-on, Ctrl-C works for any program executed from init.
Diffstat (limited to '')
-rw-r--r--init/init.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/init/init.c b/init/init.c
index ab97ece..58f57d8 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1578,21 +1578,22 @@ int main(int argc, char **argv, char **envp) {
/* fall through TOK_RX */
case TOK_RX: {
/* R dir cmd [cfg_args] : execute cmd with cfg_args, chrooted to dir */
- char **exec_args, *exec_dir;
int res;
- exec_args = cfg_args + 1;
- if (token == TOK_EX) {
- exec_dir = (char *)root_dir;
- }
- else {
- exec_dir = cfg_args[1];
- exec_args++;
- }
-
res = fork();
if (res == 0) {
- chroot(exec_dir);
+ char **exec_args;
+
+ setsid();
+ ioctl(0, TIOCSCTTY, 1); // become the controlling tty, allow Ctrl-C
+
+ exec_args = cfg_args + 1;
+ if (token == TOK_RX) {
+ chroot(*exec_args);
+ exec_args++;
+ }
+
+ /* FIXME: no chdir("/") ??? */
execve(exec_args[0], exec_args, envp);
print("<E>xec(child) : execve() failed\n");
return 1;