From 44afbbeecef309c91bd7c32f0e72ea74063a7ce0 Mon Sep 17 00:00:00 2001 From: Chad Loder Date: Tue, 18 Feb 2003 01:17:45 +0000 Subject: KNF and pedantification. OK millert@ --- usr.bin/nohup/nohup.c | 69 ++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 31 deletions(-) (limited to 'usr.bin/nohup') diff --git a/usr.bin/nohup/nohup.c b/usr.bin/nohup/nohup.c index c9a19ae8f31..d5e9a055c54 100644 --- a/usr.bin/nohup/nohup.c +++ b/usr.bin/nohup/nohup.c @@ -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 @@ char copyright[] = #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 @@ static char rcsid[] = "$OpenBSD: nohup.c,v 1.10 2003/02/16 03:09:50 cloder Exp $ #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 @@ main(argc, argv) 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 @@ main(argc, argv) } static void -dofile() +dofile(void) { int fd; - char *p, 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. + const char *p; + char path[MAXPATHLEN]; - 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); -- cgit v1.2.3