Bring up to date to 1003.2 (Draft 11.2) compliance.
authorJ.T. Conklin <jtc@winsey.com>
Thu, 15 Jul 1993 01:20:03 +0000 (01:20 +0000)
committerJ.T. Conklin <jtc@winsey.com>
Thu, 15 Jul 1993 01:20:03 +0000 (01:20 +0000)
usr.bin/nohup/nohup.1
usr.bin/nohup/nohup.c

index a3601f1..70eb8aa 100644 (file)
@@ -42,7 +42,7 @@
 .Nd invoke a command immune to hangups
 .Sh SYNOPSIS
 .Nm nohup
 .Nd invoke a command immune to hangups
 .Sh SYNOPSIS
 .Nm nohup
-.Ar command
+.Ar utility
 .Op Ar arg ...
 .Sh DESCRIPTION
 The
 .Op Ar arg ...
 .Sh DESCRIPTION
 The
@@ -53,20 +53,13 @@ with
 its arguments
 and at this time sets the signal
 .Dv SIGHUP
 its arguments
 and at this time sets the signal
 .Dv SIGHUP
-to be ignored. The signal
-.Dv SIGQUIT
-may also be set
-to be ignored.
+to be ignored. 
 If the standard output is a terminal, the standard output is
 appended to the file
 .Pa nohup.out
 in the current directory.
 If standard error is a terminal, it is directed to the same place
 as the standard output.
 If the standard output is a terminal, the standard output is
 appended to the file
 .Pa nohup.out
 in the current directory.
 If standard error is a terminal, it is directed to the same place
 as the standard output.
-.Pp
-.Nm Nohup
-exits 1 if an error occurs, otherwise the exit status is that of
-.Ar command  .
 .Sh ENVIRONMENT
 The following variable is utilized by
 .Nm nohup .
 .Sh ENVIRONMENT
 The following variable is utilized by
 .Nm nohup .
@@ -80,6 +73,26 @@ utility uses the directory named by
 .Ev HOME
 to create the file.
 .El
 .Ev HOME
 to create the file.
 .El
+.Sh DIAGNOSTICS
+The
+.Nm nohup
+utility shall exit with one of the following values:
+.Bl -tag -width Ds 
+.It 126
+The
+.Ar utility
+was found but could not be invoked.
+.It 127
+The
+.Ar utility
+could not be found or an error occured in 
+.Nm nohup.
+.El
+.Pp
+Otherwise, the exit status of 
+.Nm nohup
+shall be that of 
+.Ar utility .
 .Sh SEE ALSO
 .Xr signal 3
 .Sh STANDARDS
 .Sh SEE ALSO
 .Xr signal 3
 .Sh STANDARDS
index 7401dc0..14ea695 100644 (file)
@@ -44,16 +44,31 @@ static char sccsid[] = "@(#)nohup.c 5.4 (Berkeley) 6/1/90";
 #include <sys/param.h>
 #include <sys/signal.h>
 #include <sys/file.h>
 #include <sys/param.h>
 #include <sys/signal.h>
 #include <sys/file.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 
-extern int errno;
+static void dofile();
+static void usage();
 
 
+/* nohup shall exit with one of the following values:
+   126 - The utility was found but could not be invoked.
+   127 - An error occured in the nohup utility, or the utility could
+         not be found. */
+#define EXIT_NOEXEC    126
+#define EXIT_NOTFOUND  127
+#define EXIT_MISC      127
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       char *strerror();
+       int exit_status;
 
        if (argc < 2)
                usage();
 
        if (argc < 2)
                usage();
@@ -63,49 +78,58 @@ main(argc, argv)
        if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1) {
                /* may have just closed stderr */
                (void)fprintf(stdin, "nohup: %s\n", strerror(errno));
        if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1) {
                /* may have just closed stderr */
                (void)fprintf(stdin, "nohup: %s\n", strerror(errno));
-               exit(1);
+               exit(EXIT_MISC);
        }
 
        }
 
+       /* The nohup utility shall take the standard action for all signals
+          except that SIGHUP shall be ignored. */
        (void)signal(SIGHUP, SIG_IGN);
        (void)signal(SIGHUP, SIG_IGN);
-       (void)signal(SIGQUIT, SIG_IGN);
 
        execvp(argv[1], &argv[1]);
 
        execvp(argv[1], &argv[1]);
-       (void)fprintf(stderr,
-           "nohup: %s: %s\n", argv[1], strerror(errno));
-       exit(1);
+       exit_status = (errno = ENOENT) ? EXIT_NOTFOUND : EXIT_NOEXEC;
+       (void)fprintf(stderr, "nohup: %s: %s\n", argv[1], strerror(errno));
+       exit(exit_status);
 }
 
 }
 
+static void
 dofile()
 {
        int fd;
        char *p, path[MAXPATHLEN];
 dofile()
 {
        int fd;
        char *p, path[MAXPATHLEN];
-       off_t lseek();
-       char *getenv(), *strcpy(), *strcat(), *strerror();
 
 
+       /* If the standard output is a terminal, all output written to 
+          its standard output shall be appended to the end of the file
+          nohup.out in the current directory.  If nohup.out cannot be
+          created or opened for appending, the output shall be appended
+          to the end of the file nohup.out in the directory specified 
+          by the HOME environment variable.
+
+          If a file is created, the file's permission bits shall be
+          set to S_IRUSR | S_IWUSR. */
 #define        FILENAME        "nohup.out"
 #define        FILENAME        "nohup.out"
-       p = FILENAME;
-       if ((fd = open(p, O_RDWR|O_CREAT, 0600)) >= 0)
+       if ((fd = open(FILENAME, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0)
                goto dupit;
                goto dupit;
-       if (p = getenv("HOME")) {
+       if ((p = getenv("HOME")) != NULL) {
                (void)strcpy(path, p);
                (void)strcat(path, "/");
                (void)strcat(path, FILENAME);
                (void)strcpy(path, p);
                (void)strcat(path, "/");
                (void)strcat(path, FILENAME);
-               if ((fd = open(p = path, O_RDWR|O_CREAT, 0600)) >= 0)
+               if ((fd = open(p = path, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0)
                        goto dupit;
        }
        (void)fprintf(stderr, "nohup: can't open a nohup.out file.\n");
                        goto dupit;
        }
        (void)fprintf(stderr, "nohup: can't open a nohup.out file.\n");
-       exit(1);
+       exit(EXIT_MISC);
 
 dupit: (void)lseek(fd, 0L, SEEK_END);
        if (dup2(fd, STDOUT_FILENO) == -1) {
                (void)fprintf(stderr, "nohup: %s\n", strerror(errno));
 
 dupit: (void)lseek(fd, 0L, SEEK_END);
        if (dup2(fd, STDOUT_FILENO) == -1) {
                (void)fprintf(stderr, "nohup: %s\n", strerror(errno));
-               exit(1);
+               exit(EXIT_MISC);
        }
        (void)fprintf(stderr, "sending output to %s\n", p);
 }
 
        }
        (void)fprintf(stderr, "sending output to %s\n", p);
 }
 
+static void
 usage()
 {
        (void)fprintf(stderr, "usage: nohup command\n");
 usage()
 {
        (void)fprintf(stderr, "usage: nohup command\n");
-       exit(1);
+       exit(EXIT_MISC);
 }
 }