From owner-freebsd-standards Sat Dec 29 8:46:31 2001 Delivered-To: freebsd-standards@freebsd.org Received: from rwcrmhc51.attbi.com (rwcrmhc51.attbi.com [204.127.198.38]) by hub.freebsd.org (Postfix) with ESMTP id 862CD37B41F; Sat, 29 Dec 2001 08:46:23 -0800 (PST) Received: from attbi.com ([12.237.33.57]) by rwcrmhc51.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20011229164622.OYUX1920.rwcrmhc51.attbi.com@attbi.com>; Sat, 29 Dec 2001 16:46:22 +0000 Message-ID: <3C2DF35D.1F54BBC3@attbi.com> Date: Sat, 29 Dec 2001 10:46:21 -0600 From: Joe Halpin X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: Mike Barcroft Cc: "standards@FreeBSD.ORG" Subject: Re: at utility changes References: <3C200BBA.9D26ED93@attbi.com> <20011228031537.B99161@espresso.q9media.com> Content-Type: multipart/mixed; boundary="------------7020D9F4C691EBEDED4EE04C" Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------7020D9F4C691EBEDED4EE04C Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Here are a new set of changes. I think I got the style more or less right this time, and cloned the stime_arg1() function from touch. Joe --------------7020D9F4C691EBEDED4EE04C Content-Type: text/plain; charset=us-ascii; name="at.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="at.diff" Index: at/at.c =================================================================== RCS file: /home/ncvs/src/usr.bin/at/at.c,v retrieving revision 1.18.2.1 diff -u -r1.18.2.1 at.c --- at/at.c 2001/08/02 00:55:58 1.18.2.1 +++ at/at.c 2001/12/29 16:41:19 @@ -121,6 +121,7 @@ static char *cwdname(void); static void writefile(time_t runtimer, char queue); static void list_jobs(void); +static time_t ttime(const char *arg); /* Signal catching functions */ @@ -588,6 +589,80 @@ } } /* delete_jobs */ +#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; + +static time_t +ttime(const char *arg) +{ + /* + * This is pretty much a copy of stime_arg1() from touch.c. I changed + * the return value and the argument list because it's more convenient + * (IMO) to do everything in one place. - Joe Halpin + */ + struct timeval tv[2]; + time_t now; + struct tm *t; + int yearset; + char *p; + + if (gettimeofday(&tv[0], NULL)) + panic("Cannot get current time"); + + /* Start with the current time. */ + now = tv[0].tv_sec; + if ((t = localtime(&now)) == NULL) + panic("localtime"); + /* [[CC]YY]MMDDhhmm[.SS] */ + if ((p = strchr(arg, '.')) == NULL) + t->tm_sec = 0; /* Seconds defaults to 0. */ + else { + if (strlen(p + 1) != 2) + goto terr; + *p++ = '\0'; + t->tm_sec = ATOI2(p); + } + + yearset = 0; + switch(strlen(arg)) { + case 12: /* CCYYMMDDhhmm */ + t->tm_year = ATOI2(arg); + t->tm_year *= 100; + yearset = 1; + /* FALLTHROUGH */ + case 10: /* YYMMDDhhmm */ + if (yearset) { + yearset = ATOI2(arg); + t->tm_year += yearset; + } else { + yearset = ATOI2(arg); + if (yearset < 69) + t->tm_year = yearset + 2000; + else + t->tm_year = yearset + 1900; + } + t->tm_year -= 1900; /* Convert to UNIX time. */ + /* FALLTHROUGH */ + case 8: /* MMDDhhmm */ + t->tm_mon = ATOI2(arg); + --t->tm_mon; /* Convert from 01-12 to 00-11 */ + t->tm_mday = ATOI2(arg); + t->tm_hour = ATOI2(arg); + t->tm_min = ATOI2(arg); + break; + default: + goto terr; + } + + t->tm_isdst = -1; /* Figure out DST. */ + tv[0].tv_sec = tv[1].tv_sec = mktime(t); + if (tv[0].tv_sec != -1) + return tv[0].tv_sec; + else + terr: + panic("out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); + return -1; /* get rid of "control reaches end of non-void function" msg */ +} + int main(int argc, char **argv) { @@ -598,10 +673,12 @@ enum { ATQ, ATRM, AT, BATCH, CAT }; /* what program we want to run */ int program = AT; /* our default program */ - char *options = "q:f:mvldbVc"; /* default options for at */ + char *options = "q:f:t:rmvldbVc"; /* default options for at */ int disp_version = 0; time_t timer; + timer = -1; + RELINQUISH_PRIVS /* Eat any leading paths @@ -655,6 +732,9 @@ break; case 'd': + warnx("-d is deprecated; you should use -r in the future"); + /* fall through to 'r' */ + case 'r': if (program != AT) usage(); @@ -662,6 +742,14 @@ options = "V"; break; + case 't': + if (program != AT) + usage(); + + options = "V"; + timer = ttime(optarg); + break; + case 'l': if (program != AT) usage(); @@ -696,7 +784,7 @@ if (disp_version) fprintf(stderr, "at version " VERSION "\n" - "Bug reports to: ig25@rz.uni-karlsruhe.de (Thomas Koenig)\n"); + "Bug reports to: ig25@rz.uni-karlsruhe.de (Thomas Koenig)\n"); /* select our program */ @@ -723,7 +811,14 @@ break; case AT: - timer = parsetime(argc, argv); + + /* + * If timer is > -1, then the user gave the time with -t. + * In that case, it's already been set. If not, set it now. + */ + if (timer == -1) + timer = parsetime(argc, argv); + if (atverify) { struct tm *tm = localtime(&timer); Index: at/at.man =================================================================== RCS file: /home/ncvs/src/usr.bin/at/at.man,v retrieving revision 1.13.2.7 diff -u -r1.13.2.7 at.man --- at/at.man 2001/12/14 15:53:29 1.13.2.7 +++ at/at.man 2001/12/29 16:41:19 @@ -115,6 +115,8 @@ and to run a job at 1am tomorrow, you would do .Nm at Ar 1am tomorrow . .Pp +You may also use the POSIX time format (see -t argument) +.Pp For both .Nm and @@ -214,7 +216,7 @@ .Nm atq . .It Fl d Is an alias for -.Nm atrm . +.Nm atrm (this option is deprecated; use -r instead) . .It Fl b Is an alias for .Nm batch . @@ -225,6 +227,12 @@ shows the time the job will be executed. .It Fl c Cat the jobs listed on the command line to standard output. +.It Fl r +Remove specified job(s). +.It Fl t +Give the job time using the POSIX time format, which is described in the +touch(1) man page. +Note that giving a date past 2038 may not work on 32-bit systems. .El .Sh FILES .Bl -tag -width _ATJOB_DIR/_LOCKFILE -compact @@ -271,4 +279,6 @@ At was mostly written by .An Thomas Koenig Aq ig25@rz.uni-karlsruhe.de . The time parsing routines are by -.An David Parsons Aq orc@pell.chi.il.us . +.An David Parsons Aq orc@pell.chi.il.us , +with minor enhancement by +.An Joe Halpin Aq joe.halpin@attbi.com . --------------7020D9F4C691EBEDED4EE04C-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message