summaryrefslogtreecommitdiff
path: root/usr.bin/at
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-05-11 23:02:34 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-05-11 23:02:34 +0000
commit2ddcfdb41a7c87e9c0e9d3e2b4b1e8c474e2d44d (patch)
treedbb76aabc33f6e77682bf2e968ae55f6fc0f8502 /usr.bin/at
parent1b792dd4850aa9188aa8db53b3a941c8c48c0246 (diff)
Add POSIX -r and -t flags from FreeBSD. The old -d option is now
deprecated and no longer documented. Also, use __progname instead of examining argv and clean up a few minor warnings.
Diffstat (limited to 'usr.bin/at')
-rw-r--r--usr.bin/at/at.168
-rw-r--r--usr.bin/at/at.c128
-rw-r--r--usr.bin/at/at.h4
-rw-r--r--usr.bin/at/panic.c19
-rw-r--r--usr.bin/at/panic.h10
5 files changed, 172 insertions, 57 deletions
diff --git a/usr.bin/at/at.1 b/usr.bin/at/at.1
index 22b0c6429ea..a7f4eb864d5 100644
--- a/usr.bin/at/at.1
+++ b/usr.bin/at/at.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: at.1,v 1.21 2002/05/11 22:14:48 millert Exp $
+.\" $OpenBSD: at.1,v 1.22 2002/05/11 23:02:33 millert Exp $
.\" $FreeBSD: at.man,v 1.6 1997/02/22 19:54:05 peter Exp $
.Dd April 12, 1995
.Dt AT 1
@@ -11,7 +11,12 @@
.Nd queue, examine or delete jobs for later execution
.Sh SYNOPSIS
.Nm at
-.Op Fl bdlmv
+.Op Fl blmrv
+.Op Fl f Ar file
+.Op Fl q Ar queue
+.Fl t Ar [[CC]YY]MMDDhhmm[.SS]
+.Nm at
+.Op Fl blmrv
.Op Fl f Ar file
.Op Fl q Ar queue
.Ar time
@@ -59,9 +64,6 @@ An alias for
.Nm batch .
.It Fl c
Prints the jobs listed on the command line to standard output.
-.It Fl d
-An alias for
-.Nm atrm .
.It Fl f Ar file
Reads the job from
.Ar file
@@ -97,6 +99,41 @@ is treated as if it had been submitted to batch at that time.
If
.Nm atq
is given a specific queue, it will only show jobs pending in that queue.
+.It Fl r
+An alias for
+.Nm atrm .
+.It Fl t
+Specify the job time using the \*[Px] time format.
+The argument should be in the form
+.Ar [[CC]YY]MMDDhhmm[.SS]
+where each pair of letters represents the following:
+.Pp
+.Bl -tag -width indent -compact -offset indent
+.It Ar CC
+The first two digits of the year (the century).
+.It Ar YY
+The second two digits of the year.
+.It Ar MM
+The month of the year, from 1 to 12.
+.It Ar DD
+the day of the month, from 1 to 31.
+.It Ar hh
+The hour of the day, from 0 to 23.
+.It Ar mm
+The minute of the hour, from 0 to 59.
+.It Ar SS
+The second of the minute, from 0 to 61.
+.El
+.Pp
+If the
+.Ar CC
+and
+.Ar YY
+letter pairs are not specified, the values default to the current
+year.
+If the
+.Ar SS
+letter pair is not specified, the value defaults to 0.
.It Fl v
For
.Nm atq ,
@@ -131,10 +168,13 @@ by giving a date in the form
with an optional
.Ar year ,
or giving a date of the form
-.Ar MMDDYY ,
-.Ar MM/DD/YY
+.Ar DD.MM.CCYY ,
+.Ar DD.MM.YY ,
+.Ar MM/DD/CCYY ,
+.Ar MM/DD/YY ,
+.Ar MMDDCCYY ,
or
-.Ar DD.MM.YY .
+.Ar MMDDYY .
.Pp
The year may be given as two or four digits.
If the year is given as two digits, it is taken to occur as soon as
@@ -167,14 +207,20 @@ To run a job at 10:00am on July 31, you would do
To run a job at 1am tomorrow, you would do
.Ic at 1am tomorrow .
.Pp
+The
+.Nm at
+utility also supports the \*[Px] time format (see the
+.Fl t
+option).
+.Pp
For both
.Nm at
and
.Nm batch ,
-commands are read from standard input or the file specified
+commands are read from standard input (or the file specified
with the
.Fl f
-option and executed.
+option) and executed.
The working directory, the environment (except for the variables
.Ev TERM ,
.Ev TERMCAP ,
@@ -193,7 +239,7 @@ command invoked from a
shell will retain the current user ID.
The user will be mailed standard error and standard output from his
commands, if any.
-Mail will be sent using the command
+Mail will be sent using
.Xr sendmail 8 .
If
.Nm at
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c
index d232097df1b..f5f3db26dfd 100644
--- a/usr.bin/at/at.c
+++ b/usr.bin/at/at.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: at.c,v 1.24 2002/05/11 21:56:54 millert Exp $ */
+/* $OpenBSD: at.c,v 1.25 2002/05/11 23:02:33 millert Exp $ */
/* $NetBSD: at.c,v 1.4 1995/03/25 18:13:31 glass Exp $ */
/*
@@ -30,10 +30,9 @@
*/
/* System Headers */
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
-#include <sys/wait.h>
+#include <sys/time.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
@@ -74,7 +73,7 @@ enum { ATQ, ATRM, AT, BATCH, CAT }; /* what program we want to run */
/* File scope variables */
#ifndef lint
-static char rcsid[] = "$OpenBSD: at.c,v 1.24 2002/05/11 21:56:54 millert Exp $";
+static char rcsid[] = "$OpenBSD: at.c,v 1.25 2002/05/11 23:02:33 millert Exp $";
#endif
char *no_export[] =
@@ -87,7 +86,6 @@ static int send_mail = 0;
extern char **environ;
int fcreated;
-char *namep;
char atfile[FILENAME_MAX];
char *atinput = (char *)0; /* where to get input from */
@@ -101,6 +99,7 @@ static void alarmc(int);
static char *cwdname(void);
static void writefile(time_t, char);
static void list_jobs(void);
+static time_t ttime(const char *);
/* Signal catching functions */
@@ -125,7 +124,7 @@ alarmc(signo)
char buf[1024];
/* Time out after some seconds. */
- strlcpy(buf, namep, sizeof(buf));
+ strlcpy(buf, __progname, sizeof(buf));
strlcat(buf, ": File locking timed out\n", sizeof(buf));
write(STDERR_FILENO, buf, strlen(buf));
if (fcreated) {
@@ -457,14 +456,14 @@ list_jobs()
runtimer = 60 * (time_t) ctm;
runtime = *localtime(&runtimer);
- strftime(timestr, TIMESIZE, "%X %x", &runtime);
+ strftime(timestr, TIMESIZE, "%+", &runtime);
if (first) {
- (void)printf("Date\t\t\tOwner\tQueue\tJob#\n");
+ (void)printf("Date\t\t\t\tOwner\t\tQueue\tJob#\n");
first = 0;
}
pw = getpwuid(buf.st_uid);
- (void)printf("%s\t%s\t%c%s\t%d\n",
+ (void)printf("%s\t%-16s%c%s\t%d\n",
timestr,
pw ? pw->pw_name : "???",
queue,
@@ -556,6 +555,77 @@ process_jobs(argc, argv, what)
}
} /* delete_jobs */
+#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0'))
+
+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);
+ t->tm_year = yearset + 2000;
+ }
+ 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]");
+}
+
/* Global functions */
int
@@ -566,33 +636,21 @@ main(argc, argv)
int c;
char queue = DEFAULT_AT_QUEUE;
char queue_set = 0;
- char *pgm;
-
- enum {
- ATQ, ATRM, AT, BATCH, CAT
- }; /* what program we want to run */
- int program = AT; /* our default program */
- char *options = "q:f:mvldbc"; /* default options for at */
+ int program = AT; /* default program mode */
+ char *options = "q:f:t:bcdlmrv"; /* default options for at */
time_t timer;
+ int tflag = 0;
RELINQUISH_PRIVS
- /* Eat any leading paths */
- if ((pgm = strrchr(argv[0], '/')) == NULL)
- pgm = argv[0];
- else
- pgm++;
-
- namep = pgm;
-
/* find out what this program is supposed to do */
- if (strcmp(pgm, "atq") == 0) {
+ if (strcmp(__progname, "atq") == 0) {
program = ATQ;
options = "q:v";
- } else if (strcmp(pgm, "atrm") == 0) {
+ } else if (strcmp(__progname, "atrm") == 0) {
program = ATRM;
options = "";
- } else if (strcmp(pgm, "batch") == 0) {
+ } else if (strcmp(__progname, "batch") == 0) {
program = BATCH;
options = "f:q:mv";
}
@@ -624,7 +682,8 @@ main(argc, argv)
queue_set = 1;
break;
- case 'd':
+ case 'd': /* for backwards compatibility */
+ case 'r':
if (program != AT)
usage();
@@ -632,6 +691,13 @@ main(argc, argv)
options = "";
break;
+ case 't':
+ if (program != AT)
+ usage();
+ tflag++;
+ timer = ttime(optarg);
+ break;
+
case 'l':
if (program != AT)
usage();
@@ -661,7 +727,7 @@ main(argc, argv)
if (!check_permission())
errx(EXIT_FAILURE, "You do not have permission to use %s.",
- namep);
+ __progname);
/* select our program */
switch (program) {
@@ -679,7 +745,9 @@ main(argc, argv)
break;
case AT:
- timer = parsetime(argc, argv);
+ /* Time may have been specified via the -t flag. */
+ if (!tflag)
+ timer = parsetime(argc, argv);
if (atverify) {
struct tm *tm = localtime(&timer);
(void)fprintf(stderr, "%s\n", asctime(tm));
diff --git a/usr.bin/at/at.h b/usr.bin/at/at.h
index e752b642a57..057fd15e7a9 100644
--- a/usr.bin/at/at.h
+++ b/usr.bin/at/at.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: at.h,v 1.3 1997/03/01 23:40:09 millert Exp $ */
+/* $OpenBSD: at.h,v 1.4 2002/05/11 23:02:33 millert Exp $ */
/* $NetBSD: at.h,v 1.2 1995/03/25 18:13:32 glass Exp $ */
/*
@@ -27,7 +27,7 @@
*/
extern int fcreated;
-extern char *namep;
+extern char *__progname;
extern char atfile[];
extern char atverify;
diff --git a/usr.bin/at/panic.c b/usr.bin/at/panic.c
index fb3e90026c8..87f55e90977 100644
--- a/usr.bin/at/panic.c
+++ b/usr.bin/at/panic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: panic.c,v 1.6 2002/05/11 21:56:54 millert Exp $ */
+/* $OpenBSD: panic.c,v 1.7 2002/05/11 23:02:33 millert Exp $ */
/* $NetBSD: panic.c,v 1.2 1995/03/25 18:13:33 glass Exp $ */
/*
@@ -42,21 +42,21 @@
/* File scope variables */
#ifndef lint
-static char rcsid[] = "$OpenBSD: panic.c,v 1.6 2002/05/11 21:56:54 millert Exp $";
+static char rcsid[] = "$OpenBSD: panic.c,v 1.7 2002/05/11 23:02:33 millert Exp $";
#endif
/* External variables */
/* Global functions */
-void
+__dead void
panic(a)
char *a;
{
/*
* Something fatal has happened, print error message and exit.
*/
- (void)fprintf(stderr, "%s: %s\n", namep, a);
+ (void)fprintf(stderr, "%s: %s\n", __progname, a);
if (fcreated) {
PRIV_START
unlink(atfile);
@@ -66,7 +66,7 @@ panic(a)
exit(EXIT_FAILURE);
}
-void
+__dead void
perr(a)
char *a;
{
@@ -83,7 +83,7 @@ perr(a)
exit(EXIT_FAILURE);
}
-void
+__dead void
perr2(a, b)
char *a, *b;
{
@@ -91,15 +91,16 @@ perr2(a, b)
perr(b);
}
-void
+__dead void
usage(void)
{
/* Print usage and exit. */
(void)fprintf(stderr,
- "Usage: at [-q queue] [-f file] [-mldbv] time\n"
+ "Usage: at [-blmrv] [-f file] [-q queue] -t [[CC]YY]MMDDhhmm[.SS]\n"
+ " at [-blmrv] [-f file] [-q queue] time\n"
" at -c job [job ...]\n"
" atq [-q queue] [-v]\n"
" atrm job [job ...]\n"
- " batch [-q queue] [-f file] [-mv]\n");
+ " batch [-mv] [-f file] [-q queue]\n");
exit(EXIT_FAILURE);
}
diff --git a/usr.bin/at/panic.h b/usr.bin/at/panic.h
index f6415dc45a4..3126fd9c06f 100644
--- a/usr.bin/at/panic.h
+++ b/usr.bin/at/panic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: panic.h,v 1.4 2002/02/16 21:27:44 millert Exp $ */
+/* $OpenBSD: panic.h,v 1.5 2002/05/11 23:02:33 millert Exp $ */
/* $NetBSD: panic.h,v 1.2 1995/03/25 18:13:35 glass Exp $ */
/*
@@ -26,7 +26,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-void panic(char *);
-void perr(char *);
-void perr2(char *, char *);
-void usage(void);
+__dead void panic(char *);
+__dead void perr(char *);
+__dead void perr2(char *, char *);
+__dead void usage(void);