[Midnightbsd-cvs] src [11436] trunk/usr.bin/at: sync at with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 11:50:50 EDT 2018


Revision: 11436
          http://svnweb.midnightbsd.org/src/?rev=11436
Author:   laffer1
Date:     2018-07-07 11:50:50 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync at with freebsd

Modified Paths:
--------------
    trunk/usr.bin/at/Makefile
    trunk/usr.bin/at/Makefile.inc
    trunk/usr.bin/at/at.c
    trunk/usr.bin/at/at.h
    trunk/usr.bin/at/at.man
    trunk/usr.bin/at/panic.c
    trunk/usr.bin/at/panic.h
    trunk/usr.bin/at/parsetime.c
    trunk/usr.bin/at/parsetime.h
    trunk/usr.bin/at/perm.c
    trunk/usr.bin/at/perm.h
    trunk/usr.bin/at/privs.h

Property Changed:
----------------
    trunk/usr.bin/at/LEGAL
    trunk/usr.bin/at/Makefile.inc
    trunk/usr.bin/at/at.man

Index: trunk/usr.bin/at/LEGAL
===================================================================
--- trunk/usr.bin/at/LEGAL	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/LEGAL	2018-07-07 15:50:50 UTC (rev 11436)

Property changes on: trunk/usr.bin/at/LEGAL
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/at/Makefile
===================================================================
--- trunk/usr.bin/at/Makefile	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/Makefile	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,4 +1,5 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/at/Makefile 226420 2011-10-16 07:57:01Z ed $
 
 .include "${.CURDIR}/Makefile.inc"
 
@@ -11,7 +12,7 @@
 	at.1 atq.1 \
 	at.1 atrm.1
 
-WARNS?=	1
+NO_WFORMAT=
 
 BINOWN=	root
 BINMODE= 4555

Modified: trunk/usr.bin/at/Makefile.inc
===================================================================
--- trunk/usr.bin/at/Makefile.inc	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/Makefile.inc	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,4 +1,6 @@
-VERSION= 2.9
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/at/Makefile.inc 287549 2015-09-08 02:02:08Z delphij $
+
 LOCKFILE = .lockfile
 ATSPOOL_DIR=/var/at/spool
 ATJOB_DIR=/var/at/jobs
@@ -13,7 +15,7 @@
 CFLAGS += -DATJOB_DIR=\"$(ATJOB_DIR)/\" \
 	-DLFILE=\"$(ATJOB_DIR)/$(LOCKFILE)\" \
 	-DLOADAVG_MX=$(LOADAVG_MX) -DATSPOOL_DIR=\"$(ATSPOOL_DIR)\" \
-	-DVERSION=\"$(VERSION)\" -DDAEMON_UID=$(DAEMON_UID) -DDAEMON_GID=$(DAEMON_GID) \
+	-DDAEMON_UID=$(DAEMON_UID) -DDAEMON_GID=$(DAEMON_GID) \
 	-DDEFAULT_BATCH_QUEUE=\'$(DEFAULT_BATCH_QUEUE)\' \
 	-DDEFAULT_AT_QUEUE=\'$(DEFAULT_AT_QUEUE)\' -DPERM_PATH=\"$(PERM_PATH)/\"
 


Property changes on: trunk/usr.bin/at/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/at/at.c
===================================================================
--- trunk/usr.bin/at/at.c	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/at.c	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  at.c : Put file into atrun queue
  *  Copyright (C) 1993, 1994 Thomas Koenig
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/at/at.c 272438 2014-10-02 18:26:40Z delphij $");
 
 #define _USE_BSD 1
 
@@ -90,11 +91,12 @@
 
 /* File scope variables */
 
-const char *no_export[] =
-{
+static const char *no_export[] = {
     "TERM", "TERMCAP", "DISPLAY", "_"
-} ;
+};
 static int send_mail = 0;
+static char *atinput = NULL;	/* where to get input from */
+static char atqueue = 0;	/* which queue to examine for jobs (atq) */
 
 /* External variables */
 
@@ -101,9 +103,6 @@
 extern char **environ;
 int fcreated;
 char atfile[] = ATJOB_DIR "12345678901234";
-
-char *atinput = (char*)0;	/* where to get input from */
-char atqueue = 0;		/* which queue to examine for jobs (atq) */
 char atverify = 0;		/* verify time instead of queuing job */
 char *namep;
 
@@ -369,6 +368,7 @@
 
 	if (export)
 	{
+	    (void)fputs("export ", fp);
 	    fwrite(*atenv, sizeof(char), eqp-*atenv, fp);
 	    for(ap = eqp;*ap != '\0'; ap++)
 	    {
@@ -391,8 +391,6 @@
 		    fputc(*ap, fp);
 		}
 	    }
-	    fputs("; export ", fp);
-	    fwrite(*atenv, sizeof(char), eqp-*atenv -1, fp);
 	    fputc('\n', fp);
 	    
 	}
@@ -533,6 +531,10 @@
     /* Delete every argument (job - ID) given
      */
     int i;
+    int rc;
+    int nofJobs;
+    int nofDone;
+    int statErrno;
     struct stat buf;
     DIR *spool;
     struct dirent *dirent;
@@ -540,6 +542,9 @@
     char queue;
     long jobno;
 
+    nofJobs = argc - optind;
+    nofDone = 0;
+
     PRIV_START
 
     if (chdir(ATJOB_DIR) != 0)
@@ -555,9 +560,20 @@
     while((dirent = readdir(spool)) != NULL) {
 
 	PRIV_START
-	if (stat(dirent->d_name, &buf) != 0)
-	    perr("cannot stat in " ATJOB_DIR);
+	rc = stat(dirent->d_name, &buf);
+	statErrno = errno;
 	PRIV_END
+	/* There's a race condition between readdir above and stat here:
+	 * another atrm process could have removed the file from the spool
+	 * directory under our nose. If this happens, stat will set errno to
+	 * ENOENT, which we shouldn't treat as fatal.
+	 */
+	if (rc != 0) {
+	    if (statErrno == ENOENT)
+		continue;
+	    else
+		perr("cannot stat in " ATJOB_DIR);
+	}
 
 	if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3)
 	    continue;
@@ -603,9 +619,15 @@
 		    errx(EXIT_FAILURE, "internal error, process_jobs = %d",
 			what);
 	        }
+
+		/* All arguments have been processed
+		 */
+		if (++nofDone == nofJobs)
+		    goto end;
 	    }
 	}
     }
+end:
     closedir(spool);
 } /* delete_jobs */
 

Modified: trunk/usr.bin/at/at.h
===================================================================
--- trunk/usr.bin/at/at.h	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/at.h	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  at.h -  header for at(1)
  *  Copyright (C) 1993  Thomas Koenig
@@ -22,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/at/at.h 80294 2001-07-24 14:15:51Z obrien $
  */
 
 extern int fcreated;

Modified: trunk/usr.bin/at/at.man
===================================================================
--- trunk/usr.bin/at/at.man	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/at.man	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,4 +1,5 @@
 .\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/at/at.man 202756 2010-01-21 17:25:12Z ed $
 .Dd January 13, 2002
 .Dt "AT" 1
 .Os


Property changes on: trunk/usr.bin/at/at.man
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/at/panic.c
===================================================================
--- trunk/usr.bin/at/panic.c	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/panic.c	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  panic.c - terminate fast in case of error
  *  Copyright (C) 1993  Thomas Koenig
@@ -24,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/at/panic.c 96701 2002-05-16 00:47:14Z tjr $");
 
 /* System Headers */
 

Modified: trunk/usr.bin/at/panic.h
===================================================================
--- trunk/usr.bin/at/panic.h	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/panic.h	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  panic.h -  header for at(1)
  *  Copyright (C) 1993  Thomas Koenig
@@ -22,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/at/panic.h 89315 2002-01-13 20:21:08Z mike $
  */
 
 #include <sys/cdefs.h>

Modified: trunk/usr.bin/at/parsetime.c
===================================================================
--- trunk/usr.bin/at/parsetime.c	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/parsetime.c	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  parsetime.c - parse time for at(1)
  *  Copyright (C) 1993, 1994  Thomas Koenig
@@ -34,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/at/parsetime.c 241230 2012-10-05 17:54:27Z cracauer $");
 
 /* System Headers */
 
@@ -64,7 +65,7 @@
     MIDNIGHT, NOON, TEATIME,
     PM, AM, TOMORROW, TODAY, NOW,
     MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS,
-    NUMBER, PLUS, DOT, SLASH, ID, JUNK,
+    NUMBER, PLUS, MINUS, DOT, SLASH, ID, JUNK,
     JAN, FEB, MAR, APR, MAY, JUN,
     JUL, AUG, SEP, OCT, NOV, DEC,
     SUN, MON, TUE, WED, THU, FRI, SAT
@@ -72,7 +73,7 @@
 
 /* parse translation table - table driven parsers can be your FRIEND!
  */
-struct {
+static const struct {
     const char *name;	/* token name */
     int value;	/* token id */
     int plural;	/* is this plural? */
@@ -246,6 +247,8 @@
 	    return sc_tokid = DOT;
 	else if (sc_token[0] == '+')
 	    return sc_tokid = PLUS;
+	else if (sc_token[0] == '-')
+	    return sc_tokid = MINUS;
 	else if (sc_token[0] == '/')
 	    return sc_tokid = SLASH;
 	else
@@ -277,23 +280,15 @@
 
 
 /*
- * plus() parses a now + time
- *
- *  at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS|MONTHS|YEARS]
- *
+ * plus_or_minus() holds functionality common to plus() and minus()
  */
-
 static void
-plus(struct tm *tm)
+plus_or_minus(struct tm *tm, int delay)
 {
-    int delay;
     int expectplur;
 
-    expect(NUMBER);
+    expectplur = (delay != 1 && delay != -1) ? 1 : 0;
 
-    delay = atoi(sc_token);
-    expectplur = (delay != 1) ? 1 : 0;
-
     switch (token()) {
     case YEARS:
 	    tm->tm_year += delay;
@@ -323,11 +318,43 @@
     tm->tm_isdst = -1;
     if (mktime(tm) < 0)
 	plonk(sc_tokid);
+} /* plus_or_minus */
 
+
+/*
+ * plus() parses a now + time
+ *
+ *  at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS|MONTHS|YEARS]
+ *
+ */
+static void
+plus(struct tm *tm)
+{
+    int delay;
+
+    expect(NUMBER);
+
+    delay = atoi(sc_token);
+    plus_or_minus(tm, delay);
 } /* plus */
 
 
 /*
+ * minus() is like plus but can not be used with NOW
+ */
+static void
+minus(struct tm *tm)
+{
+    int delay;
+
+    expect(NUMBER);
+
+    delay = -atoi(sc_token);
+    plus_or_minus(tm, delay);
+} /* minus */
+
+
+/*
  * tod() computes the time of day
  *     [NUMBER [DOT NUMBER] [AM|PM]]
  */
@@ -379,7 +406,8 @@
      * if we've gone past that time - but if we're specifying a time plus
      * a relative offset, it's okay to bump things
      */
-    if ((sc_tokid == EOF || sc_tokid == PLUS) && tm->tm_hour > hour) {
+    if ((sc_tokid == EOF || sc_tokid == PLUS || sc_tokid == MINUS) && 
+	tm->tm_hour > hour) {
 	tm->tm_mday++;
 	tm->tm_wday++;
     }
@@ -456,6 +484,9 @@
     case PLUS:
 	    plus(tm);
 	    break;
+    case MINUS:
+	    minus(tm);
+	    break;
 
     case TOMORROW:
 	    /* do something tomorrow */
@@ -588,6 +619,12 @@
 	    plus(&runtime);
 	    break;
 
+	    /* MINUS is different from PLUS in that NOW is not
+	     * an optional prefix for it
+	     */
+    case MINUS:
+	    minus(&runtime);
+	    break;
     case NUMBER:
 	    tod(&runtime);
 	    month(&runtime);

Modified: trunk/usr.bin/at/parsetime.h
===================================================================
--- trunk/usr.bin/at/parsetime.h	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/parsetime.h	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  at.h -  header for at(1)
  *  Copyright (C) 1993  Thomas Koenig

Modified: trunk/usr.bin/at/perm.c
===================================================================
--- trunk/usr.bin/at/perm.c	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/perm.c	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  perm.c - check user permission for at(1)
  *  Copyright (C) 1994  Thomas Koenig
@@ -24,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/at/perm.c 87628 2001-12-10 21:13:08Z dwmalone $");
 
 /* System Headers */
 

Modified: trunk/usr.bin/at/perm.h
===================================================================
--- trunk/usr.bin/at/perm.h	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/perm.h	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  perm.h -  header for at(1)
  *  Copyright (C) 1994  Thomas Koenig
@@ -22,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/at/perm.h 87208 2001-12-02 12:26:18Z markm $
  */
 
 int check_permission(void);

Modified: trunk/usr.bin/at/privs.h
===================================================================
--- trunk/usr.bin/at/privs.h	2018-07-07 15:49:54 UTC (rev 11435)
+++ trunk/usr.bin/at/privs.h	2018-07-07 15:50:50 UTC (rev 11436)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /* 
  *  privs.h - header for privileged operations 
  *  Copyright (C) 1993  Thomas Koenig
@@ -22,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/at/privs.h 249404 2013-04-12 14:19:44Z gahr $
  */
 
 #ifndef _PRIVS_H
@@ -59,15 +60,13 @@
  * to the real userid before calling any of them.
  */
 
-#ifndef MAIN
-extern
-#endif
+extern uid_t real_uid, effective_uid;
+extern gid_t real_gid, effective_gid;
+
+#ifdef MAIN
 uid_t real_uid, effective_uid;
-
-#ifndef MAIN 
-extern
+gid_t real_gid, effective_gid;
 #endif
-gid_t real_gid, effective_gid;
 
 #define RELINQUISH_PRIVS { \
 	real_uid = getuid(); \
@@ -74,8 +73,8 @@
 	effective_uid = geteuid(); \
 	real_gid = getgid(); \
 	effective_gid = getegid(); \
-	seteuid(real_uid); \
-	setegid(real_gid); \
+	if (seteuid(real_uid) != 0) err(1, "seteuid failed"); \
+	if (setegid(real_gid) != 0) err(1, "setegid failed"); \
 }
 
 #define RELINQUISH_PRIVS_ROOT(a, b) { \
@@ -83,18 +82,18 @@
 	effective_uid = geteuid(); \
 	real_gid = (b); \
 	effective_gid = getegid(); \
-	setegid(real_gid); \
-	seteuid(real_uid); \
+	if (setegid(real_gid) != 0) err(1, "setegid failed"); \
+	if (seteuid(real_uid) != 0) err(1, "seteuid failed"); \
 }
 
 #define PRIV_START { \
-	seteuid(effective_uid); \
-	setegid(effective_gid); \
+	if (seteuid(effective_uid) != 0) err(1, "seteuid failed"); \
+	if (setegid(effective_gid) != 0) err(1, "setegid failed"); \
 }
 
 #define PRIV_END { \
-	setegid(real_gid); \
-	seteuid(real_uid); \
+	if (setegid(real_gid) != 0) err(1, "setegid failed"); \
+	if (seteuid(real_uid) != 0) err(1, "seteuid failed"); \
 }
 
 #define REDUCE_PRIV(a, b) { \
@@ -101,8 +100,8 @@
 	PRIV_START \
 	effective_uid = (a); \
 	effective_gid = (b); \
-	setreuid((uid_t)-1, effective_uid); \
-	setregid((gid_t)-1, effective_gid); \
+	if (setregid((gid_t)-1, effective_gid) != 0) err(1, "setregid failed"); \
+	if (setreuid((uid_t)-1, effective_uid) != 0) err(1, "setreuid failed"); \
 	PRIV_END \
 }
 #endif



More information about the Midnightbsd-cvs mailing list