=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/nohup/nohup.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- src/usr.bin/nohup/nohup.c 2003/02/16 03:09:50 1.10 +++ src/usr.bin/nohup/nohup.c 2003/02/18 01:17:44 1.11 @@ -1,4 +1,4 @@ -/* $OpenBSD: nohup.c,v 1.10 2003/02/16 03:09:50 cloder Exp $ */ +/* $OpenBSD: nohup.c,v 1.11 2003/02/18 01:17:44 cloder Exp $ */ /* $NetBSD: nohup.c,v 1.6 1995/08/31 23:35:25 jtc Exp $ */ /* @@ -44,7 +44,7 @@ #if 0 static char sccsid[] = "@(#)nohup.c 5.4 (Berkeley) 6/1/90"; #endif -static char rcsid[] = "$OpenBSD: nohup.c,v 1.10 2003/02/16 03:09:50 cloder Exp $"; +static char rcsid[] = "$OpenBSD: nohup.c,v 1.11 2003/02/18 01:17:44 cloder Exp $"; #endif /* not lint */ #include @@ -59,21 +59,34 @@ #include #include -static void dofile(); -static void usage(); +static void dofile(void); +__dead static void usage(void); -/* nohup shall exit with one of the following values: - 126 - The utility was found but could not be invoked. - 127 - An error occurred in the nohup utility, or the utility could - not be found. */ +/* + * nohup shall exit with one of the following values: + * 126 - The utility was found but could not be invoked. + * 127 - An error occurred in the nohup utility, or the utility could + * not be found. + */ #define EXIT_NOEXEC 126 #define EXIT_NOTFOUND 127 #define EXIT_MISC 127 +/* + * 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" + int -main(argc, argv) - int argc; - char **argv; +main(int argc, char *argv[]) { int exit_status; @@ -88,8 +101,10 @@ exit(EXIT_MISC); } - /* The nohup utility shall take the standard action for all signals - except that SIGHUP shall be ignored. */ + /* + * The nohup utility shall take the standard action for all signals + * except that SIGHUP shall be ignored. + */ (void)signal(SIGHUP, SIG_IGN); execvp(argv[1], &argv[1]); @@ -98,42 +113,34 @@ } static void -dofile() +dofile(void) { int fd; - char *p, path[MAXPATHLEN]; + const char *p; + char path[MAXPATHLEN]; - /* 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" p = FILENAME; if ((fd = open(p, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0) goto dupit; if ((p = getenv("HOME")) != NULL && *p != '\0' && (strlen(p) + strlen(FILENAME) + 1) < sizeof(path)) { - (void)strlcpy(path, p, sizeof path); - (void)strlcat(path, "/", sizeof path); - (void)strlcat(path, FILENAME, sizeof path); + (void)strlcpy(path, p, sizeof(path)); + (void)strlcat(path, "/", sizeof(path)); + (void)strlcat(path, FILENAME, sizeof(path)); if ((fd = open(p = path, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0) goto dupit; } errx(EXIT_MISC, "can't open a nohup.out file"); -dupit: (void)lseek(fd, 0, SEEK_END); +dupit: + (void)lseek(fd, (off_t)0, SEEK_END); if (dup2(fd, STDOUT_FILENO) == -1) err(EXIT_MISC, NULL); (void)fprintf(stderr, "sending output to %s\n", p); } -static void -usage() +__dead static void +usage(void) { (void)fprintf(stderr, "usage: nohup command\n"); exit(EXIT_MISC);