diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2011-08-22 19:32:43 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2011-08-22 19:32:43 +0000 |
commit | 8be7072def5077d39b591d2edcfc510b7e3369ff (patch) | |
tree | bb2b34876e9cea2b77d1a3845ecf953763f3eed8 /usr.sbin/cron | |
parent | 04daeb6083e692b48bf3ed34b10bb3da70b5ce5e (diff) |
Use standard EXIT_SUCCESS/EXIT_FAILURE and STD{IN,OUT,ERR}_FILENO
defines instead of using custom macros. OK deraadt@ gilles@
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r-- | usr.sbin/cron/atrun.c | 64 | ||||
-rw-r--r-- | usr.sbin/cron/cron.c | 18 | ||||
-rw-r--r-- | usr.sbin/cron/crontab.c | 62 | ||||
-rw-r--r-- | usr.sbin/cron/do_command.c | 38 | ||||
-rw-r--r-- | usr.sbin/cron/macros.h | 7 | ||||
-rw-r--r-- | usr.sbin/cron/misc.c | 50 | ||||
-rw-r--r-- | usr.sbin/cron/popen.c | 14 |
7 files changed, 124 insertions, 129 deletions
diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c index dca90304217..a5cc78dc61c 100644 --- a/usr.sbin/cron/atrun.c +++ b/usr.sbin/cron/atrun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atrun.c,v 1.17 2011/03/03 15:08:14 millert Exp $ */ +/* $OpenBSD: atrun.c,v 1.18 2011/08/22 19:32:42 millert Exp $ */ /* * Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -286,41 +286,41 @@ run_job(atjob *job, char *atfile) pw = getpwuid(job->uid); if (pw == NULL) { log_it("CRON", getpid(), "ORPHANED JOB", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #if (defined(BSD)) && (BSD >= 199103) if (pw->pw_expire && time(NULL) >= pw->pw_expire) { log_it(pw->pw_name, getpid(), "ACCOUNT EXPIRED, JOB ABORTED", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #endif /* Sanity checks */ if (fstat(fd, &statbuf) < OK) { log_it(pw->pw_name, getpid(), "FSTAT FAILED", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (!S_ISREG(statbuf.st_mode)) { log_it(pw->pw_name, getpid(), "NOT REGULAR", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if ((statbuf.st_mode & ALLPERMS) != (S_IRUSR | S_IWUSR | S_IXUSR)) { log_it(pw->pw_name, getpid(), "BAD FILE MODE", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (statbuf.st_uid != 0 && statbuf.st_uid != job->uid) { log_it(pw->pw_name, getpid(), "WRONG FILE OWNER", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (statbuf.st_nlink > 1) { log_it(pw->pw_name, getpid(), "BAD LINK COUNT", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if ((fp = fdopen(dup(fd), "r")) == NULL) { log_it("CRON", getpid(), "error", "dup(2) failed"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } /* @@ -371,14 +371,14 @@ run_job(atjob *job, char *atfile) (void)fclose(fp); if (!safe_p(pw->pw_name, mailto)) - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); if ((uid_t)nuid != job->uid) { log_it(pw->pw_name, getpid(), "UID MISMATCH", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if ((gid_t)ngid != job->gid) { log_it(pw->pw_name, getpid(), "GID MISMATCH", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } /* mark ourselves as different to PS command watchers */ @@ -390,7 +390,7 @@ run_job(atjob *job, char *atfile) switch ((pid = fork())) { case -1: log_it("CRON", getpid(), "error", "can't fork"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); /*NOTREACHED*/ case 0: Debug(DPROC, ("[%ld] grandchild process fork()'ed\n", @@ -405,19 +405,19 @@ run_job(atjob *job, char *atfile) /* Connect grandchild's stdin to the at job file. */ if (lseek(fd, (off_t) 0, SEEK_SET) < 0) { perror("lseek"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } - if (fd != STDIN) { - dup2(fd, STDIN); + if (fd != STDIN_FILENO) { + dup2(fd, STDIN_FILENO); close(fd); } /* Connect stdout/stderr to the pipe from our parent. */ - if (output_pipe[WRITE_PIPE] != STDOUT) { - dup2(output_pipe[WRITE_PIPE], STDOUT); + if (output_pipe[WRITE_PIPE] != STDOUT_FILENO) { + dup2(output_pipe[WRITE_PIPE], STDOUT_FILENO); close(output_pipe[WRITE_PIPE]); } - dup2(STDOUT, STDERR); + dup2(STDOUT_FILENO, STDERR_FILENO); close(output_pipe[READ_PIPE]); (void) setsid(); @@ -432,7 +432,7 @@ run_job(atjob *job, char *atfile) fprintf(stderr, "Cannot get login class for %s\n", pw->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } @@ -440,18 +440,18 @@ run_job(atjob *job, char *atfile) fprintf(stderr, "setusercontext failed for %s\n", pw->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } # ifdef BSD_AUTH as = auth_open(); if (as == NULL || auth_setpwd(as, pw) != 0) { fprintf(stderr, "can't malloc\n"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (auth_approval(as, lc, pw->pw_name, "cron") <= 0) { fprintf(stderr, "approval failed for %s\n", pw->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } auth_close(as); # endif /* BSD_AUTH */ @@ -461,7 +461,7 @@ run_job(atjob *job, char *atfile) if (setgid(pw->pw_gid) || initgroups(pw->pw_name, pw->pw_gid)) { fprintf(stderr, "unable to set groups for %s\n", pw->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #if (defined(BSD)) && (BSD >= 199103) setlogin(pw->pw_name); @@ -469,7 +469,7 @@ run_job(atjob *job, char *atfile) if (setuid(pw->pw_uid)) { fprintf(stderr, "unable to set uid to %lu\n", (unsigned long)pw->pw_uid); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #endif /* LOGIN_CAP */ @@ -485,7 +485,7 @@ run_job(atjob *job, char *atfile) fprintf(stderr, "debug DTEST is on, not exec'ing at job %s\n", atfile); - _exit(OK_EXIT); + _exit(EXIT_SUCCESS); } #endif /*DEBUGGING*/ @@ -501,7 +501,7 @@ run_job(atjob *job, char *atfile) nenvp[0] = NULL; if (execve(_PATH_BSHELL, nargv, nenvp) != 0) { perror("execve: " _PATH_BSHELL); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } break; default: @@ -522,7 +522,7 @@ run_job(atjob *job, char *atfile) if ((fp = fdopen(output_pipe[READ_PIPE], "r")) == NULL) { perror("fdopen"); - (void) _exit(ERROR_EXIT); + (void) _exit(EXIT_FAILURE); } nread = fread(buf, 1, sizeof(buf), fp); if (nread != 0 || always_mail) { @@ -540,11 +540,11 @@ run_job(atjob *job, char *atfile) if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG) >= sizeof mailcmd) { fprintf(stderr, "mailcmd too long\n"); - (void) _exit(ERROR_EXIT); + (void) _exit(EXIT_FAILURE); } if (!(mail = cron_popen(mailcmd, "w", pw))) { perror(mailcmd); - (void) _exit(ERROR_EXIT); + (void) _exit(EXIT_FAILURE); } fprintf(mail, "From: %s (Atrun Service)\n", pw->pw_name); fprintf(mail, "To: %s\n", mailto); @@ -600,9 +600,9 @@ run_job(atjob *job, char *atfile) break; } } - _exit(OK_EXIT); + _exit(EXIT_SUCCESS); bad_file: log_it(pw->pw_name, getpid(), "BAD FILE FORMAT", atfile); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c index 63aff8c111e..ea942c7932f 100644 --- a/usr.sbin/cron/cron.c +++ b/usr.sbin/cron/cron.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cron.c,v 1.42 2011/01/18 14:09:54 millert Exp $ */ +/* $OpenBSD: cron.c,v 1.43 2011/08/22 19:32:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -59,7 +59,7 @@ usage(void) { fprintf(stderr, "debugging flags (none supported in this build)]"); #endif fprintf(stderr, "]\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } int @@ -101,7 +101,7 @@ main(int argc, char *argv[]) { if (putenv("PATH="_PATH_DEFPATH) < 0) { log_it("CRON", getpid(), "DEATH", "can't malloc"); - exit(1); + exit(EXIT_FAILURE); } /* if there are no debug flags turned on, fork as a daemon should. @@ -114,23 +114,23 @@ main(int argc, char *argv[]) { switch (fork()) { case -1: log_it("CRON",getpid(),"DEATH","can't fork"); - exit(0); + exit(EXIT_FAILURE); break; case 0: /* child process */ (void) setsid(); if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) >= 0) { - (void) dup2(fd, STDIN); - (void) dup2(fd, STDOUT); - (void) dup2(fd, STDERR); - if (fd != STDERR) + (void) dup2(fd, STDIN_FILENO); + (void) dup2(fd, STDOUT_FILENO); + (void) dup2(fd, STDERR_FILENO); + if (fd != STDERR_FILENO) (void) close(fd); } log_it("CRON",getpid(),"STARTUP",CRON_VERSION); break; default: /* parent process should just die */ - _exit(0); + _exit(EXIT_SUCCESS); } } diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index ed53b581e27..d0993d3e1a2 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.63 2011/08/19 20:53:36 millert Exp $ */ +/* $OpenBSD: crontab.c,v 1.64 2011/08/22 19:32:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -70,7 +70,7 @@ usage(const char *msg) { "\t-e\t(edit user's crontab)\n" "\t-l\t(list user's crontab)\n" "\t-r\t(delete user's crontab)\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } int @@ -93,9 +93,9 @@ main(int argc, char *argv[]) { User, ProgramName); fprintf(stderr, "See crontab(1) for more information\n"); log_it(RealUser, Pid, "AUTH", "crontab command not allowed"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } - exitstatus = OK_EXIT; + exitstatus = EXIT_SUCCESS; switch (Option) { case opt_list: list_cmd(); @@ -108,10 +108,10 @@ main(int argc, char *argv[]) { break; case opt_replace: if (replace_cmd() < 0) - exitstatus = ERROR_EXIT; + exitstatus = EXIT_FAILURE; break; default: - exitstatus = ERROR_EXIT; + exitstatus = EXIT_FAILURE; break; } exit(exitstatus); @@ -126,11 +126,11 @@ parse_args(int argc, char *argv[]) { fprintf(stderr, "%s: your UID isn't in the passwd file.\n", ProgramName); fprintf(stderr, "bailing out.\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (strlen(pw->pw_name) >= sizeof User) { fprintf(stderr, "username too long\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } strlcpy(User, pw->pw_name, sizeof(User)); strlcpy(RealUser, User, sizeof(RealUser)); @@ -148,12 +148,12 @@ parse_args(int argc, char *argv[]) { if (MY_UID(pw) != ROOT_UID) { fprintf(stderr, "must be privileged to use -u\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (!(pw = getpwnam(optarg))) { fprintf(stderr, "%s: user `%s' unknown\n", ProgramName, optarg); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (strlcpy(User, optarg, sizeof User) >= sizeof User) usage("username too long"); @@ -211,15 +211,15 @@ parse_args(int argc, char *argv[]) { if (swap_gids() < OK) { perror("swapping gids"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (!(NewCrontab = fopen(Filename, "r"))) { perror(Filename); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (swap_gids_back() < OK) { perror("swapping gids back"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } } } @@ -236,14 +236,14 @@ list_cmd(void) { log_it(RealUser, Pid, "LIST", User); if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (!(f = fopen(n, "r"))) { if (errno == ENOENT) fprintf(stderr, "no crontab for %s\n", User); else perror(n); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } /* file is open. copy to stdout, close. @@ -261,14 +261,14 @@ delete_cmd(void) { log_it(RealUser, Pid, "DELETE", User); if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (unlink(n) != 0) { if (errno == ENOENT) fprintf(stderr, "no crontab for %s\n", User); else perror(n); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } poke_daemon(SPOOL_DIR, RELOAD_CRON); } @@ -291,18 +291,18 @@ edit_cmd(void) { log_it(RealUser, Pid, "BEGIN EDIT", User); if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (!(f = fopen(n, "r"))) { if (errno != ENOENT) { perror(n); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } fprintf(stderr, "no crontab for %s - using an empty one\n", User); if (!(f = fopen(_PATH_DEVNULL, "r"))) { perror(_PATH_DEVNULL); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } } @@ -330,12 +330,12 @@ edit_cmd(void) { } if (swap_gids() < OK) { perror("swapping gids"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } t = mkstemp(Filename); if (swap_gids_back() < OK) { perror("swapping gids back"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (t == -1) { perror(Filename); @@ -352,7 +352,7 @@ edit_cmd(void) { fclose(f); if (fflush(NewCrontab) < OK) { perror(Filename); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } (void)futimens(t, ts); again: @@ -363,14 +363,14 @@ edit_cmd(void) { fatal: if (swap_gids() < OK) { perror("swapping gids"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } unlink(Filename); if (swap_gids_back() < OK) { perror("swapping gids back"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } /* we still have the file open. editors will generally rewrite the @@ -392,7 +392,7 @@ edit_cmd(void) { if (timespeccmp(&ts[1], &statbuf.st_mtim, ==)) { if (swap_gids() < OK) { perror("swapping gids"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (lstat(Filename, &xstatbuf) == 0 && statbuf.st_ino != xstatbuf.st_ino) { @@ -401,7 +401,7 @@ edit_cmd(void) { } if (swap_gids_back() < OK) { perror("swapping gids back"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } fprintf(stderr, "%s: no changes made to crontab\n", ProgramName); @@ -445,12 +445,12 @@ edit_cmd(void) { remove: if (swap_gids() < OK) { perror("swapping gids"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } unlink(Filename); if (swap_gids_back() < OK) { perror("swapping gids back"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } done: log_it(RealUser, Pid, "END EDIT", User); @@ -663,7 +663,7 @@ static void die(int x) { if (TempFilename[0]) (void) unlink(TempFilename); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } static void diff --git a/usr.sbin/cron/do_command.c b/usr.sbin/cron/do_command.c index b272e5ccc6b..299e6f44c57 100644 --- a/usr.sbin/cron/do_command.c +++ b/usr.sbin/cron/do_command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: do_command.c,v 1.35 2011/03/03 15:08:14 millert Exp $ */ +/* $OpenBSD: do_command.c,v 1.36 2011/08/22 19:32:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -48,7 +48,7 @@ do_command(entry *e, user *u) { child_process(e, u); Debug(DPROC, ("[%ld] child process done, exiting\n", (long)getpid())) - _exit(OK_EXIT); + _exit(EXIT_SUCCESS); break; default: /* parent process */ @@ -127,7 +127,7 @@ child_process(entry *e, user *u) { switch (fork()) { case -1: log_it("CRON", getpid(), "error", "can't fork"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); /*NOTREACHED*/ case 0: Debug(DPROC, ("[%ld] grandchild process fork()'ed\n", @@ -165,15 +165,15 @@ child_process(entry *e, user *u) { /* grandchild process. make std{in,out} be the ends of * pipes opened by our daddy; make stderr go to stdout. */ - if (stdin_pipe[READ_PIPE] != STDIN) { - dup2(stdin_pipe[READ_PIPE], STDIN); + if (stdin_pipe[READ_PIPE] != STDIN_FILENO) { + dup2(stdin_pipe[READ_PIPE], STDIN_FILENO); close(stdin_pipe[READ_PIPE]); } - if (stdout_pipe[WRITE_PIPE] != STDOUT) { - dup2(stdout_pipe[WRITE_PIPE], STDOUT); + if (stdout_pipe[WRITE_PIPE] != STDOUT_FILENO) { + dup2(stdout_pipe[WRITE_PIPE], STDOUT_FILENO); close(stdout_pipe[WRITE_PIPE]); } - dup2(STDOUT, STDERR); + dup2(STDOUT_FILENO, STDERR_FILENO); /* set our directory, uid and gid. Set gid first, since once * we set uid, we've lost root privileges. @@ -192,24 +192,24 @@ child_process(entry *e, user *u) { fprintf(stderr, "unable to get login class for %s\n", e->pwd->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (setusercontext(lc, e->pwd, e->pwd->pw_uid, LOGIN_SETALL) < 0) { fprintf(stderr, "setusercontext failed for %s\n", e->pwd->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #ifdef BSD_AUTH as = auth_open(); if (as == NULL || auth_setpwd(as, e->pwd) != 0) { fprintf(stderr, "can't malloc\n"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } if (auth_approval(as, lc, usernm, "cron") <= 0) { fprintf(stderr, "approval failed for %s\n", e->pwd->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } auth_close(as); #endif /* BSD_AUTH */ @@ -232,7 +232,7 @@ child_process(entry *e, user *u) { if (setgid(e->pwd->pw_gid) || initgroups(usernm, e->pwd->pw_gid)) { fprintf(stderr, "unable to set groups for %s\n", e->pwd->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #if (defined(BSD)) && (BSD >= 199103) setlogin(usernm); @@ -241,7 +241,7 @@ child_process(entry *e, user *u) { fprintf(stderr, "unable to set uid to %lu\n", (unsigned long)e->pwd->pw_uid); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #endif /* LOGIN_CAP */ @@ -261,13 +261,13 @@ child_process(entry *e, user *u) { "debug DTEST is on, not exec'ing command.\n"); fprintf(stderr, "\tcmd='%s' shell='%s'\n", e->cmd, shell); - _exit(OK_EXIT); + _exit(EXIT_SUCCESS); } # endif /*DEBUGGING*/ execle(shell, shell, "-c", e->cmd, (char *)NULL, e->envp); fprintf(stderr, "execle: couldn't exec `%s'\n", shell); perror("execle"); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } break; default: @@ -345,7 +345,7 @@ child_process(entry *e, user *u) { Debug(DPROC, ("[%ld] child2 done sending to grandchild\n", (long)getpid())) - _exit(OK_EXIT); + _exit(EXIT_SUCCESS); } /* close the pipe to the grandkiddie's stdin, since its wicked uncle @@ -406,11 +406,11 @@ child_process(entry *e, user *u) { if (snprintf(mailcmd, sizeof mailcmd, MAILFMT, MAILARG) >= sizeof mailcmd) { fprintf(stderr, "mailcmd too long\n"); - (void) _exit(ERROR_EXIT); + (void) _exit(EXIT_FAILURE); } if (!(mail = cron_popen(mailcmd, "w", e->pwd))) { perror(mailcmd); - (void) _exit(ERROR_EXIT); + (void) _exit(EXIT_FAILURE); } fprintf(mail, "From: root (Cron Daemon)\n"); fprintf(mail, "To: %s\n", mailto); diff --git a/usr.sbin/cron/macros.h b/usr.sbin/cron/macros.h index ba05c8ffc5f..e26123527b7 100644 --- a/usr.sbin/cron/macros.h +++ b/usr.sbin/cron/macros.h @@ -1,4 +1,4 @@ -/* $OpenBSD: macros.h,v 1.6 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: macros.h,v 1.7 2011/08/22 19:32:42 millert Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -37,11 +37,6 @@ #define INIT_PID 1 /* parent of orphans */ #define READ_PIPE 0 /* which end of a pipe pair do you read? */ #define WRITE_PIPE 1 /* or write to? */ -#define STDIN 0 /* what is stdin's file descriptor? */ -#define STDOUT 1 /* stdout's? */ -#define STDERR 2 /* stderr's? */ -#define ERROR_EXIT 1 /* exit() with this will scare the shell */ -#define OK_EXIT 0 /* exit() with this is considered 'normal' */ #define MAX_FNAME 100 /* max length of internally generated fn */ #define MAX_COMMAND 1000 /* max length of internally generated cmd */ #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */ diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index af5792382c4..a5e9b420f21 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.43 2011/07/09 14:49:14 dhill Exp $ */ +/* $OpenBSD: misc.c,v 1.44 2011/08/22 19:32:42 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -128,12 +128,12 @@ set_cron_uid(void) { #if defined(BSD) || defined(POSIX) if (seteuid(ROOT_UID) < OK) { perror("seteuid"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } #else if (setuid(ROOT_UID) < OK) { perror("setuid"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } #endif } @@ -156,18 +156,18 @@ set_cron_cwd(void) { } else { fprintf(stderr, "%s: ", CRONDIR); perror("mkdir"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } } if (!S_ISDIR(sb.st_mode)) { fprintf(stderr, "'%s' is not a directory, bailing out.\n", CRONDIR); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (chdir(CRONDIR) < OK) { fprintf(stderr, "cannot chdir(%s), bailing out.\n", CRONDIR); perror(CRONDIR); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } /* CRONDIR okay (now==CWD), now look at SPOOL_DIR ("tabs" or some such) @@ -180,13 +180,13 @@ set_cron_cwd(void) { } else { fprintf(stderr, "%s: ", SPOOL_DIR); perror("mkdir"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } } if (!S_ISDIR(sb.st_mode)) { fprintf(stderr, "'%s' is not a directory, bailing out.\n", SPOOL_DIR); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (grp != NULL) { if (sb.st_gid != grp->gr_gid) @@ -205,13 +205,13 @@ set_cron_cwd(void) { } else { fprintf(stderr, "%s: ", AT_DIR); perror("mkdir"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } } if (!S_ISDIR(sb.st_mode)) { fprintf(stderr, "'%s' is not a directory, bailing out.\n", AT_DIR); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (grp != NULL) { if (sb.st_gid != grp->gr_gid) @@ -221,7 +221,7 @@ set_cron_cwd(void) { } } -/* acquire_daemonlock() - write our PID into /etc/cron.pid, unless +/* acquire_daemonlock() - write our PID into /var/run/cron.pid, unless * another daemon is already running, which we detect here. * * note: main() calls us twice; once before forking, once after. @@ -258,7 +258,7 @@ acquire_daemonlock(int closeflag) { strerror(save_errno)); fprintf(stderr, "%s: %s\n", ProgramName, buf); log_it("CRON", getpid(), "DEATH", buf); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } /* couldn't lock the pid file, try to read existing. */ @@ -277,19 +277,19 @@ acquire_daemonlock(int closeflag) { } fprintf(stderr, "%s: %s\n", ProgramName, buf); log_it("CRON", getpid(), "DEATH", buf); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } - /* fd must be > STDERR since we dup fd 0-2 to /dev/null */ - if (fd <= STDERR) { - if (dup2(fd, STDERR + 1) < 0) { + /* fd must be > STDERR_FILENO since we dup fd 0-2 to /dev/null */ + if (fd <= STDERR_FILENO) { + if (dup2(fd, STDERR_FILENO + 1) < 0) { snprintf(buf, sizeof buf, "can't dup pid fd: %s", strerror(errno)); fprintf(stderr, "%s: %s\n", ProgramName, buf); log_it("CRON", getpid(), "DEATH", buf); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } close(fd); - fd = STDERR + 1; + fd = STDERR_FILENO + 1; } (void) fcntl(fd, F_SETFD, FD_CLOEXEC); } @@ -483,7 +483,7 @@ log_it(const char *username, PID_T xpid, const char *event, const char *detail) if (LogFD >= OK) perror(LOG_FILE); fprintf(stderr, "%s: can't write to log file\n", ProgramName); - write(STDERR, msg, strlen(msg)); + write(STDERR_FILENO, msg, strlen(msg)); } free(msg); @@ -706,28 +706,28 @@ open_socket(void) fprintf(stderr, "%s: can't create socket: %s\n", ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't create socket"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { fprintf(stderr, "%s: can't make socket close on exec: %s\n", ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't make socket close on exec"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) { fprintf(stderr, "%s: can't make socket non-blocking: %s\n", ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't make socket non-blocking"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } bzero(&s_un, sizeof(s_un)); if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { fprintf(stderr, "%s/%s: path too long\n", SPOOL_DIR, CRONSOCK); log_it("CRON", getpid(), "DEATH", "path too long"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } unlink(s_un.sun_path); s_un.sun_family = AF_UNIX; @@ -741,14 +741,14 @@ open_socket(void) ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't bind socket"); umask(omask); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } umask(omask); if (listen(sock, SOMAXCONN)) { fprintf(stderr, "%s: can't listen on socket: %s\n", ProgramName, strerror(errno)); log_it("CRON", getpid(), "DEATH", "can't listen on socket"); - exit(ERROR_EXIT); + exit(EXIT_FAILURE); } chmod(s_un.sun_path, 0660); diff --git a/usr.sbin/cron/popen.c b/usr.sbin/cron/popen.c index 5cef5ddd791..613d1e8a094 100644 --- a/usr.sbin/cron/popen.c +++ b/usr.sbin/cron/popen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popen.c,v 1.21 2009/10/27 23:59:51 deraadt Exp $ */ +/* $OpenBSD: popen.c,v 1.22 2011/08/22 19:32:42 millert Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -89,7 +89,7 @@ cron_popen(char *program, char *type, struct passwd *pw) { fprintf(stderr, "setusercontext failed for %s\n", pw->pw_name); - _exit(ERROR_EXIT); + _exit(EXIT_FAILURE); } #else if (setgid(pw->pw_gid) < 0 || @@ -111,15 +111,15 @@ cron_popen(char *program, char *type, struct passwd *pw) { #endif /* LOGIN_CAP */ } if (*type == 'r') { - if (pdes[1] != STDOUT) { - dup2(pdes[1], STDOUT); + if (pdes[1] != STDOUT_FILENO) { + dup2(pdes[1], STDOUT_FILENO); (void)close(pdes[1]); } - dup2(STDOUT, STDERR); /* stderr too! */ + dup2(STDOUT_FILENO, STDERR_FILENO); (void)close(pdes[0]); } else { - if (pdes[0] != STDIN) { - dup2(pdes[0], STDIN); + if (pdes[0] != STDIN_FILENO) { + dup2(pdes[0], STDIN_FILENO); (void)close(pdes[0]); } (void)close(pdes[1]); |