annotate toys/posix/nohup.c @ 1355:76965793e8f4 draft

Option parsing for nohup needs to stop at first nonoption argument. Minor cleanups.
author Rob Landley <rob@landley.net>
date Wed, 11 Jun 2014 22:43:54 -0500
parents 0752b2d58909
children e127aa575ff2
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
1355
76965793e8f4 Option parsing for nohup needs to stop at first nonoption argument. Minor cleanups.
Rob Landley <rob@landley.net>
parents: 1183
diff changeset
7 USE_NOHUP(NEWTOY(nohup, "<1^", TOYFLAG_USR|TOYFLAG_BIN))
389
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.
1355
76965793e8f4 Option parsing for nohup needs to stop at first nonoption argument. Minor cleanups.
Rob Landley <rob@landley.net>
parents: 1183
diff changeset
16
76965793e8f4 Option parsing for nohup needs to stop at first nonoption argument. Minor cleanups.
Rob Landley <rob@landley.net>
parents: 1183
diff changeset
17 Redirect tty on stdin to /dev/null, tty on stdout to "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");
1183
0752b2d58909 Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents: 955
diff changeset
31 temp = xmprintf("%s/%s", temp ? temp : "", "nohup.out");
1355
76965793e8f4 Option parsing for nohup needs to stop at first nonoption argument. Minor cleanups.
Rob Landley <rob@landley.net>
parents: 1183
diff changeset
32 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, 0600);
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
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 }