From dfd339a02cf20a19206137a13fb8785d95afd8e9 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Thu, 16 May 2002 00:47:14 +0000 Subject: [PATCH] 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 Reviewed by: mike --- usr.bin/at/at.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- usr.bin/at/at.man | 9 ++++++-- usr.bin/at/panic.c | 2 ++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c index fec2c62a4b83..6756839b2f20 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 @@ ttime(const char *arg) "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 aa19b14628c4..79543222beed 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 34c527a9e2e4..ef5265b4c1d2 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");