-/*
+/*
* at.c : Put file into atrun queue
* Copyright (C) 1993, 1994 Thomas Koenig
*
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/at/at.c,v 1.29 2002/07/22 11:32:16 robert Exp $");
+__FBSDID("$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/usr.bin/at/at.c,v 1.34 2011/11/06 20:30:21 ed Exp $");
#define _USE_BSD 1
/* Macros */
-#ifndef ATJOB_DIR
+#ifndef ATJOB_DIR
#define ATJOB_DIR _PATH_ATJOBS
#endif
/* File scope variables */
-const char *no_export[] =
-{
+static const char *no_export[] = {
"TERM", "TERMCAP", "DISPLAY", "_"
-} ;
+};
static int send_mail = 0;
+static char *atinput = NULL; /* where to get input from */
+static char atqueue = 0; /* which queue to examine for jobs (atq) */
/* External variables */
extern char **environ;
int fcreated;
char atfile[] = ATJOB_DIR "12345678901234";
-
-char *atinput = (char*)0; /* where to get input from */
-char atqueue = 0; /* which queue to examine for jobs (atq) */
char atverify = 0; /* verify time instead of queuing job */
char *namep;
int posixly_correct; /* Behave as per POSIX */
/* Signal catching functions */
-static void sigc(int signo __unused)
+static void
+sigc(int signo __unused)
{
-/* If the user presses ^C, remove the spool file and exit
+/* If the user presses ^C, remove the spool file and exit
*/
if (fcreated)
{
_exit(EXIT_FAILURE);
}
-static void alarmc(int signo __unused)
+static void
+alarmc(int signo __unused)
{
char buf[1024];
/* Local functions */
-static char *cwdname(void)
+static char *
+cwdname(void)
{
/* Read in the current directory; the name will be overwritten on
* subsequent calls.
if (getcwd(ptr, size-1) != NULL)
return ptr;
-
+
if (errno != ERANGE)
perr("cannot get directory");
-
+
free (ptr);
size += SIZE;
if ((ptr = malloc(size)) == NULL)
}
static long
-nextjob()
+nextjob(void)
{
long jobno;
FILE *fid;
- if ((fid = fopen(ATJOB_DIR ".SEQ", "r+")) != (FILE*)0) {
+ if ((fid = fopen(ATJOB_DIR ".SEQ", "r+")) != NULL) {
if (fscanf(fid, "%5lx", &jobno) == 1) {
rewind(fid);
jobno = (1+jobno) % 0xfffff; /* 2^20 jobs enough? */
fclose(fid);
return jobno;
}
- else if ((fid = fopen(ATJOB_DIR ".SEQ", "w")) != (FILE*)0) {
+ else if ((fid = fopen(ATJOB_DIR ".SEQ", "w")) != NULL) {
fprintf(fid, "%05lx\n", jobno = 1);
fclose(fid);
return 1;
mode_t cmask;
struct flock lock;
char * oldpwd_str = NULL;
-
+
#ifdef __FreeBSD__
(void) setlocale(LC_TIME, "");
#endif
if ((jobno = nextjob()) == EOF)
perr("cannot generate job number");
- sprintf(ppos, "%c%5lx%8lx", queue,
+ sprintf(ppos, "%c%5lx%8lx", queue,
jobno, (unsigned long) (runtimer/60));
for(ap=ppos; *ap != '\0'; ap ++)
*/
cmask = umask(S_IRUSR | S_IWUSR | S_IXUSR);
if ((fdes = creat(atfile, O_WRONLY)) == -1)
- perr("cannot create atjob file");
+ perr("cannot create atjob file");
if ((fd2 = dup(fdes)) <0)
perr("error in dup() of job file");
REDUCE_PRIV(DAEMON_UID, DAEMON_GID)
- /* We've successfully created the file; let's set the flag so it
+ /* We've successfully created the file; let's set the flag so it
* gets removed in case of an interrupt or error.
*/
fcreated = 1;
if (mailname == NULL)
mailname = getenv("LOGNAME");
- if ((mailname == NULL) || (mailname[0] == '\0')
+ if ((mailname == NULL) || (mailname[0] == '\0')
|| (strlen(mailname) >= MAXLOGNAME) || (getpwnam(mailname)==NULL))
{
pass_entry = getpwuid(real_uid);
for (i=0; i<sizeof(no_export)/sizeof(no_export[0]); i++)
{
export = export
- && (strncmp(*atenv, no_export[i],
+ && (strncmp(*atenv, no_export[i],
(size_t) (eqp-*atenv)) != 0);
}
}
fputs("; export ", fp);
fwrite(*atenv, sizeof(char), eqp-*atenv -1, fp);
fputc('\n', fp);
-
+
}
- }
+ }
/* Cd to the directory at the time and write out all the
* commands the user supplies from stdin.
*/
{
if (*ap != '/' && !isalnum(*ap))
fputc('\\', fp);
-
+
fputc(*ap, fp);
}
}
fprintf(fp, "\n");
if (ferror(fp))
panic("output error");
-
+
if (ferror(stdin))
panic("input error");
fprintf(stderr, "Job %ld will be executed using /bin/sh\n", jobno);
}
-static int
+static int
in_job_list(long job, long *joblist, int len)
{
int i;
if (stat(name, &buf) != 0)
perr("cannot stat in " ATJOB_DIR);
-
+
/* See it's a regular file and has its x bit turned on and
* is the user's
*/
else {
struct passwd *pw = getpwuid(buf.st_uid);
- printf("%s\t%s\t%c%s\t%s\n",
- timestr,
- pw ? pw->pw_name : "???",
- queue,
- (S_IXUSR & buf.st_mode) ? "":"(done)",
+ printf("%s\t%s\t%c%s\t%s\n",
+ timestr,
+ pw ? pw->pw_name : "???",
+ queue,
+ (S_IXUSR & buf.st_mode) ? "":"(done)",
name);
}
}
static void
list_jobs(long *joblist, int len)
{
- /* List all a user's jobs in the queue, by looping through ATJOB_DIR,
+ /* List all a user's jobs in the queue, by looping through ATJOB_DIR,
* or everybody's if we are root
*/
DIR *spool;
struct dirent *dirent;
int first=1;
-
+
#ifdef __FreeBSD__
(void) setlocale(LC_TIME, "");
#endif
if ((spool = opendir(".")) == NULL)
perr("cannot open " ATJOB_DIR);
- /* Loop over every file in the directory
+ /* Loop over every file in the directory
*/
while((dirent = readdir(spool)) != NULL) {
list_one_job(dirent->d_name, joblist, len, &first);
PRIV_END
- /* Loop over every file in the directory
+ /* Loop over every file in the directory
*/
while((dirent = readdir(spool)) != NULL) {
while((ch = getc(fp)) != EOF) {
putchar(ch);
}
+ fclose(fp);
}
break;
}
}
}
+ closedir(spool);
} /* process_jobs */
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
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)
*p++ = '\0';
t->tm_sec = ATOI2(p);
}
-
+
yearset = 0;
switch(strlen(arg)) {
case 12: /* CCYYMMDDhhmm */
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)
timer = -1;
RELINQUISH_PRIVS
- if (argv[0] == NULL)
+ if (argv[0] == NULL)
usage();
/* Eat any leading paths
*/
case 'f':
atinput = optarg;
break;
-
+
case 'q': /* specify queue */
if (strlen(optarg) > 1)
usage();
case AT:
/*
* If timer is > -1, then the user gave the time with -t. In that
- * case, it's already been set. If not, set it now.
+ * case, it's already been set. If not, set it now.
*/
- if (timer == -1)
+ if (timer == -1)
timer = parsetime(argc, argv);
if (atverify)
timer = parsetime(argc, argv);
else
timer = time(NULL);
-
+
if (atverify)
{
struct tm *tm = localtime(&timer);