summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-05-16 00:47:14 +0000
committertjr <tjr@FreeBSD.org>2002-05-16 00:47:14 +0000
commit24cc1f8e45f072238cecb4ba927e38f90d1627f5 (patch)
tree7219d40d120bfb31a4ecb353fbb3c01a7a6566c4
parentb005f02fe7b6d76737de49db8ffce8e82656935c (diff)
downloadFreeBSD-src-24cc1f8e45f072238cecb4ba927e38f90d1627f5.zip
FreeBSD-src-24cc1f8e45f072238cecb4ba927e38f90d1627f5.tar.gz
Add the SUSv3 -l option to at. This is an alias for atq. Allow job ids
to be specified on the command line for which information should be reported. Submitted by: Joe Halpin <joe.halpin@attbi.com> Reviewed by: mike
-rw-r--r--usr.bin/at/at.c57
-rw-r--r--usr.bin/at/at.man9
-rw-r--r--usr.bin/at/panic.c2
3 files changed, 62 insertions, 6 deletions
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c
index fec2c62..6756839 100644
--- a/usr.bin/at/at.c
+++ b/usr.bin/at/at.c
@@ -120,9 +120,11 @@ static void sigc(int signo);
static void alarmc(int signo);
static char *cwdname(void);
static void writefile(time_t runtimer, char queue);
-static void list_jobs(void);
+static void list_jobs(long *, int);
static long nextjob(void);
static time_t ttime(const char *arg);
+static int in_job_list(long, long *, int);
+static long *get_job_list(int, char *[], int *);
/* Signal catching functions */
@@ -445,8 +447,20 @@ writefile(time_t runtimer, char queue)
fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno);
}
+static int
+in_job_list(long job, long *joblist, int len)
+{
+ int i;
+
+ for (i = 0; i < len; i++)
+ if (job == joblist[i])
+ return 1;
+
+ return 0;
+}
+
static void
-list_jobs()
+list_jobs(long *joblist, int len)
{
/* List all a user's jobs in the queue, by looping through ATJOB_DIR,
* or everybody's if we are root
@@ -492,6 +506,10 @@ list_jobs()
if(sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm)!=3)
continue;
+ /* If jobs are given, only list those jobs */
+ if (joblist && !in_job_list(jobno, joblist, len))
+ continue;
+
if (atqueue && (queue != atqueue))
continue;
@@ -665,6 +683,31 @@ terr:
"out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]");
}
+static long *
+get_job_list(int argc, char *argv[], int *joblen)
+{
+ int i, len;
+ long *joblist;
+ char *ep;
+
+ joblist = NULL;
+ len = argc;
+ if (len > 0) {
+ if ((joblist = malloc(len * sizeof(*joblist))) == NULL)
+ panic("out of memory");
+
+ for (i = 0; i < argc; i++) {
+ errno = 0;
+ if ((joblist[i] = strtol(argv[i], &ep, 10)) < 0 ||
+ ep == argv[i] || *ep != '\0' || errno)
+ panic("invalid job number");
+ }
+ }
+
+ *joblen = len;
+ return joblist;
+}
+
int
main(int argc, char **argv)
{
@@ -676,7 +719,11 @@ main(int argc, char **argv)
int program = AT; /* our default program */
const char *options = "q:f:t:rmvldbc"; /* default options for at */
time_t timer;
+ long *joblist;
+ int joblen;
+ joblist = NULL;
+ joblen = 0;
timer = -1;
RELINQUISH_PRIVS
@@ -755,7 +802,7 @@ main(int argc, char **argv)
usage();
program = ATQ;
- options = "q:v";
+ options = "q:";
break;
case 'b':
@@ -787,7 +834,9 @@ main(int argc, char **argv)
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
- list_jobs();
+ if (queue_set == 0)
+ joblist = get_job_list(argc - optind, argv + optind, &joblen);
+ list_jobs(joblist, joblen);
break;
case ATRM:
diff --git a/usr.bin/at/at.man b/usr.bin/at/at.man
index aa19b14..7954322 100644
--- a/usr.bin/at/at.man
+++ b/usr.bin/at/at.man
@@ -26,6 +26,11 @@
.Nm at
.Fl c Ar job Op Ar job ...
.Nm at
+.Fl l Op Ar job ...
+.Nm at
+.Fl l
+.Fl q Ar queue
+.Nm at
.Fl r Ar job Op Ar job ...
.Pp
.Nm atq
@@ -235,8 +240,8 @@ Read the job from
.Ar file
rather than standard input.
.It Fl l
-Is an alias for
-.Nm atq .
+With no arguments, list all jobs for the invoking user. If one or more
+job numbers are given, list only those jobs.
.It Fl d
Is an alias for
.Nm atrm
diff --git a/usr.bin/at/panic.c b/usr.bin/at/panic.c
index 34c527a..ef5265b 100644
--- a/usr.bin/at/panic.c
+++ b/usr.bin/at/panic.c
@@ -83,6 +83,8 @@ usage(void)
" at -c job [job ...]\n"
" at [-f file] -t [[CC]YY]MMDDhhmm[.SS]\n"
" at -r job [job ...]\n"
+ " at -l -q queuename\n"
+ " at -l [job ...]\n"
" atq [-q x] [-v]\n"
" atrm job [job ...]\n"
" batch [-f file] [-m]\n");
OpenPOWER on IntegriCloud