diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-01-17 03:09:36 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-01-17 03:10:53 +0300 |
commit | ccf7f0e4d3aed3bd9f46a239d9033cd773e67ab8 (patch) | |
tree | 488a7303e4994bd289eb0f3f57ea14cb3ae31aae | |
parent | 6a70db85cfc2aba89fc23edf426a47630f497eb8 (diff) |
setsid: implement -c
function old new delta
setsid_main 53 96 +43
packed_usage 30846 30833 -13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/setsid.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/miscutils/setsid.c b/miscutils/setsid.c index 637081b6c..1b27377b2 100644 --- a/miscutils/setsid.c +++ b/miscutils/setsid.c @@ -15,19 +15,22 @@ */ //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"); + 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 +64,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); } |