1303 files changed, 32187 insertions, 57138 deletions
diff --git a/miscutils/setsid.c b/miscutils/setsid.c index 637081b..143a8f8 100644 --- a/miscutils/setsid.c +++ b/miscutils/setsid.c @@ -13,21 +13,33 @@ * 2004-11-12 Paul Fox * - busyboxed */ +//config:config SETSID +//config: bool "setsid" +//config: default y +//config: help +//config: setsid runs a program in a new session + +//applet:IF_SETSID(APPLET(setsid, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SETSID) += setsid.o //usage:#define setsid_trivial_usage -//usage: "PROG ARGS" +//usage: "[-c] PROG ARGS" //usage:#define setsid_full_usage "\n\n" //usage: "Run PROG in a new session. PROG will have no controlling terminal\n" -//usage: "and will not be affected by keyboard signals (Ctrl-C etc).\n" -//usage: "See setsid(2) for details." +//usage: "and will not be affected by keyboard signals (^C etc).\n" +//usage: "\n -c Set controlling terminal to stdin" #include "libbb.h" int setsid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int setsid_main(int argc UNUSED_PARAM, char **argv) { - if (!argv[1]) - bb_show_usage(); + unsigned opt; + + opt_complementary = "-1"; /* at least one arg */ + opt = getopt32(argv, "+c"); /* +: stop on first non-opt */ + argv += optind; /* setsid() is allowed only when we are not a process group leader. * Otherwise our PID serves as PGID of some existing process group @@ -61,6 +73,10 @@ int setsid_main(int argc UNUSED_PARAM, char **argv) setsid(); } - argv++; + if (opt) { + /* -c: set (with stealing) controlling tty */ + ioctl(0, TIOCSCTTY, 1); + } + BB_EXECVP_or_die(argv); } |