summaryrefslogtreecommitdiff
path: root/usr.sbin/cron
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/atrun.c24
-rw-r--r--usr.sbin/cron/cron.c18
-rw-r--r--usr.sbin/cron/externs.h3
-rw-r--r--usr.sbin/cron/funcs.h4
-rw-r--r--usr.sbin/cron/misc.c16
5 files changed, 39 insertions, 26 deletions
diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c
index a5cc78dc61c..cc2418a8c67 100644
--- a/usr.sbin/cron/atrun.c
+++ b/usr.sbin/cron/atrun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atrun.c,v 1.18 2011/08/22 19:32:42 millert Exp $ */
+/* $OpenBSD: atrun.c,v 1.19 2013/04/17 15:58:45 deraadt Exp $ */
/*
* Copyright (c) 2002-2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -42,8 +42,7 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
{
DIR *atdir = NULL;
int cwd, queue, pending;
- long l;
- TIME_T run_time;
+ time_t run_time;
char *ep;
at_db new_db;
atjob *job, *tjob;
@@ -93,11 +92,10 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
* RUNTIME is the time to run in seconds since the epoch
* QUEUE is a letter that designates the job's queue
*/
- l = strtol(file->d_name, &ep, 10);
- if (ep[0] != '.' || !isalpha((unsigned char)ep[1]) || l < 0 ||
- l >= INT_MAX)
+ if (strtot(file->d_name, &ep, &run_time) == -1)
+ continue;
+ if (ep[0] != '.' || !isalpha((unsigned char)ep[1]))
continue;
- run_time = (TIME_T)l;
queue = ep[1];
if (!isalpha(queue))
continue;
@@ -133,7 +131,7 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
/* Free up old at db */
Debug(DLOAD, ("unlinking old at database:\n"))
for (job = old_db->head; job != NULL; ) {
- Debug(DLOAD, ("\t%ld.%c\n", (long)job->run_time, job->queue))
+ Debug(DLOAD, ("\t%lld.%c\n", (long long)job->run_time, job->queue))
tjob = job;
job = job->next;
free(tjob);
@@ -154,7 +152,7 @@ scan_atjobs(at_db *old_db, struct timeval *tv)
* Loop through the at job database and run jobs whose time have come.
*/
void
-atrun(at_db *db, double batch_maxload, TIME_T now)
+atrun(at_db *db, double batch_maxload, time_t now)
{
char atfile[MAX_FNAME];
struct stat statbuf;
@@ -168,8 +166,8 @@ atrun(at_db *db, double batch_maxload, TIME_T now)
if (job->run_time > now)
continue;
- snprintf(atfile, sizeof(atfile), "%s/%ld.%c", AT_DIR,
- (long)job->run_time, job->queue);
+ snprintf(atfile, sizeof(atfile), "%s/%lld.%c", AT_DIR,
+ (long long)job->run_time, job->queue);
if (stat(atfile, &statbuf) != 0)
unlink_job(db, job); /* disapeared */
@@ -202,8 +200,8 @@ atrun(at_db *db, double batch_maxload, TIME_T now)
((getloadavg(&la, 1) == 1) && la <= batch_maxload))
#endif
) {
- snprintf(atfile, sizeof(atfile), "%s/%ld.%c", AT_DIR,
- (long)batch->run_time, batch->queue);
+ snprintf(atfile, sizeof(atfile), "%s/%lld.%c", AT_DIR,
+ (long long)batch->run_time, batch->queue);
run_job(batch, atfile);
unlink_job(db, batch);
}
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index ea942c7932f..08aba72c485 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.43 2011/08/22 19:32:42 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.44 2013/04/17 15:58:45 deraadt Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -29,9 +29,9 @@ enum timejump { negative, small, medium, large };
static void usage(void),
run_reboot_jobs(cron_db *),
- find_jobs(int, cron_db *, int, int),
+ find_jobs(time_t, cron_db *, int, int),
set_time(int),
- cron_sleep(int),
+ cron_sleep(time_t),
sigchld_handler(int),
sighup_handler(int),
sigchld_reaper(void),
@@ -39,7 +39,8 @@ static void usage(void),
parse_args(int c, char *v[]);
static volatile sig_atomic_t got_sighup, got_sigchld;
-static int timeRunning, virtualTime, clockTime, cronSock;
+static time_t timeRunning, virtualTime, clockTime;
+static int cronSock;
static long GMToff;
static cron_db database;
static at_db at_database;
@@ -298,7 +299,7 @@ run_reboot_jobs(cron_db *db) {
}
static void
-find_jobs(int vtime, cron_db *db, int doWild, int doNonWild) {
+find_jobs(time_t vtime, cron_db *db, int doWild, int doNonWild) {
time_t virtualSecond = vtime * SECONDS_PER_MINUTE;
struct tm *tm = gmtime(&virtualSecond);
int minute, hour, dom, month, dow;
@@ -372,7 +373,7 @@ set_time(int initialize) {
* Try to just hit the next minute.
*/
static void
-cron_sleep(int target) {
+cron_sleep(time_t target) {
int fd, nfds;
unsigned char poke;
struct timeval t1, t2, tv;
@@ -391,8 +392,9 @@ cron_sleep(int target) {
}
while (timerisset(&tv) && tv.tv_sec < 65) {
- Debug(DSCH, ("[%ld] Target time=%ld, sec-to-wait=%ld\n",
- (long)getpid(), (long)target*SECONDS_PER_MINUTE, tv.tv_sec))
+ Debug(DSCH, ("[%ld] Target time=%lld, sec-to-wait=%lld\n",
+ (long)getpid(), (long long)target*SECONDS_PER_MINUTE,
+ (long long)tv.tv_sec))
poke = RELOAD_CRON | RELOAD_AT;
if (fdsr)
diff --git a/usr.sbin/cron/externs.h b/usr.sbin/cron/externs.h
index e1819d1e998..310b738767f 100644
--- a/usr.sbin/cron/externs.h
+++ b/usr.sbin/cron/externs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: externs.h,v 1.10 2004/06/17 22:11:55 millert Exp $ */
+/* $OpenBSD: externs.h,v 1.11 2013/04/17 15:58:45 deraadt Exp $ */
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
@@ -68,7 +68,6 @@
#define DIR_T struct dirent
#define WAIT_T int
#define SIG_T sig_t
-#define TIME_T time_t
#define PID_T pid_t
#ifndef TZNAME_ALREADY_DEFINED
diff --git a/usr.sbin/cron/funcs.h b/usr.sbin/cron/funcs.h
index 2bc548412af..19550df7e4a 100644
--- a/usr.sbin/cron/funcs.h
+++ b/usr.sbin/cron/funcs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: funcs.h,v 1.14 2008/01/05 16:59:06 chl Exp $ */
+/* $OpenBSD: funcs.h,v 1.15 2013/04/17 15:58:45 deraadt Exp $ */
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -57,6 +57,8 @@ int job_runqueue(void),
safe_p(const char *, const char *),
scan_atjobs(at_db *, struct timeval *);
+int strtot(const char *nptr, char **endptr, time_t *tp);
+
char *env_get(char *, char **),
*arpadate(time_t *),
*mkprints(unsigned char *, unsigned int),
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index a5e9b420f21..0b97c21c98d 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.44 2011/08/22 19:32:42 millert Exp $ */
+/* $OpenBSD: misc.c,v 1.45 2013/04/17 15:58:45 deraadt Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
@@ -443,7 +443,7 @@ log_it(const char *username, PID_T xpid, const char *event, const char *detail)
#if defined(LOG_FILE)
char *msg;
size_t msglen;
- TIME_T now = time((TIME_T) 0);
+ time_t now = time(NULL);
struct tm *t = localtime(&now);
#endif /*LOG_FILE*/
#if defined(SYSLOG)
@@ -784,3 +784,15 @@ poke_daemon(const char *spool_dir, unsigned char cookie) {
close(sock);
(void) signal(SIGPIPE, SIG_DFL);
}
+
+int
+strtot(const char *nptr, char **endptr, time_t *tp)
+{
+ unsigned long long ull;
+
+ ull = strtoull(nptr, endptr, 10);
+ if ((time_t)ull < 0 || (time_t)ull != ull)
+ return (-1);
+ *tp = (time_t)ull;
+ return (0);
+}