Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/nohup.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 984 - (hide annotations) (download)
Sun May 30 11:32:42 2010 UTC (13 years, 11 months ago) by niro
File MIME type: text/plain
File size: 2122 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 niro 532 /* vi: set sw=4 ts=4: */
2     /* nohup - invoke a utility immune to hangups.
3     *
4     * Busybox version based on nohup specification at
5     * http://www.opengroup.org/onlinepubs/007904975/utilities/nohup.html
6     *
7     * Copyright 2006 Rob Landley <rob@landley.net>
8 niro 816 * Copyright 2006 Bernhard Reutner-Fischer
9 niro 532 *
10     * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11     */
12    
13 niro 816 #include "libbb.h"
14 niro 532
15 niro 816 /* Compat info: nohup (GNU coreutils 6.8) does this:
16     # nohup true
17     nohup: ignoring input and appending output to `nohup.out'
18     # nohup true 1>/dev/null
19     nohup: ignoring input and redirecting stderr to stdout
20     # nohup true 2>zz
21     # cat zz
22     nohup: ignoring input and appending output to `nohup.out'
23     # nohup true 2>zz 1>/dev/null
24     # cat zz
25     nohup: ignoring input
26     # nohup true </dev/null 1>/dev/null
27     nohup: redirecting stderr to stdout
28     # nohup true </dev/null 2>zz 1>/dev/null
29     # cat zz
30     (nothing)
31     #
32     */
33    
34     int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
35 niro 984 int nohup_main(int argc UNUSED_PARAM, char **argv)
36 niro 532 {
37 niro 816 const char *nohupout;
38     char *home;
39 niro 532
40     xfunc_error_retval = 127;
41    
42 niro 984 if (!argv[1]) {
43     bb_show_usage();
44     }
45 niro 532
46     /* If stdin is a tty, detach from it. */
47 niro 816 if (isatty(STDIN_FILENO)) {
48     /* bb_error_msg("ignoring input"); */
49     close(STDIN_FILENO);
50     xopen(bb_dev_null, O_RDONLY); /* will be fd 0 (STDIN_FILENO) */
51     }
52 niro 532
53     nohupout = "nohup.out";
54     /* Redirect stdout to nohup.out, either in "." or in "$HOME". */
55     if (isatty(STDOUT_FILENO)) {
56     close(STDOUT_FILENO);
57     if (open(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR) < 0) {
58     home = getenv("HOME");
59     if (home) {
60     nohupout = concat_path_file(home, nohupout);
61     xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
62 niro 816 } else {
63     xopen(bb_dev_null, O_RDONLY); /* will be fd 1 */
64 niro 532 }
65     }
66 niro 816 bb_error_msg("appending output to %s", nohupout);
67     }
68 niro 532
69 niro 816 /* If we have a tty on stderr, redirect to stdout. */
70     if (isatty(STDERR_FILENO)) {
71     /* if (stdout_wasnt_a_tty)
72     bb_error_msg("redirecting stderr to stdout"); */
73     dup2(STDOUT_FILENO, STDERR_FILENO);
74     }
75 niro 532
76 niro 816 signal(SIGHUP, SIG_IGN);
77    
78     BB_EXECVP(argv[1], argv+1);
79     bb_simple_perror_msg_and_die(argv[1]);
80 niro 532 }