annotate toys/posix/nohup.c @ 1676:cbb1aca81eca draft

Make toy_exec() check if argc is in optargs and deal with it there so we don't need a separate xexec_optargs().
author Rob Landley <rob@landley.net>
date Sat, 07 Feb 2015 16:17:44 -0600
parents e127aa575ff2
children c0ef9b7976f0
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");
1529
e127aa575ff2 More static analysis fixes from Ashwini Sharma.
Rob Landley <rob@landley.net>
parents: 1355
diff changeset
31
1183
0752b2d58909 Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents: 955
diff changeset
32 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
33 xcreate(temp, O_CREAT|O_APPEND|O_WRONLY, 0600);
1529
e127aa575ff2 More static analysis fixes from Ashwini Sharma.
Rob Landley <rob@landley.net>
parents: 1355
diff changeset
34 free(temp);
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
35 }
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 }
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 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
38 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
39 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
40 }
1676
cbb1aca81eca Make toy_exec() check if argc is in optargs and deal with it there so we don't need a separate xexec_optargs().
Rob Landley <rob@landley.net>
parents: 1529
diff changeset
41 xexec(toys.optargs);
389
5e9c1d73c84a Implement nohup.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 }