Mercurial > hg > toybox
annotate toys/nohup.c @ 422:82d70cff7357
Very slight efficiency tweak.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 02 Feb 2012 07:42:31 -0600 |
parents | 5e9c1d73c84a |
children |
rev | line source |
---|---|
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); | |
422
82d70cff7357
Very slight efficiency tweak.
Rob Landley <rob@landley.net>
parents:
389
diff
changeset
|
27 if (isatty(1)) { |
389 | 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 } | |
422
82d70cff7357
Very slight efficiency tweak.
Rob Landley <rob@landley.net>
parents:
389
diff
changeset
|
37 if (isatty(0)) { |
389 | 38 close(0); |
39 open("/dev/null", O_RDONLY); | |
40 } | |
41 xexec(toys.optargs); | |
42 } |