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
This commit is contained in:
Tim J. Robbins 2002-05-16 00:47:14 +00:00
parent 16b9af9990
commit dfd339a02c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=96701
3 changed files with 62 additions and 6 deletions

View File

@ -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:

View File

@ -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

View File

@ -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");