Mercurial > hg > toybox
comparison toys/posix/nohup.c @ 694:786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 2986aa63a021 |
children | 144d5ba7d410 |
comparison
equal
deleted
inserted
replaced
693:4a5a250e0633 | 694:786841fdb1e0 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* nohup.c - run commandline with SIGHUP blocked. |
2 * | |
3 * nohup.c - run commandline with SIGHUP blocked. | |
4 * | 2 * |
5 * Copyright 2011 Rob Landley <rob@landley.net> | 3 * Copyright 2011 Rob Landley <rob@landley.net> |
6 * | 4 * |
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html | 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html |
8 | 6 |
9 USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN)) | 7 USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN)) |
10 | 8 |
11 config NOHUP | 9 config NOHUP |
12 bool "nohup" | 10 bool "nohup" |
13 default y | 11 default y |
14 help | 12 help |
15 usage: nohup COMMAND [ARGS...] | 13 usage: nohup COMMAND [ARGS...] |
16 | 14 |
17 Run a command that survives the end of its terminal. | 15 Run a command that survives the end of its terminal. |
18 If stdin is a tty, redirect from /dev/null | 16 If stdin is a tty, redirect from /dev/null |
19 If stdout is a tty, redirect to file "nohup.out" | 17 If stdout is a tty, redirect to file "nohup.out" |
20 */ | 18 */ |
21 | 19 |
22 #include "toys.h" | 20 #include "toys.h" |
23 | 21 |
24 void nohup_main(void) | 22 void nohup_main(void) |
25 { | 23 { |
26 signal(SIGHUP, SIG_IGN); | 24 signal(SIGHUP, SIG_IGN); |
27 if (isatty(1)) { | 25 if (isatty(1)) { |
28 close(1); | 26 close(1); |
29 if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY, | 27 if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY, |
30 S_IRUSR|S_IWUSR )) | 28 S_IRUSR|S_IWUSR )) |
31 { | 29 { |
32 char *temp = getenv("HOME"); | 30 char *temp = getenv("HOME"); |
33 temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out"); | 31 temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out"); |
34 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR); | 32 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR); |
35 } | 33 } |
36 } | 34 } |
37 if (isatty(0)) { | 35 if (isatty(0)) { |
38 close(0); | 36 close(0); |
39 open("/dev/null", O_RDONLY); | 37 open("/dev/null", O_RDONLY); |
40 } | 38 } |
41 xexec(toys.optargs); | 39 xexec(toys.optargs); |
42 } | 40 } |