Rob Landley | 5023970 | 2010-01-05 13:17:47 -0600 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: |
| 2 | * |
| 3 | * setsid.c - Run program in a new session ID. |
| 4 | * |
| 5 | * Copyright 2006 Rob Landley <rob@landley.net> |
| 6 | * |
Rob Landley | 9317c06 | 2012-03-06 20:48:27 -0600 | [diff] [blame] | 7 | * Not in SUSv4. |
Rob Landley | 5023970 | 2010-01-05 13:17:47 -0600 | [diff] [blame] | 8 | |
| 9 | USE_SETSID(NEWTOY(setsid, "^<1t", TOYFLAG_USR|TOYFLAG_BIN)) |
| 10 | |
| 11 | config SETSID |
| 12 | bool "setsid" |
| 13 | default y |
| 14 | help |
| 15 | usage: setsid [-t] command [args...] |
| 16 | |
| 17 | Run process in a new session. |
| 18 | |
| 19 | -t Grab tty (become foreground process, receiving keyboard signals) |
| 20 | */ |
| 21 | |
| 22 | #include "toys.h" |
| 23 | |
| 24 | void setsid_main(void) |
| 25 | { |
| 26 | while (setsid()<0) |
| 27 | if (vfork()) _exit(0); |
| 28 | if (toys.optflags) { |
| 29 | setpgid(0,0); |
| 30 | tcsetpgrp(0, getpid()); |
| 31 | } |
| 32 | xexec(toys.optargs); |
| 33 | } |