summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/lib
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-09-15 06:39:25 +0000
committercharnier <charnier@FreeBSD.org>1997-09-15 06:39:25 +0000
commitbdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001 (patch)
tree62741259da03c9d124c89e3590b84512939c0733 /usr.sbin/cron/lib
parentb8c46235c5b5fcd433f224674a9be99e69acc8ee (diff)
downloadFreeBSD-src-bdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001.zip
FreeBSD-src-bdee4a3e4bcaeb996f0a5f6081f49d2b42cd0001.tar.gz
Use err(3). Rewrote man page in mdoc format.
Diffstat (limited to 'usr.sbin/cron/lib')
-rw-r--r--usr.sbin/cron/lib/entry.c3
-rw-r--r--usr.sbin/cron/lib/env.c5
-rw-r--r--usr.sbin/cron/lib/misc.c67
3 files changed, 29 insertions, 46 deletions
diff --git a/usr.sbin/cron/lib/entry.c b/usr.sbin/cron/lib/entry.c
index 9aa1ef3..39ff0df 100644
--- a/usr.sbin/cron/lib/entry.c
+++ b/usr.sbin/cron/lib/entry.c
@@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id$";
+static const char rcsid[] =
+ "$Id: entry.c,v 1.6 1997/02/22 16:05:06 peter Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
diff --git a/usr.sbin/cron/lib/env.c b/usr.sbin/cron/lib/env.c
index 5859b63..d66e1a3 100644
--- a/usr.sbin/cron/lib/env.c
+++ b/usr.sbin/cron/lib/env.c
@@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id$";
+static const char rcsid[] =
+ "$Id: env.c,v 1.5 1997/02/22 16:05:07 peter Exp $";
#endif
@@ -192,7 +193,7 @@ env_get(name, envp)
register int len = strlen(name);
register char *p, *q;
- while (p = *envp++) {
+ while ((p = *envp++)) {
if (!(q = strchr(p, '=')))
continue;
if ((q - p) == len && !strncmp(p, name, len))
diff --git a/usr.sbin/cron/lib/misc.c b/usr.sbin/cron/lib/misc.c
index 9892ab3..6c098de 100644
--- a/usr.sbin/cron/lib/misc.c
+++ b/usr.sbin/cron/lib/misc.c
@@ -16,7 +16,8 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id$";
+static const char rcsid[] =
+ "$Id: misc.c,v 1.5 1997/02/22 16:05:08 peter Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@@ -32,6 +33,7 @@ static char rcsid[] = "$Id$";
#endif
#include <sys/file.h>
#include <sys/stat.h>
+#include <err.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
@@ -174,15 +176,11 @@ void
set_cron_uid()
{
#if defined(BSD) || defined(POSIX)
- if (seteuid(ROOT_UID) < OK) {
- perror("seteuid");
- exit(ERROR_EXIT);
- }
+ if (seteuid(ROOT_UID) < OK)
+ err(ERROR_EXIT, "seteuid");
#else
- if (setuid(ROOT_UID) < OK) {
- perror("setuid");
- exit(ERROR_EXIT);
- }
+ if (setuid(ROOT_UID) < OK)
+ err(ERROR_EXIT, "setuid");
#endif
}
@@ -195,45 +193,32 @@ set_cron_cwd()
/* first check for CRONDIR ("/var/cron" or some such)
*/
if (stat(CRONDIR, &sb) < OK && errno == ENOENT) {
- perror(CRONDIR);
+ warn("%s", CRONDIR);
if (OK == mkdir(CRONDIR, 0700)) {
- fprintf(stderr, "%s: created\n", CRONDIR);
+ warnx("%s: created", CRONDIR);
stat(CRONDIR, &sb);
} else {
- fprintf(stderr, "%s: ", CRONDIR);
- perror("mkdir");
- exit(ERROR_EXIT);
+ err(ERROR_EXIT, "%s: mkdir", CRONDIR);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
- fprintf(stderr, "'%s' is not a directory, bailing out.\n",
- CRONDIR);
- exit(ERROR_EXIT);
- }
- if (chdir(CRONDIR) < OK) {
- fprintf(stderr, "cannot chdir(%s), bailing out.\n", CRONDIR);
- perror(CRONDIR);
- exit(ERROR_EXIT);
- }
+ if (!(sb.st_mode & S_IFDIR))
+ err(ERROR_EXIT, "'%s' is not a directory, bailing out", CRONDIR);
+ if (chdir(CRONDIR) < OK)
+ err(ERROR_EXIT, "cannot chdir(%s), bailing out", CRONDIR);
/* CRONDIR okay (now==CWD), now look at SPOOL_DIR ("tabs" or some such)
*/
if (stat(SPOOL_DIR, &sb) < OK && errno == ENOENT) {
- perror(SPOOL_DIR);
+ warn("%s", SPOOL_DIR);
if (OK == mkdir(SPOOL_DIR, 0700)) {
- fprintf(stderr, "%s: created\n", SPOOL_DIR);
+ warnx("%s: created", SPOOL_DIR);
stat(SPOOL_DIR, &sb);
} else {
- fprintf(stderr, "%s: ", SPOOL_DIR);
- perror("mkdir");
- exit(ERROR_EXIT);
+ err(ERROR_EXIT, "%s: mkdir", SPOOL_DIR);
}
}
- if (!(sb.st_mode & S_IFDIR)) {
- fprintf(stderr, "'%s' is not a directory, bailing out.\n",
- SPOOL_DIR);
- exit(ERROR_EXIT);
- }
+ if (!(sb.st_mode & S_IFDIR))
+ err(ERROR_EXIT, "'%s' is not a directory, bailing out", SPOOL_DIR);
}
@@ -269,9 +254,8 @@ acquire_daemonlock(closeflag)
) {
sprintf(buf, "can't open or create %s: %s",
pidfile, strerror(errno));
- fprintf(stderr, "%s: %s\n", ProgramName, buf);
log_it("CRON", getpid(), "DEATH", buf);
- exit(ERROR_EXIT);
+ errx(ERROR_EXIT, "%s", buf);
}
if (flock(fd, LOCK_EX|LOCK_NB) < OK) {
@@ -280,9 +264,8 @@ acquire_daemonlock(closeflag)
fscanf(fp, "%d", &otherpid);
sprintf(buf, "can't lock %s, otherpid may be %d: %s",
pidfile, otherpid, strerror(save_errno));
- fprintf(stderr, "%s: %s\n", ProgramName, buf);
log_it("CRON", getpid(), "DEATH", buf);
- exit(ERROR_EXIT);
+ errx(ERROR_EXIT, "%s", buf);
}
(void) fcntl(fd, F_SETFD, 1);
@@ -483,9 +466,7 @@ log_it(username, xpid, event, detail)
if (LogFD < OK) {
LogFD = open(LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0600);
if (LogFD < OK) {
- fprintf(stderr, "%s: can't open log file\n",
- ProgramName);
- perror(LOG_FILE);
+ warn("can't open log file %s", LOG_FILE);
} else {
(void) fcntl(LogFD, F_SETFD, 1);
}
@@ -504,8 +485,8 @@ log_it(username, xpid, event, detail)
*/
if (LogFD < OK || write(LogFD, msg, strlen(msg)) < OK) {
if (LogFD >= OK)
- perror(LOG_FILE);
- fprintf(stderr, "%s: can't write to log file\n", ProgramName);
+ warn("%s", LOG_FILE);
+ warnx("can't write to log file");
write(STDERR, msg, strlen(msg));
}
OpenPOWER on IntegriCloud