From 2904747da9e41440ebe593ff2cabb601538c3eaf Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 27 Jan 2024 23:03:12 -0600 Subject: [PATCH] Teach setsid to grab tty more forcefully, and that -cc means steal. --- toys/other/setsid.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/toys/other/setsid.c b/toys/other/setsid.c index 654ce7a1..c6e0c53d 100644 --- a/toys/other/setsid.c +++ b/toys/other/setsid.c @@ -2,7 +2,7 @@ * * Copyright 2006 Rob Landley -USE_SETSID(NEWTOY(setsid, "^<1wcd[!dc]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_SETSID(NEWTOY(setsid, "^<1wc@d[!dc]", TOYFLAG_USR|TOYFLAG_BIN)) config SETSID bool "setsid" @@ -13,13 +13,17 @@ config SETSID Run process in a new session. -d Detach from tty - -c Control tty (become foreground process & receive keyboard signals) + -c Control tty (repeat to steal) -w Wait for child (and exit with its status) */ #define FOR_setsid #include "toys.h" +GLOBALS( + long c; +) + void setsid_main(void) { int i; @@ -43,8 +47,10 @@ void setsid_main(void) } } - if (FLAG(c)) tcsetpgrp(0, getpid()); - if (FLAG(d) && (i = open("/dev/tty", O_RDONLY)) != -1) { + if (FLAG(c)) { + ioctl(0, TIOCSCTTY, TT.c>1); + tcsetpgrp(0, getpid()); + } if (FLAG(d) && (i = open("/dev/tty", O_RDONLY)) != -1) { ioctl(i, TIOCNOTTY); close(i); } -- 2.39.2