Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/nohup.c

    r821 r1765  
    1 /* vi:set ts=4: */
     1/* vi: set sw=4 ts=4: */
    22/* nohup - invoke a utility immune to hangups.
    3  * 
     3 *
    44 * Busybox version based on nohup specification at
    55 * http://www.opengroup.org/onlinepubs/007904975/utilities/nohup.html
    6  * 
     6 *
    77 * Copyright 2006 Rob Landley <rob@landley.net>
    8  *
     8 * Copyright 2006 Bernhard Fischer
     9 *
    910 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    1011 */
    1112
    12 #include <fcntl.h>
    13 #include <signal.h>
    14 #include <unistd.h>
    15 #include "busybox.h"
     13#include "libbb.h"
    1614
    17 int nohup_main(int argc, char *argv[])
     15int nohup_main(int argc, char **argv);
     16int nohup_main(int argc, char **argv)
    1817{
    19     int temp, nullfd;
    20     char *nohupout = "nohup.out", *home = NULL;
     18    int nullfd;
     19    const char *nohupout;
     20    char *home = NULL;
    2121
    22     // I have no idea why the standard cares about this.
     22    xfunc_error_retval = 127;
    2323
    24     bb_default_error_retval = 127;
     24    if (argc < 2) bb_show_usage();
    2525
    26     if (argc<2) bb_show_usage();
     26    nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
     27    /* If stdin is a tty, detach from it. */
     28    if (isatty(STDIN_FILENO))
     29        dup2(nullfd, STDIN_FILENO);
    2730
    28     nullfd = bb_xopen(bb_dev_null, O_WRONLY|O_APPEND);
    29     // If stdin is a tty, detach from it.
    30 
    31     if (isatty(0)) dup2(nullfd, 0);
    32 
    33     // Redirect stdout to nohup.out, either in "." or in "$HOME".
    34 
    35     if (isatty(1)) {
    36         close(1);
     31    nohupout = "nohup.out";
     32    /* Redirect stdout to nohup.out, either in "." or in "$HOME". */
     33    if (isatty(STDOUT_FILENO)) {
     34        close(STDOUT_FILENO);
    3735        if (open(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR) < 0) {
    3836            home = getenv("HOME");
    3937            if (home) {
    40                 home = concat_path_file(home, nohupout);
    41                 bb_xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
     38                nohupout = concat_path_file(home, nohupout);
     39                xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
    4240            }
    4341        }
    44     } else dup2(nullfd, 1);
     42    } else dup2(nullfd, STDOUT_FILENO);
    4543
    46     // If we have a tty on strderr, announce filename and redirect to stdout.
    47     // Else redirect to /dev/null.
     44    /* If we have a tty on stderr, announce filename and redirect to stdout.
     45     * Else redirect to /dev/null.
     46     */
     47    if (isatty(STDERR_FILENO)) {
     48        bb_error_msg("appending to %s", nohupout);
     49        dup2(STDOUT_FILENO, STDERR_FILENO);
     50    } else dup2(nullfd, STDERR_FILENO);
    4851
    49     temp = isatty(2);
    50     if (temp) fdprintf(2,"Writing to %s\n", home ? home : nohupout);
    51     dup2(temp ? 1 : nullfd, 2);
    52     close(nullfd);
    53     signal (SIGHUP, SIG_IGN);
     52    if (nullfd > 2)
     53        close(nullfd);
     54    signal(SIGHUP, SIG_IGN);
    5455
    55     // Exec our new program.
    56 
    57     execvp(argv[1],argv+1);
    58     if (ENABLE_FEATURE_CLEAN_UP) free(home);
    59     bb_error_msg_and_die("exec %s",argv[1]);
     56    BB_EXECVP(argv[1], argv+1);
     57    if (ENABLE_FEATURE_CLEAN_UP && home)
     58        free((char*)nohupout);
     59    bb_perror_msg_and_die("%s", argv[1]);
    6060}
Note: See TracChangeset for help on using the changeset viewer.