/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
*
* Synopsis: atq [ -c ] [ -n ] [ name ... ]
*
*
* Print the queue of files waiting to be executed. These files
* were created by using the "at" command and are located in the
* directory defined by ATDIR.
*/
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <pwd.h>
#include <ctype.h>
#include <unistd.h>
#include <locale.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "cron.h"
extern char *errmsg();
extern char *strchr();
/*
* Months of the year
*/
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec",
};
static void atabortperror(char *msg);
static void usage(void);
static void printjobname(char *file);
static void printrank(int n);
int
{
int i;
/* queue */
extern int creation(); /* sort jobs by date of creation */
extern int execution(); /* sort jobs by date of execution */
int filewanted(); /* should file be included in queue? */
int countfiles(); /* count the number of files in queue */
/* for a given person */
int badarg = 0;
char *c;
/*
* Interpret command line flags if they exist.
*/
(*argv)++;
while (**argv) {
switch (*(*argv)++) {
case 'c' : cflag++;
break;
case 'n' : nflag++;
break;
default : usage();
}
}
}
/*
* If a certain name (or names) is requested, set a pointer to the
* beginning of the list.
*/
if (argc > 0) {
++namewanted;
atabortperror("can't allocate list of users");
for (i = 0; i < argc; i++) {
"atq: No such user %s\n", argv[i]);
exit(1);
}
argnum++;
}
else
badarg++;
}
if (badarg)
if (argnum)
printf("Printing queue information only "
else {
printf("atq: Non-priviledged user cannot "
"request information regarding other "
"users\n");
exit(1);
}
/* no argument specified and the invoker is not root */
++namewanted;
argnum = 1;
atabortperror("can't allocate list of users");
}
/*
* Move to the spooling area and scan the directory, placing the
* files in the queue structure. The queue comes back sorted by
* execution time or creation time.
*/
/*
* Either print a message stating:
*
* 1) that the spooling area is empty.
* 2) the number of jobs in the spooling area.
* 3) the number of jobs in the spooling area belonging to
* a certain person.
* 4) that the person requested doesn't have any files in the
* spooling area.
*
* or send the queue off to "printqueue" for printing.
*
* This whole process might seem a bit elaborate, but it's worthwhile
* to print some informative messages for the user.
*
*/
if ((numentries == 0) && (!nflag)) {
printf("no files in queue.\n");
exit(0);
}
if (nflag) {
exit(0);
}
if (argnum == 1)
else c = *argv;
c : "specified users");
exit(0);
}
return (0);
}
/*
* Count the number of jobs in the spooling area owned by a certain person(s).
*/
int
{
int i, j; /* for loop indices */
/* certain person(s) */
/*
* For each file in the queue, see if the user(s) own the file. We
* have to use "entryfound" (rather than simply incrementing "numfiles")
* so that if a person's name appears twice on the command line we
*/
for (i = 0; i < numentries; i++) {
continue;
}
entryfound = 0;
for (j = 0; j < nuids; j++) {
++entryfound;
++ptr;
}
if (entryfound)
++numfiles;
}
return (numfiles);
}
/*
* Print the queue. If only jobs belonging to a certain person(s) are requested,
* only print jobs that belong to that person(s).
*/
static void
{
int i, j; /* for loop indices */
char *getname();
/*
* Print the header for the queue.
*/
printf(" Rank Execution Date Owner Job "
"Queue Job Name\n");
/*
* Print the queue. If a certain name(s) was requested, print only jobs
* belonging to that person(s), otherwise print the entire queue.
* Once again, we have to use "entryfound" (rather than simply
* comparing each command line argument) so that if a person's name
*
*
* "printrank", "printdate", and "printjobname" all take existing
* data and display it in a friendly manner.
*
*/
lastqueue = '\0';
for (i = 0; i < numentries; i++) {
continue;
}
rank = 1;
}
if (namewanted) {
entryfound = 0;
for (j = 0; j < nuids; j++) {
++entryfound;
++ptr;
}
if (!entryfound)
continue;
}
}
++ptr;
}
/*
* such account name exists.
*/
{
return ((uid_t)-1);
}
/*
*/
char *
{
return ("???");
}
/*
* Print the rank of a job. (I've got to admit it, I stole it from "lpq")
*/
static void
printrank(int n)
{
static char *r[] = {
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
};
if ((n/10) == 1)
else
}
/*
* Print the date that a job is to be executed. This takes some manipulation
* of the file name.
*/
static void
{
/*
* Convert the file name to a date.
*/
/* years since 1900 + base century 1900 */
/*
* Format the execution date of a job.
*/
/*
* Print the date the job will be executed.
*/
}
/*
* Print a job name. If the old "at" has been used to create the spoolfile,
* the three line header that the new version of "at" puts in the spoolfile.
* Thus, we just print "???".
*/
static void
{
/*
* Open the job file and grab the third line.
*/
printf(" ");
return;
}
/*
* Skip over the first and second lines.
*/
/*
* Now get the job name.
*/
return;
}
/*
* Put a pointer at the begining of the line and remove the basename
* from the job file.
*/
++ptr;
else
else
}
/*
* Sort files by queue, time of creation, and sequence. (used by "scandir")
*/
int
{
int i;
return (0);
return (0);
p1++;
p2++;
return (i);
return (0);
return (0);
return (-1);
return (1);
p1++;
p2++;
}
/*
* Sort files by queue, time of execution, and sequence. (used by "scandir")
*/
int
{
int i;
return (1);
return (1);
p1++;
p2++;
return (i);
return (-1);
return (1);
p1++;
p2++;
}
/*
* Print usage info and exit.
*/
static void
usage(void)
{
exit(1);
}
static void
{
}
static void
{
}
static void
{
exit(1);
}
static void
{
exit(1);
}