summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2015-11-14 13:09:14 +0000
committermillert <millert@openbsd.org>2015-11-14 13:09:14 +0000
commita38a3395d370b654188c2cb2aad0985179e49867 (patch)
treea11d36cb397691b0418d93cf462acb66006e2475 /usr.sbin/cron
parentThe character is an int so use %x not %hhx. (diff)
downloadwireguard-openbsd-a38a3395d370b654188c2cb2aad0985179e49867.tar.xz
wireguard-openbsd-a38a3395d370b654188c2cb2aad0985179e49867.zip
Remove log_it() and call syslog(3) directly using the same format:
"(username) WHAT (details)". Logs due to normal operation (e.g. crontab operations or running commands) are logged at LOG_INFO like before. Actual errors are logged at LOG_ERR, less important things are logged at LOG_WARNING OR LOG_NOTICE. Also ignore SIGHUP now that there is no log file to reopen.
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/atrun.c60
-rw-r--r--usr.sbin/cron/cron.c41
-rw-r--r--usr.sbin/cron/crontab.c23
-rw-r--r--usr.sbin/cron/database.c24
-rw-r--r--usr.sbin/cron/do_command.c25
-rw-r--r--usr.sbin/cron/entry.c11
-rw-r--r--usr.sbin/cron/funcs.h4
-rw-r--r--usr.sbin/cron/misc.c31
8 files changed, 94 insertions, 125 deletions
diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c
index 7e6846b15be..1ab65985151 100644
--- a/usr.sbin/cron/atrun.c
+++ b/usr.sbin/cron/atrun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atrun.c,v 1.39 2015/11/12 21:12:05 millert Exp $ */
+/* $OpenBSD: atrun.c,v 1.40 2015/11/14 13:09:14 millert Exp $ */
/*
* Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h>
#include <unistd.h>
@@ -81,11 +82,11 @@ scan_atjobs(at_db **db, struct timespec *ts)
struct stat sb;
if ((dfd = open(_PATH_AT_SPOOL, O_RDONLY|O_DIRECTORY)) == -1) {
- log_it("CRON", "OPEN FAILED", _PATH_AT_SPOOL);
+ syslog(LOG_ERR, "(CRON) OPEN FAILED (%s)", _PATH_AT_SPOOL);
return (0);
}
if (fstat(dfd, &sb) != 0) {
- log_it("CRON", "FSTAT FAILED", _PATH_AT_SPOOL);
+ syslog(LOG_ERR, "(CRON) FSTAT FAILED (%s)", _PATH_AT_SPOOL);
close(dfd);
return (0);
}
@@ -95,7 +96,7 @@ scan_atjobs(at_db **db, struct timespec *ts)
}
if ((atdir = fdopendir(dfd)) == NULL) {
- log_it("CRON", "OPENDIR FAILED", _PATH_AT_SPOOL);
+ syslog(LOG_ERR, "(CRON) OPENDIR FAILED (%s)", _PATH_AT_SPOOL);
close(dfd);
return (0);
}
@@ -237,7 +238,7 @@ run_job(atjob *job, char *atfile)
/* Open the file and unlink it so we don't try running it again. */
if ((fd = open(atfile, O_RDONLY|O_NONBLOCK|O_NOFOLLOW, 0)) < 0) {
- log_it("CRON", "CAN'T OPEN", atfile);
+ syslog(LOG_ERR, "(CRON) CAN'T OPEN (%s)", atfile);
return;
}
unlink(atfile);
@@ -253,7 +254,7 @@ run_job(atjob *job, char *atfile)
break;
case -1:
/* error */
- log_it("CRON", "error", "can't fork");
+ syslog(LOG_ERR, "(CRON) CAN'T FORK (%m)");
/* FALLTHROUGH */
default:
/* parent */
@@ -272,39 +273,43 @@ run_job(atjob *job, char *atfile)
*/
pw = getpwuid(job->uid);
if (pw == NULL) {
- log_it("CRON", "ORPHANED JOB", atfile);
+ syslog(LOG_WARNING, "(CRON) ORPHANED JOB (%s)", atfile);
_exit(EXIT_FAILURE);
}
if (pw->pw_expire && time(NULL) >= pw->pw_expire) {
- log_it(pw->pw_name, "ACCOUNT EXPIRED, JOB ABORTED",
- atfile);
+ syslog(LOG_NOTICE, "(%s) ACCOUNT EXPIRED, JOB ABORTED (%s)",
+ pw->pw_name, atfile);
_exit(EXIT_FAILURE);
}
/* Sanity checks */
if (fstat(fd, &sb) < 0) {
- log_it(pw->pw_name, "FSTAT FAILED", atfile);
+ syslog(LOG_ERR, "(%s) FSTAT FAILED (%s)", pw->pw_name, atfile);
_exit(EXIT_FAILURE);
}
if (!S_ISREG(sb.st_mode)) {
- log_it(pw->pw_name, "NOT REGULAR", atfile);
+ syslog(LOG_WARNING, "(%s) NOT REGULAR (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
if ((sb.st_mode & ALLPERMS) != (S_IRUSR | S_IWUSR | S_IXUSR)) {
- log_it(pw->pw_name, "BAD FILE MODE", atfile);
+ syslog(LOG_WARNING, "(%s) BAD FILE MODE (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
if (sb.st_uid != 0 && sb.st_uid != job->uid) {
- log_it(pw->pw_name, "WRONG FILE OWNER", atfile);
+ syslog(LOG_WARNING, "(%s) WRONG FILE OWNER (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
if (sb.st_nlink > 1) {
- log_it(pw->pw_name, "BAD LINK COUNT", atfile);
+ syslog(LOG_WARNING, "(%s) BAD LINK COUNT (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
if ((fp = fdopen(dup(fd), "r")) == NULL) {
- log_it("CRON", "error", "dup(2) failed");
+ syslog(LOG_ERR, "(CRON) DUP FAILED (%m)");
_exit(EXIT_FAILURE);
}
@@ -358,11 +363,13 @@ run_job(atjob *job, char *atfile)
if (!safe_p(pw->pw_name, mailto))
_exit(EXIT_FAILURE);
if ((uid_t)nuid != job->uid) {
- log_it(pw->pw_name, "UID MISMATCH", atfile);
+ syslog(LOG_WARNING, "(%s) UID MISMATCH (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
if ((gid_t)ngid != job->gid) {
- log_it(pw->pw_name, "GID MISMATCH", atfile);
+ syslog(LOG_WARNING, "(%s) GID MISMATCH (%s)", pw->pw_name,
+ atfile);
_exit(EXIT_FAILURE);
}
@@ -374,15 +381,15 @@ run_job(atjob *job, char *atfile)
/* Fork again, child will run the job, parent will catch output. */
switch ((pid = fork())) {
case -1:
- log_it("CRON", "error", "can't fork");
+ syslog(LOG_ERR, "(CRON) CAN'T FORK (%m)");
_exit(EXIT_FAILURE);
/*NOTREACHED*/
case 0:
/* Write log message now that we have our real pid. */
- log_it(pw->pw_name, "ATJOB", atfile);
+ syslog(LOG_INFO, "(%s) ATJOB (%s)", pw->pw_name, atfile);
- /* Close log file (or syslog) */
- log_close();
+ /* Close syslog file */
+ closelog();
/* Connect grandchild's stdin to the at job file. */
if (lseek(fd, 0, SEEK_SET) < 0) {
@@ -480,7 +487,7 @@ run_job(atjob *job, char *atfile)
if (gethostname(hostname, sizeof(hostname)) != 0)
strlcpy(hostname, "unknown", sizeof(hostname));
- if (snprintf(mailcmd, sizeof mailcmd, MAILFMT,
+ if (snprintf(mailcmd, sizeof mailcmd, MAILFMT,
MAILARG) >= sizeof mailcmd) {
fprintf(stderr, "mailcmd too long\n");
(void) _exit(EXIT_FAILURE);
@@ -508,10 +515,9 @@ run_job(atjob *job, char *atfile)
* this fact so the problem can (hopefully) be debugged.
*/
if ((status = cron_pclose(mail, mailpid)) != 0) {
- snprintf(buf, sizeof(buf), "mailed %lu byte%s of output"
- " but got status 0x%04x\n", (unsigned long)bytes,
- (bytes == 1) ? "" : "s", status);
- log_it(pw->pw_name, "MAIL", buf);
+ syslog(LOG_NOTICE, "(%s) MAIL (mailed %zu byte%s of "
+ "output but got status 0x%04x)", pw->pw_name,
+ bytes, (bytes == 1) ? "" : "s", status);
}
}
@@ -534,6 +540,6 @@ run_job(atjob *job, char *atfile)
_exit(EXIT_SUCCESS);
bad_file:
- log_it(pw->pw_name, "BAD FILE FORMAT", atfile);
+ syslog(LOG_ERR, "(%s) BAD FILE FORMAT (%s)", pw->pw_name, atfile);
_exit(EXIT_FAILURE);
}
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index 50eba6a864f..a93d38e3b58 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.70 2015/11/12 21:12:05 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.71 2015/11/14 13:09:14 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h>
#include <unistd.h>
@@ -50,13 +51,12 @@ static void usage(void),
set_time(int),
cron_sleep(time_t, sigset_t *),
sigchld_handler(int),
- sighup_handler(int),
sigchld_reaper(void),
parse_args(int c, char *v[]);
static int open_socket(void);
-static volatile sig_atomic_t got_sighup, got_sigchld;
+static volatile sig_atomic_t got_sigchld;
static time_t timeRunning, virtualTime, clockTime;
static int cronSock;
static long GMToff;
@@ -93,30 +93,31 @@ main(int argc, char *argv[])
sact.sa_flags |= SA_RESTART;
sact.sa_handler = sigchld_handler;
(void) sigaction(SIGCHLD, &sact, NULL);
- sact.sa_handler = sighup_handler;
- (void) sigaction(SIGHUP, &sact, NULL);
sact.sa_handler = SIG_IGN;
+ (void) sigaction(SIGHUP, &sact, NULL);
(void) sigaction(SIGPIPE, &sact, NULL);
+ openlog(__progname, LOG_PID, LOG_CRON);
+
if (pledge("stdio rpath wpath cpath fattr getpw unix id dns proc exec",
NULL) == -1) {
- log_it("CRON", "pledge", strerror(errno));
+ syslog(LOG_ERR, "(CRON) PLEDGE (%m)");
exit(EXIT_FAILURE);
}
cronSock = open_socket();
if (putenv("PATH="_PATH_DEFPATH) < 0) {
- log_it("CRON", "DEATH", "can't malloc");
+ syslog(LOG_ERR, "(CRON) DEATH (%m)");
exit(EXIT_FAILURE);
}
if (NoFork == 0) {
if (daemon(0, 0) == -1) {
- log_it("CRON", "DEATH", "can't fork");
+ syslog(LOG_ERR, "(CRON) DEATH (%m)");
exit(EXIT_FAILURE);
}
- log_it("CRON", "STARTUP", CRON_VERSION);
+ syslog(LOG_INFO, "(CRON) STARTUP (%s)", CRON_VERSION);
}
load_database(&database);
@@ -388,10 +389,6 @@ cron_sleep(time_t target, sigset_t *mask)
}
} else {
/* Interrupted by a signal. */
- if (got_sighup) {
- got_sighup = 0;
- log_close();
- }
if (got_sigchld) {
got_sigchld = 0;
sigchld_reaper();
@@ -424,27 +421,27 @@ open_socket(void)
struct sockaddr_un s_un;
if ((grp = getgrnam(CRON_GROUP)) == NULL)
- log_it("CRON", "STARTUP", "can't find cron group");
+ syslog(LOG_WARNING, "(CRON) STARTUP (can't find cron group)");
sock = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (sock == -1) {
fprintf(stderr, "%s: can't create socket: %s\n",
__progname, strerror(errno));
- log_it("CRON", "DEATH", "can't create socket");
+ syslog(LOG_ERR, "(CRON) DEATH (can't create socket)");
exit(EXIT_FAILURE);
}
bzero(&s_un, sizeof(s_un));
if (strlcpy(s_un.sun_path, _PATH_CRON_SOCK, sizeof(s_un.sun_path))
>= sizeof(s_un.sun_path)) {
fprintf(stderr, "%s: path too long\n", _PATH_CRON_SOCK);
- log_it("CRON", "DEATH", "path too long");
+ syslog(LOG_ERR, "(CRON) DEATH (socket path too long)");
exit(EXIT_FAILURE);
}
s_un.sun_family = AF_UNIX;
if (connect(sock, (struct sockaddr *)&s_un, sizeof(s_un)) == 0) {
fprintf(stderr, "%s: already running\n", __progname);
- log_it("CRON", "DEATH", "already running");
+ syslog(LOG_ERR, "(CRON) DEATH (already running)");
exit(EXIT_FAILURE);
}
if (errno != ENOENT)
@@ -456,13 +453,13 @@ open_socket(void)
if (rc != 0) {
fprintf(stderr, "%s: can't bind socket: %s\n",
__progname, strerror(errno));
- log_it("CRON", "DEATH", "can't bind socket");
+ syslog(LOG_ERR, "(CRON) DEATH (can't bind socket)");
exit(EXIT_FAILURE);
}
if (listen(sock, SOMAXCONN)) {
fprintf(stderr, "%s: can't listen on socket: %s\n",
__progname, strerror(errno));
- log_it("CRON", "DEATH", "can't listen on socket");
+ syslog(LOG_ERR, "(CRON) DEATH (can't listen on socket)");
exit(EXIT_FAILURE);
}
chmod(s_un.sun_path, 0660);
@@ -478,12 +475,6 @@ open_socket(void)
}
static void
-sighup_handler(int x)
-{
- got_sighup = 1;
-}
-
-static void
sigchld_handler(int x)
{
got_sigchld = 1;
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c
index 55a51076849..d78cce59c20 100644
--- a/usr.sbin/cron/crontab.c
+++ b/usr.sbin/cron/crontab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crontab.c,v 1.89 2015/11/12 21:12:05 millert Exp $ */
+/* $OpenBSD: crontab.c,v 1.90 2015/11/14 13:09:14 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h>
#include <unistd.h>
@@ -82,22 +83,24 @@ main(int argc, char *argv[])
{
int exitstatus;
- user_gid = getgid();
- crontab_gid = getegid();
-
if (pledge("stdio rpath wpath cpath fattr getpw unix id proc exec",
NULL) == -1) {
err(EXIT_FAILURE, "pledge");
}
+ user_gid = getgid();
+ crontab_gid = getegid();
+
setlocale(LC_ALL, "");
+ openlog(__progname, LOG_PID, LOG_CRON);
setvbuf(stderr, NULL, _IOLBF, 0);
parse_args(argc, argv); /* sets many globals, opens a file */
if (!allowed(RealUser, _PATH_CRON_ALLOW, _PATH_CRON_DENY)) {
fprintf(stderr, "You do not have permission to use crontab\n");
fprintf(stderr, "See crontab(1) for more information\n");
- log_it(RealUser, "AUTH", "crontab command not allowed");
+ syslog(LOG_WARNING, "(%s) AUTH (crontab command not allowed)",
+ RealUser);
exit(EXIT_FAILURE);
}
exitstatus = EXIT_SUCCESS;
@@ -211,7 +214,7 @@ list_cmd(void)
char n[PATH_MAX];
FILE *f;
- log_it(RealUser, "LIST", User);
+ syslog(LOG_INFO, "(%s) LIST (%s)", RealUser, User);
if (snprintf(n, sizeof n, "%s/%s", _PATH_CRON_SPOOL, User) >= sizeof(n))
errc(EXIT_FAILURE, ENAMETOOLONG, "%s/%s", _PATH_CRON_SPOOL, User);
if (!(f = fopen(n, "r"))) {
@@ -235,7 +238,7 @@ delete_cmd(void)
{
char n[PATH_MAX];
- log_it(RealUser, "DELETE", User);
+ syslog(LOG_INFO, "(%s) DELETE (%s)", RealUser, User);
if (snprintf(n, sizeof n, "%s/%s", _PATH_CRON_SPOOL, User) >= sizeof(n))
errc(EXIT_FAILURE, ENAMETOOLONG, "%s/%s", _PATH_CRON_SPOOL, User);
if (unlink(n) != 0) {
@@ -264,7 +267,7 @@ edit_cmd(void)
struct stat statbuf, xstatbuf;
struct timespec ts[2];
- log_it(RealUser, "BEGIN EDIT", User);
+ syslog(LOG_INFO, "(%s) BEGIN EDIT (%s)", RealUser, User);
if (snprintf(n, sizeof n, "%s/%s", _PATH_CRON_SPOOL, User) >= sizeof(n))
errc(EXIT_FAILURE, ENAMETOOLONG, "%s/%s", _PATH_CRON_SPOOL, User);
if (!(f = fopen(n, "r"))) {
@@ -380,7 +383,7 @@ edit_cmd(void)
remove:
unlink(Filename);
done:
- log_it(RealUser, "END EDIT", User);
+ syslog(LOG_INFO, "(%s) END EDIT (%s)", RealUser, User);
}
/* returns 0 on success
@@ -513,7 +516,7 @@ replace_cmd(void)
goto done;
}
TempFilename[0] = '\0';
- log_it(RealUser, "REPLACE", User);
+ syslog(LOG_INFO, "(%s) REPLACE (%s)", RealUser, User);
poke_daemon(RELOAD_CRON);
diff --git a/usr.sbin/cron/database.c b/usr.sbin/cron/database.c
index adf01e6e0f1..7be6df68f9c 100644
--- a/usr.sbin/cron/database.c
+++ b/usr.sbin/cron/database.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: database.c,v 1.32 2015/11/12 21:12:05 millert Exp $ */
+/* $OpenBSD: database.c,v 1.33 2015/11/14 13:09:14 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h> /* for structs.h */
#include <unistd.h>
@@ -55,7 +56,7 @@ load_database(cron_db **db)
* cached any of the database), we'll see the changes next time.
*/
if (stat(_PATH_CRON_SPOOL, &statbuf) < 0) {
- log_it("CRON", "STAT FAILED", _PATH_CRON_SPOOL);
+ syslog(LOG_ERR, "(CRON) STAT FAILED (%s)", _PATH_CRON_SPOOL);
return;
}
@@ -92,7 +93,7 @@ load_database(cron_db **db)
* we fork a lot more often than the mtime of the dir changes.
*/
if (!(dir = opendir(_PATH_CRON_SPOOL))) {
- log_it("CRON", "OPENDIR FAILED", _PATH_CRON_SPOOL);
+ syslog(LOG_ERR, "(CRON) OPENDIR FAILED (%s)", _PATH_CRON_SPOOL);
/* Restore system crontab entry as needed. */
if (!TAILQ_EMPTY(&new_db->users) &&
(u = TAILQ_FIRST(&old_db->users))) {
@@ -168,7 +169,7 @@ process_crontab(int dfd, const char *uname, const char *fname,
if (fname[0] != '/' && (pw = getpwnam(uname)) == NULL) {
/* file doesn't have a user in passwd file.
*/
- log_it(uname, "ORPHAN", "no passwd entry");
+ syslog(LOG_WARNING, "(%s) ORPHAN (no passwd entry)", uname);
goto next_crontab;
}
@@ -176,32 +177,33 @@ process_crontab(int dfd, const char *uname, const char *fname,
if (crontab_fd < 0) {
/* crontab not accessible?
*/
- log_it(uname, "CAN'T OPEN", fname);
+ syslog(LOG_ERR, "(%s) CAN'T OPEN (%s)", uname, fname);
goto next_crontab;
}
if (fstat(crontab_fd, statbuf) < 0) {
- log_it(uname, "FSTAT FAILED", fname);
+ syslog(LOG_ERR, "(%s) FSTAT FAILED (%s)", uname, fname);
goto next_crontab;
}
if (!S_ISREG(statbuf->st_mode)) {
- log_it(uname, "NOT REGULAR", fname);
+ syslog(LOG_WARNING, "(%s) NOT REGULAR (%s)", uname, fname);
goto next_crontab;
}
if (pw != NULL) {
/* Looser permissions on system crontab. */
if ((statbuf->st_mode & 077) != 0) {
- log_it(uname, "BAD FILE MODE", fname);
+ syslog(LOG_WARNING, "(%s) BAD FILE MODE (%s)",
+ uname, fname);
goto next_crontab;
}
}
if (statbuf->st_uid != 0 && (pw == NULL ||
statbuf->st_uid != pw->pw_uid || strcmp(uname, pw->pw_name) != 0)) {
- log_it(uname, "WRONG FILE OWNER", fname);
+ syslog(LOG_WARNING, "(%s) WRONG FILE OWNER (%s)", uname, fname);
goto next_crontab;
}
if (pw != NULL && statbuf->st_nlink != 1) {
- log_it(uname, "BAD LINK COUNT", fname);
+ syslog(LOG_WARNING, "(%s) BAD LINK COUNT (%s)", uname, fname);
goto next_crontab;
}
@@ -225,7 +227,7 @@ process_crontab(int dfd, const char *uname, const char *fname,
*/
TAILQ_REMOVE(&old_db->users, u, entries);
free_user(u);
- log_it(uname, "RELOAD", fname);
+ syslog(LOG_INFO, "(%s) RELOAD (%s)", uname, fname);
}
u = load_user(crontab_fd, pw, fname);
if (u != NULL) {
diff --git a/usr.sbin/cron/do_command.c b/usr.sbin/cron/do_command.c
index d953d8c7a2a..cc7424611cf 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.53 2015/11/09 16:37:07 millert Exp $ */
+/* $OpenBSD: do_command.c,v 1.54 2015/11/14 13:09:14 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h> /* for structs.h */
#include <unistd.h>
#include <vis.h>
@@ -57,7 +58,7 @@ do_command(entry *e, user *u)
*/
switch (fork()) {
case -1:
- log_it("CRON", "error", "can't fork");
+ syslog(LOG_ERR, "(CRON) CAN'T FORK (%m)");
break;
case 0:
/* child process */
@@ -138,7 +139,7 @@ child_process(entry *e, user *u)
*/
switch (fork()) {
case -1:
- log_it("CRON", "error", "can't fork");
+ syslog(LOG_ERR, "(CRON) CAN'T FORK (%m)");
_exit(EXIT_FAILURE);
/*NOTREACHED*/
case 0:
@@ -150,14 +151,14 @@ child_process(entry *e, user *u)
if ((e->flags & DONT_LOG) == 0) {
char *x;
if (stravis(&x, e->cmd, 0) != -1) {
- log_it(usernm, "CMD", x);
+ syslog(LOG_INFO, "(%s) CMD (%s)", usernm, x);
free(x);
}
}
/* that's the last thing we'll log. close the log files.
*/
- log_close();
+ closelog();
/* get new pgrp, void tty, etc.
*/
@@ -342,7 +343,7 @@ child_process(entry *e, user *u)
if (ch != EOF) {
FILE *mail = NULL;
char *mailto;
- int bytes = 1;
+ size_t bytes = 1;
int status = 0;
pid_t mailpid;
@@ -425,13 +426,9 @@ child_process(entry *e, user *u)
* what's going on.
*/
if (mail && status) {
- char buf[MAX_TEMPSTR];
-
- snprintf(buf, sizeof buf,
- "mailed %d byte%s of output but got status 0x%04x\n",
- bytes, (bytes==1)?"":"s",
- status);
- log_it(usernm, "MAIL", buf);
+ syslog(LOG_NOTICE, "(%s) MAIL (mailed %zu byte"
+ "%s of output but got status 0x%04x)", usernm,
+ bytes, (bytes == 1) ? "" : "s", status);
}
} /*if data from grandchild*/
@@ -469,7 +466,7 @@ safe_p(const char *usernm, const char *s)
(isalnum(ch) || ch == '_' ||
(!first && strchr(safe_delim, ch))))
continue;
- log_it(usernm, "UNSAFE", s);
+ syslog(LOG_WARNING, "(%s) UNSAFE (%s)", usernm, s);
return (FALSE);
}
return (TRUE);
diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c
index e50f7400e6c..761f01d3d6f 100644
--- a/usr.sbin/cron/entry.c
+++ b/usr.sbin/cron/entry.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entry.c,v 1.47 2015/11/09 16:37:07 millert Exp $ */
+/* $OpenBSD: entry.c,v 1.48 2015/11/14 13:09:14 millert Exp $ */
/*
* Copyright 1988,1990,1993,1994 by Paul Vixie
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h> /* for structs.h */
#include <unistd.h>
@@ -290,7 +291,7 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw,
if (!env_get("SHELL", e->envp)) {
if (snprintf(envstr, sizeof envstr, "SHELL=%s", _PATH_BSHELL) >=
sizeof(envstr))
- log_it("CRON", "error", "can't set SHELL");
+ syslog(LOG_ERR, "(CRON) ERROR (can't set SHELL)");
else {
if ((tenvp = env_set(e->envp, envstr)) == NULL) {
ecode = e_memory;
@@ -302,7 +303,7 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw,
if (!env_get("HOME", e->envp)) {
if (snprintf(envstr, sizeof envstr, "HOME=%s", pw->pw_dir) >=
sizeof(envstr))
- log_it("CRON", "error", "can't set HOME");
+ syslog(LOG_ERR, "(CRON) ERROR (can't set HOME)");
else {
if ((tenvp = env_set(e->envp, envstr)) == NULL) {
ecode = e_memory;
@@ -313,7 +314,7 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw,
}
if (snprintf(envstr, sizeof envstr, "LOGNAME=%s", pw->pw_name) >=
sizeof(envstr))
- log_it("CRON", "error", "can't set LOGNAME");
+ syslog(LOG_ERR, "(CRON) ERROR (can't set LOGNAME)");
else {
if ((tenvp = env_set(e->envp, envstr)) == NULL) {
ecode = e_memory;
@@ -323,7 +324,7 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw,
}
if (snprintf(envstr, sizeof envstr, "USER=%s", pw->pw_name) >=
sizeof(envstr))
- log_it("CRON", "error", "can't set USER");
+ syslog(LOG_ERR, "(CRON) ERROR (can't set USER)");
else {
if ((tenvp = env_set(e->envp, envstr)) == NULL) {
ecode = e_memory;
diff --git a/usr.sbin/cron/funcs.h b/usr.sbin/cron/funcs.h
index 27222960200..29a721a2d09 100644
--- a/usr.sbin/cron/funcs.h
+++ b/usr.sbin/cron/funcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.h,v 1.27 2015/11/12 21:12:05 millert Exp $ */
+/* $OpenBSD: funcs.h,v 1.28 2015/11/14 13:09:14 millert Exp $ */
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -30,8 +30,6 @@ void load_database(cron_db **),
unget_char(int, FILE *),
free_entry(entry *),
skip_comments(FILE *),
- log_it(const char *, const char *, const char *),
- log_close(void),
poke_daemon(unsigned char),
atrun(at_db *, double, time_t);
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index fa1756bbb71..8e0865d0a85 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.70 2015/11/09 16:37:07 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.71 2015/11/14 13:09:14 millert Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h> /* for structs.h */
#include "macros.h"
@@ -32,7 +31,6 @@
#include "funcs.h"
#include "globals.h"
-static int syslog_open = FALSE;
int LineNumber;
/* get_char(file) : like getc() but increment LineNumber on newlines
@@ -120,33 +118,6 @@ skip_comments(FILE *file)
unget_char(ch, file);
}
-void
-log_it(const char *username, const char *event, const char *detail)
-{
- char **info, *info_events[] = { "CMD", "ATJOB", "BEGIN EDIT", "DELETE",
- "END EDIT", "LIST", "MAIL", "RELOAD", "REPLACE", "STARTUP", NULL };
-
- if (!syslog_open) {
- openlog(__progname, LOG_PID, LOG_CRON);
- syslog_open = TRUE; /* assume openlog success */
- }
-
- for (info = info_events; *info; info++)
- if (!strcmp(event, *info))
- break;
- syslog(*info ? LOG_INFO : LOG_WARNING, "(%s) %s (%s)", username, event,
- detail);
-}
-
-void
-log_close(void)
-{
- if (syslog_open) {
- closelog();
- syslog_open = FALSE;
- }
-}
-
/* char *first_word(char *s, char *t)
* return pointer to first word
* parameters: