389
|
1 /* vi: set sw=4 ts=4:
|
|
2 *
|
|
3 * nohup.c - run commandline with SIGHUP blocked.
|
|
4 *
|
|
5 * Copyright 2011 Rob Landley <rob@landley.net>
|
|
6 *
|
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html
|
|
8
|
|
9 USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN))
|
|
10
|
|
11 config NOHUP
|
|
12 bool "nohup"
|
|
13 default y
|
|
14 help
|
|
15 usage: nohup COMMAND [ARGS...]
|
|
16
|
|
17 Run a command that survives the end of its terminal.
|
|
18 If stdin is a tty, redirect from /dev/null
|
|
19 If stdout is a tty, redirect to file "nohup.out"
|
|
20 */
|
|
21
|
|
22 #include "toys.h"
|
|
23
|
|
24 void nohup_main(void)
|
|
25 {
|
|
26 signal(SIGHUP, SIG_IGN);
|
|
27 if (ttyname(1)) {
|
|
28 close(1);
|
|
29 if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY,
|
|
30 S_IRUSR|S_IWUSR ))
|
|
31 {
|
|
32 char *temp = getenv("HOME");
|
|
33 temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out");
|
|
34 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
|
35 }
|
|
36 }
|
|
37 if (ttyname(0)) {
|
|
38 close(0);
|
|
39 open("/dev/null", O_RDONLY);
|
|
40 }
|
|
41 xexec(toys.optargs);
|
|
42 }
|