version 1.29, 2002/05/14 18:05:39 |
version 1.30, 2002/07/15 19:13:29 |
|
|
*/ |
*/ |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
|
#include <sys/socket.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/time.h> |
#include <sys/time.h> |
|
#include <sys/un.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <dirent.h> |
#include <dirent.h> |
#include <err.h> |
#include <err.h> |
|
|
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <utime.h> |
#include <utmp.h> |
#include <utmp.h> |
|
|
#if (MAXLOGNAME-1) > UT_NAMESIZE |
#if (MAXLOGNAME-1) > UT_NAMESIZE |
|
|
static void alarmc(int); |
static void alarmc(int); |
static void writefile(time_t, char); |
static void writefile(time_t, char); |
static void list_jobs(int, char **, int, int); |
static void list_jobs(int, char **, int, int); |
|
static void poke_daemon(void); |
static time_t ttime(const char *); |
static time_t ttime(const char *); |
|
|
static void |
static void |
|
|
if (fpin == NULL) |
if (fpin == NULL) |
perr("Cannot open input file"); |
perr("Cannot open input file"); |
} |
} |
(void)fprintf(fp, "#!/bin/sh\n# atrun uid=%u gid=%u\n# mail %*s %d\n", |
(void)fprintf(fp, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %*s %d\n", |
real_uid, real_gid, LOGNAMESIZE, mailname, send_mail); |
(long)real_uid, (long)real_gid, LOGNAMESIZE, mailname, send_mail); |
|
|
/* Write out the umask at the time of invocation */ |
/* Write out the umask at the time of invocation */ |
(void)fprintf(fp, "umask %o\n", cmask); |
(void)fprintf(fp, "umask %o\n", cmask); |
|
|
|
|
(void)close(fd2); |
(void)close(fd2); |
|
|
|
/* Poke cron so it knows to reload the at spool. */ |
|
poke_daemon(); |
|
|
runtime = *localtime(&runtimer); |
runtime = *localtime(&runtimer); |
strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime); |
strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime); |
(void)fprintf(stderr, "commands will be executed using %s\n", shell); |
(void)fprintf(stderr, "commands will be executed using %s\n", shell); |
|
|
FILE *fp; |
FILE *fp; |
DIR *spool; |
DIR *spool; |
int job_matches, jobs_len, uids_len; |
int job_matches, jobs_len, uids_len; |
int error, i, ch; |
int error, i, ch, changed; |
|
|
PRIV_START; |
PRIV_START; |
|
|
|
|
} |
} |
|
|
/* Loop over every file in the directory */ |
/* Loop over every file in the directory */ |
|
changed = 0; |
while ((dirent = readdir(spool)) != NULL) { |
while ((dirent = readdir(spool)) != NULL) { |
|
|
PRIV_START; |
PRIV_START; |
|
|
|
|
if (!interactive || |
if (!interactive || |
(interactive && rmok(runtimer))) { |
(interactive && rmok(runtimer))) { |
if (unlink(dirent->d_name) != 0) |
if (unlink(dirent->d_name) == 0) |
|
changed = 1; |
|
else |
perr(dirent->d_name); |
perr(dirent->d_name); |
if (!force && !interactive) |
if (!force && !interactive) |
fprintf(stderr, |
fprintf(stderr, |
|
|
free(jobs); |
free(jobs); |
free(uids); |
free(uids); |
|
|
|
/* If we modied the spool, poke cron so it knows to reload. */ |
|
if (changed) |
|
poke_daemon(); |
|
|
return (error); |
return (error); |
} |
} |
|
|
|
|
terr: |
terr: |
panic("out of range or illegal time specification: " |
panic("out of range or illegal time specification: " |
"[[CC]YY]MMDDhhmm[.SS]"); |
"[[CC]YY]MMDDhhmm[.SS]"); |
|
} |
|
|
|
#define RELOAD_AT 0x4 /* XXX - from cron's macros.h */ |
|
|
|
/* XXX - share with crontab */ |
|
static void |
|
poke_daemon() { |
|
int sock, flags; |
|
unsigned char poke; |
|
struct sockaddr_un sun; |
|
|
|
PRIV_START; |
|
|
|
if (utime(_PATH_ATJOBS, NULL) < 0) { |
|
warn("can't update mtime on %s", _PATH_ATJOBS); |
|
PRIV_END; |
|
return; |
|
} |
|
|
|
/* Failure to poke the daemon socket is not a fatal error. */ |
|
(void) signal(SIGPIPE, SIG_IGN); |
|
strlcpy(sun.sun_path, CRONDIR "/" SPOOL_DIR "/" CRONSOCK, |
|
sizeof(sun.sun_path)); |
|
sun.sun_family = AF_UNIX; |
|
sun.sun_len = strlen(sun.sun_path); |
|
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 && |
|
connect(sock, (struct sockaddr *)&sun, sizeof(sun)) == 0) { |
|
poke = RELOAD_AT; |
|
write(sock, &poke, 1); |
|
close(sock); |
|
} else |
|
fprintf(stderr, "Warning, cron does not appear to be running.\n"); |
|
(void) signal(SIGPIPE, SIG_DFL); |
|
|
|
PRIV_END; |
} |
} |
|
|
int |
int |