summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/at/at.c32
-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
6 files changed, 54 insertions, 43 deletions
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c
index 88541d7dac8..0bc7673d8a3 100644
--- a/usr.bin/at/at.c
+++ b/usr.bin/at/at.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: at.c,v 1.60 2011/08/30 19:56:08 guenther Exp $ */
+/* $OpenBSD: at.c,v 1.61 2013/04/17 15:58:42 deraadt Exp $ */
/*
* at.c : Put file into atrun queue
@@ -67,6 +67,7 @@ static __dead void panic(const char *);
static void perr(const char *);
static void perr2(const char *, const char *);
static __dead void usage(void);
+static int rmok(long long);
time_t parsetime(int, char **);
/*
@@ -161,8 +162,8 @@ newjob(time_t runtimer, int queue)
* queues instead...
*/
for (i = 0; i < 120; i++) {
- snprintf(atfile, sizeof(atfile), "%s/%ld.%c", AT_DIR,
- (long)runtimer, queue);
+ snprintf(atfile, sizeof(atfile), "%s/%lld.%c", AT_DIR,
+ (long long)runtimer, queue);
fd = open(atfile, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR);
if (fd >= 0)
return (fd);
@@ -440,7 +441,7 @@ print_job(struct atjob *job, int n, int shortformat)
runtime = *localtime(&job->runtimer);
if (shortformat) {
strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime);
- (void)printf("%ld.%c\t%s\n", (long)job->runtimer,
+ (void)printf("%lld.%c\t%s\n", (long long)job->runtimer,
job->queue, timestr);
} else {
pw = getpwuid(job->uid);
@@ -450,9 +451,9 @@ print_job(struct atjob *job, int n, int shortformat)
else
printf("%3d%-5s", n, ranks[n % 10]);
strftime(timestr, TIMESIZE, "%b %e, %Y %R", &runtime);
- (void)printf("%-21.18s%-11.8s%10ld.%c %c%s\n",
+ (void)printf("%-21.18s%-11.8s%10lld.%c %c%s\n",
timestr, pw ? pw->pw_name : "???",
- (long)job->runtimer, job->queue, job->queue,
+ (long long)job->runtimer, job->queue, job->queue,
(S_IXUSR & job->mode) ? "" : " (done)");
}
}
@@ -473,7 +474,6 @@ list_jobs(int argc, char **argv, int count_only, int csort)
struct stat stbuf;
time_t runtimer;
uid_t *uids;
- long l;
char queue, *ep;
DIR *spool;
int i, shortformat;
@@ -537,11 +537,10 @@ list_jobs(int argc, char **argv, int count_only, int csort)
|| !(S_IXUSR & stbuf.st_mode || vflag))
continue;
- l = strtol(dirent->d_name, &ep, 10);
- if (*ep != '.' || !isalpha(*(ep + 1)) || *(ep + 2) != '\0' ||
- l < 0 || l >= INT_MAX)
+ if (strtot(dirent->d_name, &ep, &runtimer) == -1)
+ continue;
+ if (*ep != '.' || !isalpha(*(ep + 1)) || *(ep + 2) != '\0')
continue;
- runtimer = (time_t)l;
queue = *(ep + 1);
if (atqueue && (queue != atqueue))
@@ -608,11 +607,11 @@ list_jobs(int argc, char **argv, int count_only, int csort)
}
static int
-rmok(int job)
+rmok(long long job)
{
int ch, junk;
- printf("%d: remove it? ", job);
+ printf("%lld: remove it? ", job);
ch = getchar();
while ((junk = getchar()) != EOF && junk != '\n')
;
@@ -689,11 +688,10 @@ process_jobs(int argc, char **argv, int what)
if (stbuf.st_uid != real_uid && real_uid != 0)
continue;
- l = strtol(dirent->d_name, &ep, 10);
- if (*ep != '.' || !isalpha(*(ep + 1)) || *(ep + 2) != '\0' ||
- l < 0 || l >= INT_MAX)
+ if (strtot(dirent->d_name, &ep, &runtimer) == -1)
+ continue;
+ if (*ep != '.' || !isalpha(*(ep + 1)) || *(ep + 2) != '\0')
continue;
- runtimer = (time_t)l;
/* Check runtimer against argv; argc==0 means do all. */
job_matches = (argc == 0) ? 1 : 0;
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);
+}