annotate toys/posix/nohup.c @ 1008:a55854bde872

su: cleanery * make help message more like others * s/TT\.(.)Argu/TT.\1/g * move environ to toys.h * simplify failure messages * clear password before quit * not check what execve returns * -lc
author Strake <strake888@gmail.com>
date Sat, 17 Aug 2013 02:54:58 -0500
parents 144d5ba7d410
children 0752b2d58909
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
1 /* nohup.c - run commandline with SIGHUP blocked.
389
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2011 Rob Landley <rob@landley.net>
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 USE_NOHUP(NEWTOY(nohup, "<1", TOYFLAG_USR|TOYFLAG_BIN))
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config NOHUP
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
10 bool "nohup"
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
11 default y
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
12 help
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
13 usage: nohup COMMAND [ARGS...]
389
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
15 Run a command that survives the end of its terminal.
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
16 If stdin is a tty, redirect from /dev/null
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
17 If stdout is a tty, redirect to file "nohup.out"
389
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 void nohup_main(void)
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
24 signal(SIGHUP, SIG_IGN);
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
25 if (isatty(1)) {
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
26 close(1);
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
27 if (-1 == open("nohup.out", O_CREAT|O_APPEND|O_WRONLY,
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
28 S_IRUSR|S_IWUSR ))
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
29 {
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
30 char *temp = getenv("HOME");
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
31 temp = xmsprintf("%s/%s", temp ? temp : "", "nohup.out");
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
32 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
33 }
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
34 }
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
35 if (isatty(0)) {
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
36 close(0);
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
37 open("/dev/null", O_RDONLY);
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.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
38 }
955
144d5ba7d410 Replace users of xexec(toys.optargs) with xexec_optargs(0) to avoid free/reuse bug during argument parsing.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
39 xexec_optargs(0);
389
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 }