Annotation of 43BSDReno/usr.bin/nohup/nohup.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1989 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)nohup.c    5.4 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: #include <sys/param.h>
                     31: #include <sys/signal.h>
                     32: #include <sys/file.h>
                     33: #include <unistd.h>
                     34: #include <stdio.h>
                     35: 
                     36: extern int errno;
                     37: 
                     38: main(argc, argv)
                     39:        int argc;
                     40:        char **argv;
                     41: {
                     42:        char *strerror();
                     43: 
                     44:        if (argc < 2)
                     45:                usage();
                     46: 
                     47:        if (isatty(STDOUT_FILENO))
                     48:                dofile();
                     49:        if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1) {
                     50:                /* may have just closed stderr */
                     51:                (void)fprintf(stdin, "nohup: %s\n", strerror(errno));
                     52:                exit(1);
                     53:        }
                     54: 
                     55:        (void)signal(SIGHUP, SIG_IGN);
                     56:        (void)signal(SIGQUIT, SIG_IGN);
                     57: 
                     58:        execvp(argv[1], &argv[1]);
                     59:        (void)fprintf(stderr,
                     60:            "nohup: %s: %s\n", argv[1], strerror(errno));
                     61:        exit(1);
                     62: }
                     63: 
                     64: dofile()
                     65: {
                     66:        int fd;
                     67:        char *p, path[MAXPATHLEN];
                     68:        off_t lseek();
                     69:        char *getenv(), *strcpy(), *strcat(), *strerror();
                     70: 
                     71: #define        FILENAME        "nohup.out"
                     72:        p = FILENAME;
                     73:        if ((fd = open(p, O_RDWR|O_CREAT, 0600)) >= 0)
                     74:                goto dupit;
                     75:        if (p = getenv("HOME")) {
                     76:                (void)strcpy(path, p);
                     77:                (void)strcat(path, "/");
                     78:                (void)strcat(path, FILENAME);
                     79:                if ((fd = open(p = path, O_RDWR|O_CREAT, 0600)) >= 0)
                     80:                        goto dupit;
                     81:        }
                     82:        (void)fprintf(stderr, "nohup: can't open a nohup.out file.\n");
                     83:        exit(1);
                     84: 
                     85: dupit: (void)lseek(fd, 0L, SEEK_END);
                     86:        if (dup2(fd, STDOUT_FILENO) == -1) {
                     87:                (void)fprintf(stderr, "nohup: %s\n", strerror(errno));
                     88:                exit(1);
                     89:        }
                     90:        (void)fprintf(stderr, "sending output to %s\n", p);
                     91: }
                     92: 
                     93: usage()
                     94: {
                     95:        (void)fprintf(stderr, "usage: nohup command\n");
                     96:        exit(1);
                     97: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.