[Midnightbsd-cvs] src [10827] trunk/usr.sbin/cron/cron: sync with freebsd.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 10 16:31:17 EDT 2018
Revision: 10827
http://svnweb.midnightbsd.org/src/?rev=10827
Author: laffer1
Date: 2018-06-10 16:31:17 -0400 (Sun, 10 Jun 2018)
Log Message:
-----------
sync with freebsd.
Modified Paths:
--------------
trunk/usr.sbin/cron/cron/Makefile
trunk/usr.sbin/cron/cron/compat.h
trunk/usr.sbin/cron/cron/config.h
trunk/usr.sbin/cron/cron/cron.8
trunk/usr.sbin/cron/cron/cron.c
trunk/usr.sbin/cron/cron/cron.h
trunk/usr.sbin/cron/cron/database.c
trunk/usr.sbin/cron/cron/do_command.c
trunk/usr.sbin/cron/cron/externs.h
trunk/usr.sbin/cron/cron/job.c
trunk/usr.sbin/cron/cron/pathnames.h
trunk/usr.sbin/cron/cron/popen.c
trunk/usr.sbin/cron/cron/user.c
Property Changed:
----------------
trunk/usr.sbin/cron/cron/cron.8
Modified: trunk/usr.sbin/cron/cron/Makefile
===================================================================
--- trunk/usr.sbin/cron/cron/Makefile 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/Makefile 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,5 +1,5 @@
-# $MidnightBSD: src/usr.sbin/cron/cron/Makefile,v 1.3 2009/10/07 02:32:55 laffer1 Exp $
-# $FreeBSD: src/usr.sbin/cron/cron/Makefile,v 1.15 2001/07/20 06:19:40 obrien Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/cron/cron/Makefile 201390 2010-01-02 11:07:44Z ed $
PROG= cron
MAN= cron.8
Modified: trunk/usr.sbin/cron/cron/compat.h
===================================================================
--- trunk/usr.sbin/cron/cron/compat.h 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/compat.h 2018-06-10 20:31:17 UTC (rev 10827)
@@ -17,7 +17,7 @@
*/
/*
- * $FreeBSD: src/usr.sbin/cron/cron/compat.h,v 1.5 1999/08/28 01:15:49 peter Exp $
+ * $FreeBSD: stable/10/usr.sbin/cron/cron/compat.h 50479 1999-08-28 01:35:59Z peter $
*/
#ifndef __P
Modified: trunk/usr.sbin/cron/cron/config.h
===================================================================
--- trunk/usr.sbin/cron/cron/config.h 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/config.h 2018-06-10 20:31:17 UTC (rev 10827)
@@ -18,7 +18,7 @@
/* config.h - configurables for Vixie Cron
*
- * $FreeBSD: src/usr.sbin/cron/cron/config.h,v 1.8 1999/08/28 01:15:49 peter Exp $
+ * $FreeBSD: stable/10/usr.sbin/cron/cron/config.h 50479 1999-08-28 01:35:59Z peter $
*/
#if !defined(_PATH_SENDMAIL)
Modified: trunk/usr.sbin/cron/cron/cron.8
===================================================================
--- trunk/usr.sbin/cron/cron/cron.8 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/cron.8 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"/* Copyright 1988,1990,1993 by Paul Vixie
.\" * All rights reserved
.\" *
@@ -15,10 +16,9 @@
.\" * Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
.\" */
.\"
-.\" $MidnightBSD: src/usr.sbin/cron/cron/cron.8,v 1.2 2007/08/18 07:37:09 laffer1 Exp $
-.\" $FreeBSD: src/usr.sbin/cron/cron/cron.8,v 1.24 2005/02/13 23:45:51 ru Exp $
+.\" $FreeBSD: stable/10/usr.sbin/cron/cron/cron.8 321389 2017-07-23 18:00:11Z ngie $
.\"
-.Dd July 30, 2010
+.Dd July 19, 2017
.Dt CRON 8
.Os
.Sh NAME
@@ -29,6 +29,7 @@
.Op Fl j Ar jitter
.Op Fl J Ar rootjitter
.Op Fl m Ar mailto
+.Op Fl n
.Op Fl s
.Op Fl o
.Op Fl x Ar debugflag Ns Op , Ns Ar ...
@@ -53,7 +54,11 @@
.Nm
utility also searches for
.Pa /etc/crontab
-which is in a different format (see
+and files in
+.Pa /etc/cron.d
+and
+.Pa /usr/local/etc/cron.d
+which are in a different format (see
.Xr crontab 5 ) .
.Pp
The
@@ -133,6 +138,8 @@
.Li ''
or
.Li \*q\*q .
+.It Fl n
+Do not daemonize; run in foreground instead.
.It Fl s
Enable special handling of situations when the GMT offset of the local
timezone changes, such as the switches between the standard time and
@@ -203,13 +210,17 @@
.El
.El
.Sh FILES
-.Bl -tag -width /etc/pam.d/cron -compact
+.Bl -tag -width /usr/local/etc/cron.d -compact
.It Pa /etc/crontab
System crontab file
+.It Pa /etc/cron.d
+Directory for optional/modularized system crontab files.
.It Pa /etc/pam.d/cron
.Xr pam.conf 5
configuration file for
.Nm
+.It Pa /usr/local/etc/cron.d
+Directory for third-party package provided crontab files.
.It Pa /var/cron/tabs
Directory for personal crontab files
.El
Property changes on: trunk/usr.sbin/cron/cron/cron.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/cron/cron/cron.c
===================================================================
--- trunk/usr.sbin/cron/cron/cron.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/cron.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
@@ -13,12 +14,11 @@
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
- * $FreeBSD: src/usr.sbin/cron/cron/cron.c,v 1.15.8.1 2006/01/15 17:50:36 delphij Exp $
*/
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
- "$MidnightBSD: src/usr.sbin/cron/cron/cron.c,v 1.2 2007/08/18 06:59:04 laffer1 Exp $";
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/cron.c 321237 2017-07-19 19:41:13Z ngie $";
#endif
#define MAIN_PROGRAM
@@ -36,9 +36,9 @@
static void usage(void),
run_reboot_jobs(cron_db *),
- cron_tick(cron_db *),
- cron_sync(void),
- cron_sleep(cron_db *),
+ cron_tick(cron_db *, int),
+ cron_sync(int),
+ cron_sleep(cron_db *, int),
cron_clean(cron_db *),
#ifdef USE_SIGCHLD
sigchld_handler(int),
@@ -46,16 +46,22 @@
sighup_handler(int),
parse_args(int c, char *v[]);
+static int run_at_secres(cron_db *);
+
static time_t last_time = 0;
static int dst_enabled = 0;
+static int dont_daemonize = 0;
struct pidfh *pfh;
static void
usage() {
+#if DEBUGGING
char **dflags;
+#endif
fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] "
- "[-m mailto] [-s] [-o] [-x debugflag[,...]]\n");
+ "[-m mailto] [-n] [-s] [-o] [-x debugflag[,...]]\n");
+#if DEBUGGING
fprintf(stderr, "\ndebugflags: ");
for(dflags = DebugFlagNames; *dflags; dflags++) {
@@ -62,6 +68,7 @@
fprintf(stderr, "%s ", *dflags);
}
fprintf(stderr, "\n");
+#endif
exit(ERROR_EXIT);
}
@@ -95,6 +102,9 @@
char *argv[];
{
cron_db database;
+ int runnum;
+ int secres1, secres2;
+ struct tm *tm;
ProgramName = argv[0];
@@ -128,7 +138,7 @@
if (0) {
# endif
(void) fprintf(stderr, "[%d] cron started\n", getpid());
- } else {
+ } else if (dont_daemonize == 0) {
if (daemon(1, 0) == -1) {
pidfile_remove(pfh);
log_it("CRON",getpid(),"DEATH","can't become daemon");
@@ -144,23 +154,47 @@
database.tail = NULL;
database.mtime = (time_t) 0;
load_database(&database);
+ secres1 = secres2 = run_at_secres(&database);
run_reboot_jobs(&database);
- cron_sync();
+ cron_sync(secres1);
+ runnum = 0;
while (TRUE) {
# if DEBUGGING
/* if (!(DebugFlags & DTEST)) */
# endif /*DEBUGGING*/
- cron_sleep(&database);
+ cron_sleep(&database, secres1);
- load_database(&database);
+ if (secres1 == 0 || runnum % 60 == 0) {
+ load_database(&database);
+ secres2 = run_at_secres(&database);
+ if (secres2 != secres1) {
+ secres1 = secres2;
+ if (secres1 != 0) {
+ runnum = 0;
+ } else {
+ /*
+ * Going from 1 sec to 60 sec res. If we
+ * are already at minute's boundary, so
+ * let it run, otherwise schedule for the
+ * next minute.
+ */
+ tm = localtime(&TargetTime);
+ if (tm->tm_sec > 0) {
+ cron_sync(secres2);
+ continue;
+ }
+ }
+ }
+ }
/* do this iteration
*/
- cron_tick(&database);
+ cron_tick(&database, secres1);
- /* sleep 1 minute
+ /* sleep 1 or 60 seconds
*/
- TargetTime += 60;
+ TargetTime += (secres1 != 0) ? 1 : 60;
+ runnum += 1;
}
}
@@ -184,21 +218,21 @@
static void
-cron_tick(db)
- cron_db *db;
+cron_tick(cron_db *db, int secres)
{
static struct tm lasttm;
static time_t diff = 0, /* time difference in seconds from the last offset change */
difflimit = 0; /* end point for the time zone correction */
struct tm otztm; /* time in the old time zone */
- int otzminute, otzhour, otzdom, otzmonth, otzdow;
+ int otzsecond, otzminute, otzhour, otzdom, otzmonth, otzdow;
register struct tm *tm = localtime(&TargetTime);
- register int minute, hour, dom, month, dow;
+ register int second, minute, hour, dom, month, dow;
register user *u;
register entry *e;
/* make 0-based values out of these so we can use them as indicies
*/
+ second = (secres == 0) ? 0 : tm->tm_sec -FIRST_SECOND;
minute = tm->tm_min -FIRST_MINUTE;
hour = tm->tm_hour -FIRST_HOUR;
dom = tm->tm_mday -FIRST_DOM;
@@ -205,8 +239,8 @@
month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH;
dow = tm->tm_wday -FIRST_DOW;
- Debug(DSCH, ("[%d] tick(%d,%d,%d,%d,%d)\n",
- getpid(), minute, hour, dom, month, dow))
+ Debug(DSCH, ("[%d] tick(%d,%d,%d,%d,%d,%d)\n",
+ getpid(), second, minute, hour, dom, month, dow))
if (dst_enabled && last_time != 0
&& TargetTime > last_time /* exclude stepping back */
@@ -259,6 +293,7 @@
/* make 0-based values out of these so we can use them as indicies
*/
+ otzsecond = (secres == 0) ? 0 : otztm.tm_sec -FIRST_SECOND;
otzminute = otztm.tm_min -FIRST_MINUTE;
otzhour = otztm.tm_hour -FIRST_HOUR;
otzdom = otztm.tm_mday -FIRST_DOM;
@@ -280,7 +315,8 @@
e->uid, e->gid, e->cmd))
if ( diff != 0 && (e->flags & (RUN_AT|NOT_UNTIL)) ) {
- if (bit_test(e->minute, otzminute)
+ if (bit_test(e->second, otzsecond)
+ && bit_test(e->minute, otzminute)
&& bit_test(e->hour, otzhour)
&& bit_test(e->month, otzmonth)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
@@ -299,7 +335,8 @@
continue;
}
- if (bit_test(e->minute, minute)
+ if (bit_test(e->second, second)
+ && bit_test(e->minute, minute)
&& bit_test(e->hour, hour)
&& bit_test(e->month, month)
&& ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR))
@@ -329,20 +366,37 @@
* that's something sysadmin's know to expect what with crashing computers..
*/
static void
-cron_sync() {
- register struct tm *tm;
+cron_sync(int secres) {
+ struct tm *tm;
TargetTime = time((time_t*)0);
- tm = localtime(&TargetTime);
- TargetTime += (60 - tm->tm_sec);
+ if (secres != 0) {
+ TargetTime += 1;
+ } else {
+ tm = localtime(&TargetTime);
+ TargetTime += (60 - tm->tm_sec);
+ }
}
+static void
+timespec_subtract(struct timespec *result, struct timespec *x,
+ struct timespec *y)
+{
+ *result = *x;
+ result->tv_sec -= y->tv_sec;
+ result->tv_nsec -= y->tv_nsec;
+ if (result->tv_nsec < 0) {
+ result->tv_sec--;
+ result->tv_nsec += 1000000000;
+ }
+}
static void
-cron_sleep(db)
- cron_db *db;
+cron_sleep(cron_db *db, int secres)
{
- int seconds_to_wait = 0;
+ int seconds_to_wait;
+ int rval;
+ struct timespec ctime, ttime, stime, remtime;
/*
* Loop until we reach the top of the next minute, sleep when possible.
@@ -349,18 +403,24 @@
*/
for (;;) {
- seconds_to_wait = (int) (TargetTime - time((time_t*)0));
+ clock_gettime(CLOCK_REALTIME, &ctime);
+ ttime.tv_sec = TargetTime;
+ ttime.tv_nsec = 0;
+ timespec_subtract(&stime, &ttime, &ctime);
/*
* If the seconds_to_wait value is insane, jump the cron
*/
- if (seconds_to_wait < -600 || seconds_to_wait > 600) {
+ if (stime.tv_sec < -600 || stime.tv_sec > 600) {
cron_clean(db);
- cron_sync();
+ cron_sync(secres);
continue;
}
+ seconds_to_wait = (stime.tv_nsec > 0) ? stime.tv_sec + 1 :
+ stime.tv_sec;
+
Debug(DSCH, ("[%d] TargetTime=%ld, sec-to-wait=%d\n",
getpid(), (long)TargetTime, seconds_to_wait))
@@ -369,13 +429,19 @@
* to run, break
*/
- if (seconds_to_wait <= 0)
+ if (stime.tv_sec < 0)
break;
if (job_runqueue() == 0) {
Debug(DSCH, ("[%d] sleeping for %d seconds\n",
getpid(), seconds_to_wait))
- sleep(seconds_to_wait);
+ for (;;) {
+ rval = nanosleep(&stime, &remtime);
+ if (rval == 0 || errno != EINTR)
+ break;
+ stime.tv_sec = remtime.tv_sec;
+ stime.tv_nsec = remtime.tv_nsec;
+ }
}
}
}
@@ -448,7 +514,7 @@
int argch;
char *endp;
- while ((argch = getopt(argc, argv, "j:J:m:osx:")) != -1) {
+ while ((argch = getopt(argc, argv, "j:J:m:nosx:")) != -1) {
switch (argch) {
case 'j':
Jitter = strtoul(optarg, &endp, 10);
@@ -465,6 +531,9 @@
case 'm':
defmailto = optarg;
break;
+ case 'n':
+ dont_daemonize = 1;
+ break;
case 'o':
dst_enabled = 0;
break;
@@ -481,3 +550,17 @@
}
}
+static int
+run_at_secres(cron_db *db)
+{
+ user *u;
+ entry *e;
+
+ for (u = db->head; u != NULL; u = u->next) {
+ for (e = u->crontab; e != NULL; e = e->next) {
+ if ((e->flags & SEC_RES) != 0)
+ return 1;
+ }
+ }
+ return 0;
+}
Modified: trunk/usr.sbin/cron/cron/cron.h
===================================================================
--- trunk/usr.sbin/cron/cron/cron.h 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/cron.h 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
@@ -17,8 +18,7 @@
/* cron.h - header for vixie's cron
*
- * $MidnightBSD: src/usr.sbin/cron/cron/cron.h,v 1.2 2007/08/18 07:37:09 laffer1 Exp $
- * $FreeBSD: src/usr.sbin/cron/cron/cron.h,v 1.15.8.1 2006/01/15 17:50:36 delphij Exp $
+ * $FreeBSD: stable/10/usr.sbin/cron/cron/cron.h 321242 2017-07-19 20:24:38Z ngie $
*
* vix 14nov88 [rest of log is in RCS]
* vix 14jan87 [0 or 7 can be sunday; thanks, mwm at berkeley]
@@ -74,7 +74,6 @@
#define MAX_COMMAND 1000 /* max length of internally generated cmd */
#define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
#define MAX_TEMPSTR 100 /* obvious */
-#define MAX_UNAME 20 /* max length of username, should be overkill */
#define ROOT_UID 0 /* don't change this, it really must be root */
#define ROOT_USER "root" /* ditto */
#define SYS_NAME "*system*" /* magic owner name for system crontab */
@@ -125,6 +124,10 @@
LineNumber = ln; \
}
+#define FIRST_SECOND 0
+#define LAST_SECOND 59
+#define SECOND_COUNT (LAST_SECOND - FIRST_SECOND + 1)
+
#define FIRST_MINUTE 0
#define LAST_MINUTE 59
#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
@@ -166,6 +169,7 @@
#endif
char **envp;
char *cmd;
+ bitstr_t bit_decl(second, SECOND_COUNT);
bitstr_t bit_decl(minute, MINUTE_COUNT);
bitstr_t bit_decl(hour, HOUR_COUNT);
bitstr_t bit_decl(dom, DOM_COUNT);
@@ -177,6 +181,7 @@
#define WHEN_REBOOT 0x04
#define RUN_AT 0x08
#define NOT_UNTIL 0x10
+#define SEC_RES 0x20
time_t lastrun;
} entry;
@@ -214,7 +219,7 @@
unget_char(int, FILE *),
free_entry(entry *),
skip_comments(FILE *),
- log_it(char *, int, char *, char *),
+ log_it(char *, int, char *, const char *),
log_close(void);
int job_runqueue(void),
@@ -237,7 +242,7 @@
**env_copy(char **),
**env_set(char **, char *);
-user *load_user(int, struct passwd *, const char *),
+user *load_user(int, struct passwd *, char *),
*find_user(cron_db *, char *);
entry *load_entry(FILE *, void (*)(char *),
Modified: trunk/usr.sbin/cron/cron/database.c
===================================================================
--- trunk/usr.sbin/cron/cron/database.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/database.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
@@ -14,11 +15,10 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
*/
-/* $FreeBSD: src/usr.sbin/cron/cron/database.c,v 1.8 1999/08/28 01:15:50 peter Exp $ */
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
- "$MidnightBSD: src/usr.sbin/cron/cron/database.c,v 1.2 2007/08/18 07:37:09 laffer1 Exp $";
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/database.c 321242 2017-07-19 20:24:38Z ngie $";
#endif
/* vix 26jan87 [RCS has the log]
@@ -45,10 +45,19 @@
{
DIR *dir;
struct stat statbuf;
- struct stat syscron_stat;
+ struct stat syscron_stat, st;
+ time_t maxmtime;
DIR_T *dp;
cron_db new_db;
user *u, *nu;
+ struct {
+ const char *name;
+ struct stat st;
+ } syscrontabs [] = {
+ { SYSCRONTABS },
+ { LOCALSYSCRONTABS }
+ };
+ int i;
Debug(DLOAD, ("[%d] load_database()\n", getpid()))
@@ -66,6 +75,16 @@
if (stat(SYSCRONTAB, &syscron_stat) < OK)
syscron_stat.st_mtime = 0;
+ maxmtime = TMAX(statbuf.st_mtime, syscron_stat.st_mtime);
+
+ for (i = 0; i < nitems(syscrontabs); i++) {
+ if (stat(syscrontabs[i].name, &syscrontabs[i].st) != -1) {
+ maxmtime = TMAX(syscrontabs[i].st.st_mtime, maxmtime);
+ } else {
+ syscrontabs[i].st.st_mtime = 0;
+ }
+ }
+
/* if spooldir's mtime has not changed, we don't need to fiddle with
* the database.
*
@@ -73,7 +92,7 @@
* so is guaranteed to be different than the stat() mtime the first
* time this function is called.
*/
- if (old_db->mtime == TMAX(statbuf.st_mtime, syscron_stat.st_mtime)) {
+ if (old_db->mtime == maxmtime) {
Debug(DLOAD, ("[%d] spool dir mtime unch, no load needed.\n",
getpid()))
return;
@@ -84,7 +103,7 @@
* actually changed. Whatever is left in the old database when
* we're done is chaff -- crontabs that disappeared.
*/
- new_db.mtime = TMAX(statbuf.st_mtime, syscron_stat.st_mtime);
+ new_db.mtime = maxmtime;
new_db.head = new_db.tail = NULL;
if (syscron_stat.st_mtime) {
@@ -93,6 +112,30 @@
&new_db, old_db);
}
+ for (i = 0; i < nitems(syscrontabs); i++) {
+ char tabname[MAXPATHLEN];
+ if (syscrontabs[i].st.st_mtime == 0)
+ continue;
+ if (!(dir = opendir(syscrontabs[i].name))) {
+ log_it("CRON", getpid(), "OPENDIR FAILED",
+ syscrontabs[i].name);
+ (void) exit(ERROR_EXIT);
+ }
+
+ while (NULL != (dp = readdir(dir))) {
+ if (dp->d_name[0] == '.')
+ continue;
+ if (fstatat(dirfd(dir), dp->d_name, &st, 0) == 0 &&
+ !S_ISREG(st.st_mode))
+ continue;
+ snprintf(tabname, sizeof(tabname), "%s/%s",
+ syscrontabs[i].name, dp->d_name);
+ process_crontab("root", SYS_NAME, tabname,
+ &syscrontabs[i].st, &new_db, old_db);
+ }
+ closedir(dir);
+ }
+
/* we used to keep this dir open all the time, for the sake of
* efficiency. however, we need to close it in every fork, and
* we fork a lot more often than the mtime of the dir changes.
Modified: trunk/usr.sbin/cron/cron/do_command.c
===================================================================
--- trunk/usr.sbin/cron/cron/do_command.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/do_command.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
@@ -14,10 +15,10 @@
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
*/
-/* $FreeBSD: src/usr.sbin/cron/cron/do_command.c,v 1.22.8.1 2006/01/15 17:50:36 delphij Exp $ */
+
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
- "$MidnightBSD: src/usr.sbin/cron/cron/do_command.c,v 1.2 2007/08/18 07:37:09 laffer1 Exp $";
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/do_command.c 321244 2017-07-19 20:29:07Z ngie $";
#endif
@@ -147,7 +148,7 @@
#ifdef USE_SIGCHLD
/* our parent is watching for our death by catching SIGCHLD. we
* do not care to watch for our children's deaths this way -- we
- * use wait() explictly. so we have to disable the signal (which
+ * use wait() explicitly. so we have to disable the signal (which
* was inherited from the parent).
*/
(void) signal(SIGCHLD, SIG_DFL);
@@ -161,8 +162,10 @@
/* create some pipes to talk to our future child
*/
- pipe(stdin_pipe); /* child's stdin */
- pipe(stdout_pipe); /* child's stdout */
+ if (pipe(stdin_pipe) != 0 || pipe(stdout_pipe) != 0) {
+ log_it("CRON", getpid(), "error", "can't pipe");
+ exit(ERROR_EXIT);
+ }
/* since we are a forked process, we can diddle the command string
* we were passed -- nobody else is going to use it again, right?
@@ -335,8 +338,9 @@
_exit(OK_EXIT);
}
# endif /*DEBUGGING*/
- execle(shell, shell, "-c", e->cmd, (char *)0, e->envp);
- warn("execl: couldn't exec `%s'", shell);
+ execle(shell, shell, "-c", e->cmd, (char *)NULL,
+ e->envp);
+ warn("execle: couldn't exec `%s'", shell);
_exit(ERROR_EXIT);
}
break;
@@ -481,7 +485,9 @@
auto char mailcmd[MAX_COMMAND];
auto char hostname[MAXHOSTNAMELEN];
- (void) gethostname(hostname, MAXHOSTNAMELEN);
+ if (gethostname(hostname, MAXHOSTNAMELEN) == -1)
+ hostname[0] = '\0';
+ hostname[sizeof(hostname) - 1] = '\0';
(void) snprintf(mailcmd, sizeof(mailcmd),
MAILARGS, MAILCMD);
if (!(mail = cron_popen(mailcmd, "w", e))) {
@@ -488,7 +494,8 @@
warn("%s", MAILCMD);
(void) _exit(ERROR_EXIT);
}
- fprintf(mail, "From: %s (Cron Daemon)\n", usernm);
+ fprintf(mail, "From: Cron Daemon <%s@%s>\n",
+ usernm, hostname);
fprintf(mail, "To: %s\n", mailto);
fprintf(mail, "Subject: Cron <%s@%s> %s\n",
usernm, first_word(hostname, "."),
Modified: trunk/usr.sbin/cron/cron/externs.h
===================================================================
--- trunk/usr.sbin/cron/cron/externs.h 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/externs.h 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,4 +1,6 @@
-/* $MidnightBSD: src/usr.sbin/cron/cron/externs.h,v 1.2 2007/08/18 07:37:09 laffer1 Exp $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/cron/cron/externs.h 173412 2007-11-07 10:53:41Z kevlo $ */
+
/* Copyright 1993,1994 by Paul Vixie
* All rights reserved
*
Modified: trunk/usr.sbin/cron/cron/job.c
===================================================================
--- trunk/usr.sbin/cron/cron/job.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/job.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,5 +1,4 @@
/* $MidnightBSD$ */
-/* $FreeBSD: src/usr.sbin/cron/cron/job.c,v 1.6 1999/08/28 01:15:50 peter Exp $ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
*
@@ -17,6 +16,12 @@
* Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
*/
+#if !defined(lint) && !defined(LINT)
+static const char rcsid[] =
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/job.c 50479 1999-08-28 01:35:59Z peter $";
+#endif
+
+
#include "cron.h"
Modified: trunk/usr.sbin/cron/cron/pathnames.h
===================================================================
--- trunk/usr.sbin/cron/cron/pathnames.h 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/pathnames.h 2018-06-10 20:31:17 UTC (rev 10827)
@@ -17,7 +17,7 @@
*/
/*
- * $FreeBSD: src/usr.sbin/cron/cron/pathnames.h,v 1.5 1999/08/28 01:15:50 peter Exp $
+ * $FreeBSD: stable/10/usr.sbin/cron/cron/pathnames.h 321242 2017-07-19 20:24:38Z ngie $
*/
#if (defined(BSD)) && (BSD >= 199103) || defined(__linux) || defined(AIX)
@@ -63,6 +63,8 @@
/* 4.3BSD-style crontab */
#define SYSCRONTAB "/etc/crontab"
+#define SYSCRONTABS "/etc/cron.d"
+#define LOCALSYSCRONTABS "/usr/local/etc/cron.d"
/* what editor to use if no EDITOR or VISUAL
* environment variable specified.
Modified: trunk/usr.sbin/cron/cron/popen.c
===================================================================
--- trunk/usr.sbin/cron/cron/popen.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/popen.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
@@ -22,7 +23,6 @@
/* this came out of the ftpd sources; it's been modified to avoid the
* globbing stuff since we don't need it. also execvp instead of execv.
*/
-/* $FreeBSD: src/usr.sbin/cron/cron/popen.c,v 1.12 2002/02/06 02:00:07 bbraun Exp $ */
#ifndef lint
#if 0
@@ -29,7 +29,7 @@
static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif
static const char rcsid[] =
- "$MidnightBSD$";
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/popen.c 293132 2016-01-04 03:20:41Z pfg $";
#endif /* not lint */
#include "cron.h"
@@ -83,9 +83,8 @@
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return(NULL);
- if (!(pids = (PID_T *)malloc((u_int)(fds * sizeof(PID_T)))))
+ if (!(pids = calloc(fds, sizeof(PID_T))))
return(NULL);
- bzero((char *)pids, fds * sizeof(PID_T));
}
if (pipe(pdes) < 0)
return(NULL);
@@ -173,8 +172,10 @@
/* fall back to the old method */
(void) endpwent();
# endif
- /* set our directory, uid and gid. Set gid first,
- * since once we set uid, we've lost root privileges.
+ /*
+ * Set our directory, uid and gid. Set gid
+ * first since once we set uid, we've lost
+ * root privileges.
*/
if (setgid(e->gid) != 0)
_exit(ERROR_EXIT);
Modified: trunk/usr.sbin/cron/cron/user.c
===================================================================
--- trunk/usr.sbin/cron/cron/user.c 2018-06-10 20:29:28 UTC (rev 10826)
+++ trunk/usr.sbin/cron/cron/user.c 2018-06-10 20:31:17 UTC (rev 10827)
@@ -1,26 +1,26 @@
-/* $MidnightBSD: src/usr.sbin/cron/cron/user.c,v 1.2 2007/08/18 07:37:09 laffer1 Exp $ */
-/* $FreeBSD: src/usr.sbin/cron/cron/user.c,v 1.8 1999/08/28 01:15:50 peter Exp $ */
+/* $MidnightBSD$ */
/* Copyright 1988,1990,1993,1994 by Paul Vixie
* All rights reserved
- */
-
-/*
- * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
*
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * Distribute freely, except: don't remove my name from the source or
+ * documentation (don't take credit for my work), mark your changes (don't
+ * get me blamed for your possible bugs), don't alter or remove this
+ * notice. May be sold if buildable source is provided to buyer. No
+ * warrantee of any kind, express or implied, is included with this
+ * software; use at your own risk, responsibility for damages (if any) to
+ * anyone resulting from the use of this software rests entirely with the
+ * user.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
+ * I'll try to keep a version up to date. I can be reached as follows:
+ * Paul Vixie <paul at vix.com> uunet!decwrl!vixie!paul
*/
+#if !defined(lint) && !defined(LINT)
+static const char rcsid[] =
+ "$FreeBSD: stable/10/usr.sbin/cron/cron/user.c 50479 1999-08-28 01:35:59Z peter $";
+#endif
+
/* vix 26jan87 [log is in RCS file]
*/
@@ -30,8 +30,10 @@
static char *User_name;
void
-free_user(user *u) {
- entry *e, *ne;
+free_user(u)
+ user *u;
+{
+ entry *e, *ne;
free(u->name);
for (e = u->crontab; e != NULL; e = ne) {
@@ -42,23 +44,28 @@
}
static void
-log_error(char *msg)
+log_error(msg)
+ char *msg;
{
log_it(User_name, getpid(), "PARSE", msg);
}
user *
-load_user(int crontab_fd, struct passwd *pw, const char *name) {
- char envstr[MAX_ENVSTR];
- FILE *file;
- user *u;
- entry *e;
- int status, save_errno;
- char **envp, **tenvp;
+load_user(crontab_fd, pw, name)
+ int crontab_fd;
+ struct passwd *pw; /* NULL implies syscrontab */
+ char *name;
+{
+ char envstr[MAX_ENVSTR];
+ FILE *file;
+ user *u;
+ entry *e;
+ int status;
+ char **envp, **tenvp;
if (!(file = fdopen(crontab_fd, "r"))) {
- perror("fdopen on crontab_fd in load_user");
- return (NULL);
+ warn("fdopen on crontab_fd in load_user");
+ return NULL;
}
Debug(DPARS, ("load_user()\n"))
@@ -70,24 +77,23 @@
return NULL;
}
if ((u->name = strdup(name)) == NULL) {
- save_errno = errno;
free(u);
- errno = save_errno;
- return (NULL);
+ errno = ENOMEM;
+ return NULL;
}
u->crontab = NULL;
- /* init environment. this will be copied/augmented for each entry.
+ /*
+ * init environment. this will be copied/augmented for each entry.
*/
if ((envp = env_init()) == NULL) {
- save_errno = errno;
free(u->name);
free(u);
- errno = save_errno;
- return (NULL);
+ return NULL;
}
- /* load the crontab
+ /*
+ * load the crontab
*/
while ((status = load_env(envstr, file)) >= OK) {
switch (status) {
@@ -104,14 +110,13 @@
}
break;
case TRUE:
- if ((tenvp = env_set(envp, envstr)) == NULL) {
- save_errno = errno;
+ if ((tenvp = env_set(envp, envstr))) {
+ envp = tenvp;
+ } else {
free_user(u);
u = NULL;
- errno = save_errno;
goto done;
}
- envp = tenvp;
break;
}
}
@@ -120,5 +125,5 @@
env_free(envp);
fclose(file);
Debug(DPARS, ("...load_user() done\n"))
- return (u);
+ return u;
}
More information about the Midnightbsd-cvs
mailing list