diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-07-15 19:13:30 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-07-15 19:13:30 +0000 |
commit | ebcbb2b2d2b68ee6347b5018b9212bbe5fccd946 (patch) | |
tree | e71531558e9d84cf8ad053a7652ab38b58160e8d /usr.bin/at | |
parent | 55ae52781373a832341554a38aebe998ada66dcc (diff) |
Move atrun(8) functionality into cron(8) proper. This fixes the
long-standing annoyance that atrun's granularity is 10 minutes.
Most at jobs run with a 1 minute granularity. Jobs submitted via
"at now" or "batch" will run immediately. Includes a rewritten
cron(8) man page. at(1) will be integrated more closely into
cron at a future date.
Upgrading notes:
the atrun job in root's crontab should be removed.
the /var/at/spool directory is no longer used
Diffstat (limited to 'usr.bin/at')
-rw-r--r-- | usr.bin/at/Makefile | 3 | ||||
-rw-r--r-- | usr.bin/at/at.1 | 7 | ||||
-rw-r--r-- | usr.bin/at/at.c | 62 | ||||
-rw-r--r-- | usr.bin/at/pathnames.h | 46 |
4 files changed, 60 insertions, 58 deletions
diff --git a/usr.bin/at/Makefile b/usr.bin/at/Makefile index 18fbe101830..f5d9c51e621 100644 --- a/usr.bin/at/Makefile +++ b/usr.bin/at/Makefile @@ -1,7 +1,8 @@ -# $OpenBSD: Makefile,v 1.6 2002/05/14 18:05:39 millert Exp $ +# $OpenBSD: Makefile,v 1.7 2002/07/15 19:13:29 millert Exp $ PROG= at SRCS= at.c panic.c parsetime.c perm.c +CFLAGS+=-I${.CURDIR}/../../usr.sbin/cron MAN= at.1 atrm.1 atq.1 LINKS= ${BINDIR}/at ${BINDIR}/atq \ ${BINDIR}/at ${BINDIR}/atrm \ diff --git a/usr.bin/at/at.1 b/usr.bin/at/at.1 index 9c44910d7ef..d3ef0c48997 100644 --- a/usr.bin/at/at.1 +++ b/usr.bin/at/at.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: at.1,v 1.25 2002/05/14 18:05:39 millert Exp $ +.\" $OpenBSD: at.1,v 1.26 2002/07/15 19:13:29 millert Exp $ .\" $FreeBSD: at.man,v 1.6 1997/02/22 19:54:05 peter Exp $ .Dd May 13, 2002 .Dt AT 1 @@ -50,7 +50,7 @@ Executes commands at a specified time. Executes commands when system load levels permit. In other words, when the load average drops below 1.5, or the value specified in the invocation of -.Nm atrun . +.Xr cron 8 . .El .Pp The options are as follows: @@ -280,8 +280,6 @@ This is the default configuration. .Bl -tag -width /var/at/at.allow -compact .It Pa /var/at/jobs directory containing job files -.It Pa /var/at/spool -directory containing output spool files .It Pa /var/at/at.allow allow permission control .It Pa /var/at/at.deny @@ -294,7 +292,6 @@ job sequence file .Xr sh 1 , .Xr touch 1 , .Xr umask 2 , -.Xr atrun 8 , .Xr cron 8 , .Xr sendmail 8 .Sh AUTHORS diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c index 50ec0e973eb..d66a1a5edbd 100644 --- a/usr.bin/at/at.c +++ b/usr.bin/at/at.c @@ -1,4 +1,4 @@ -/* $OpenBSD: at.c,v 1.29 2002/05/14 18:05:39 millert Exp $ */ +/* $OpenBSD: at.c,v 1.30 2002/07/15 19:13:29 millert Exp $ */ /* $NetBSD: at.c,v 1.4 1995/03/25 18:13:31 glass Exp $ */ /* @@ -33,8 +33,11 @@ */ #include <sys/param.h> +#include <sys/socket.h> #include <sys/stat.h> #include <sys/time.h> +#include <sys/un.h> + #include <ctype.h> #include <dirent.h> #include <err.h> @@ -49,6 +52,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <utime.h> #include <utmp.h> #if (MAXLOGNAME-1) > UT_NAMESIZE @@ -69,7 +73,7 @@ #define TIMESIZE 50 /* Size of buffer passed to strftime() */ #ifndef lint -static const char rcsid[] = "$OpenBSD: at.c,v 1.29 2002/05/14 18:05:39 millert Exp $"; +static const char rcsid[] = "$OpenBSD: at.c,v 1.30 2002/07/15 19:13:29 millert Exp $"; #endif /* Variables to remove from the job's environment. */ @@ -93,6 +97,7 @@ static void sigc(int); static void alarmc(int); static void writefile(time_t, char); static void list_jobs(int, char **, int, int); +static void poke_daemon(void); static time_t ttime(const char *); static void @@ -260,8 +265,8 @@ writefile(time_t runtimer, char queue) if (fpin == NULL) perr("Cannot open input file"); } - (void)fprintf(fp, "#!/bin/sh\n# atrun uid=%u gid=%u\n# mail %*s %d\n", - real_uid, real_gid, LOGNAMESIZE, mailname, send_mail); + (void)fprintf(fp, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %*s %d\n", + (long)real_uid, (long)real_gid, LOGNAMESIZE, mailname, send_mail); /* Write out the umask at the time of invocation */ (void)fprintf(fp, "umask %o\n", cmask); @@ -369,6 +374,9 @@ writefile(time_t runtimer, char queue) (void)close(fd2); + /* Poke cron so it knows to reload the at spool. */ + poke_daemon(); + runtime = *localtime(&runtimer); strftime(timestr, TIMESIZE, "%a %b %e %T %Y", &runtime); (void)fprintf(stderr, "commands will be executed using %s\n", shell); @@ -604,7 +612,7 @@ process_jobs(int argc, char **argv, int what) FILE *fp; DIR *spool; int job_matches, jobs_len, uids_len; - int error, i, ch; + int error, i, ch, changed; PRIV_START; @@ -644,6 +652,7 @@ process_jobs(int argc, char **argv, int what) } /* Loop over every file in the directory */ + changed = 0; while ((dirent = readdir(spool)) != NULL) { PRIV_START; @@ -688,7 +697,9 @@ process_jobs(int argc, char **argv, int what) if (!interactive || (interactive && rmok(runtimer))) { - if (unlink(dirent->d_name) != 0) + if (unlink(dirent->d_name) == 0) + changed = 1; + else perr(dirent->d_name); if (!force && !interactive) fprintf(stderr, @@ -733,6 +744,10 @@ process_jobs(int argc, char **argv, int what) free(jobs); free(uids); + /* If we modied the spool, poke cron so it knows to reload. */ + if (changed) + poke_daemon(); + return (error); } @@ -805,6 +820,41 @@ ttime(const char *arg) "[[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 main(int argc, char **argv) { diff --git a/usr.bin/at/pathnames.h b/usr.bin/at/pathnames.h deleted file mode 100644 index 88bc5f03ee3..00000000000 --- a/usr.bin/at/pathnames.h +++ /dev/null @@ -1,46 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.5 2002/05/11 23:16:44 millert Exp $ */ -/* $NetBSD: pathnames.h,v 1.3 1995/03/25 18:13:38 glass Exp $ */ - -/* - * Copyright (c) 1993 Christopher G. Demetriou - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef _PATHNAMES_H_ -#define _PATHNAMES_H_ - -#include <paths.h> - -#define _PATH_ATJOBS "/var/at/jobs/" -#define _PATH_ATSPOOL "/var/at/spool/" -#define _PATH_SEQFILE "/var/at/.SEQ" -#define _PATH_AT_ALLOW "/var/at/at.allow" -#define _PATH_AT_DENY "/var/at/at.deny" - -#endif /* _PATHNAMES_H_ */ |