-/*
+/*
* atrun.c - run jobs queued by at; run with root privileges.
* Copyright (C) 1993, 1994 Thomas Koenig
*
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static const char rcsid[] =
- "$FreeBSD: src/libexec/atrun/atrun.c,v 1.27 2009/12/25 10:30:54 ed Exp $";
+__FBSDID("$FreeBSD: src/libexec/atrun/atrun.c,v 1.27 2009/12/25 10:30:54 ed Exp $");
#endif /* not lint */
/* System Headers */
static void usage(void);
/* Local functions */
-static int
+static ssize_t
write_string(int fd, const char* a)
{
return write(fd, a, strlen(a));
pid = fork();
if (pid == -1)
perr("cannot fork");
-
+
else if (pid != 0)
return;
if (S_ISLNK(lbuf.st_mode))
perrx("Symbolic link encountered in job %s - aborting", filename);
-
+
if ((lbuf.st_dev != buf.st_dev) || (lbuf.st_ino != buf.st_ino) ||
(lbuf.st_uid != buf.st_uid) || (lbuf.st_gid != buf.st_gid) ||
(lbuf.st_size!=buf.st_size))
perrx("Somebody changed files from under us for job %s - aborting",
filename);
-
+
if (buf.st_nlink > 1)
perrx("Somebody is trying to run a linked script for job %s", filename);
-
+
if ((fflags = fcntl(fd_in, F_GETFD)) <0)
perr("error in fcntl");
if (mailbuf[0] == '-')
perrx("Illegal mail name %s in %s", mailbuf, filename);
-
+
mailname = mailbuf;
if (nuid != uid)
if (chdir(ATSPOOL_DIR) < 0)
perr("cannot chdir to %s", ATSPOOL_DIR);
-
+
/* Create a file to hold the output of the job we are about to run.
* Write the mail header.
- */
+ */
if((fd_out=open(filename,
O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) < 0)
perr("cannot create output file");
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
-
+
pid = fork();
if (pid < 0)
perr("error in fork");
PRIV_START
nice(tolower(queue) - 'a');
-
+
#ifdef LOGIN_CAP
/*
* For simplicity and safety, set all aspects of the user context
unlink(filename);
if ((buf.st_size != size) || send_mail)
- {
+ {
PRIV_START
#ifdef LOGIN_CAP
{
switch (c)
{
- case 'l':
+ case 'l':
if (sscanf(optarg, "%lf", &load_avg) != 1)
perr("garbled option -l");
if (load_avg <= 0.)
/* We don't want directories
*/
- if (!S_ISREG(buf.st_mode))
+ if (!S_ISREG(buf.st_mode))
continue;
if (sscanf(dirent->d_name,"%c%5lx%8lx",&queue,&jobno,&ctm) != 3)
batch_uid = buf.st_uid;
batch_gid = buf.st_gid;
}
-
+
/* The file is executable and old enough
*/
if (islower(queue))
if (debug)
fprintf(stderr, "usage: atrun [-l load_avg] [-d]\n");
else
- syslog(LOG_ERR, "usage: atrun [-l load_avg] [-d]");
+ syslog(LOG_ERR, "usage: atrun [-l load_avg] [-d]");
exit(EXIT_FAILURE);
}