Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- a/atd.c 2015-12-06 16:45:10.000000000 +0100
- +++ b/atd.c 2016-02-20 12:23:19.000000000 +0100
- @@ -276,6 +276,7 @@
- */
- pid_t pid;
- int fd_out, fd_in;
- + char shell_path[256];
- char jobbuf[9];
- char *mailname = NULL;
- int mailsize = 128;
- @@ -296,6 +297,8 @@
- int retcode;
- #endif
- + memset(shell_path, '\0', 256);
- +
- #ifdef _SC_LOGIN_NAME_MAX
- errno = 0;
- rc = sysconf(_SC_LOGIN_NAME_MAX);
- @@ -308,12 +311,12 @@
- #endif
- sscanf(filename, "%c%5lx", &queue, &jobno);
- if ((mailname = malloc(mailsize+1)) == NULL)
- - pabort("Job %8lu : out of virtual memory", jobno);
- + pabort("Job %lu : out of virtual memory", jobno);
- - sprintf(jobbuf, "%8lu", jobno);
- + sprintf(jobbuf, "%lu", jobno);
- if ((newname = strdup(filename)) == 0)
- - pabort("Job %8lu : out of virtual memory", jobno);
- + pabort("Job %lu : out of virtual memory", jobno);
- newname[0] = '=';
- /* We try to make a hard link to lock the file. If we fail, then
- @@ -350,7 +353,7 @@
- pentry = getpwuid(uid);
- if (pentry == NULL) {
- - pabort("Userid %lu not found - aborting job %8lu (%.500s)",
- + pabort("Userid %lu not found - aborting job %lu (%.500s)",
- (unsigned long) uid, jobno, filename);
- }
- PRIV_START
- @@ -372,17 +375,17 @@
- perr("Error in fstat of input file");
- if (S_ISLNK(lbuf.st_mode))
- - perr("Symbolic link encountered in job %8lu (%.500s) - aborting",
- + perr("Symbolic link encountered in job %lu (%.500s) - aborting",
- jobno, 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))
- - perr("Somebody changed files from under us for job %8lu (%.500s) - "
- + perr("Somebody changed files from under us for job %lu (%.500s) - "
- "aborting", jobno, filename);
- if (buf.st_nlink > 2) {
- - perr("Somebody is trying to run a linked script for job %8lu (%.500s)",
- + perr("Somebody is trying to run a linked script for job %lu (%.500s)",
- jobno, filename);
- }
- if ((fflags = fcntl(fd_in, F_GETFD)) < 0)
- @@ -397,20 +400,19 @@
- * NFS and works with local file systems. It's not clear where
- * the bug is located. -Joey
- */
- - sprintf(fmt, "#!/bin/sh\n# atrun uid=%%d gid=%%d\n# mail %%%ds %%d",
- - mailsize );
- + sprintf(fmt, "#!%%255s\n# atrun uid=%%d gid=%%d\n# mail %%%ds %%d", mailsize);
- if (fscanf(stream, fmt,
- - &nuid, &ngid, mailname, &send_mail) != 4)
- + shell_path, &nuid, &ngid, mailname, &send_mail) != 5)
- pabort("File %.500s is in wrong format - aborting",
- filename);
- if (mailname[0] == '-')
- - pabort("illegal mail name %.300s in job %8lu (%.300s)", mailname,
- + pabort("illegal mail name %.300s in job %lu (%.300s)", mailname,
- jobno, filename);
- if (nuid != uid)
- - pabort("Job %8lu (%.500s) - userid %d does not match file uid %d",
- + pabort("Job %lu (%.500s) - userid %d does not match file uid %d",
- jobno, filename, nuid, uid);
- /* We are now committed to executing this script. Unlink the
- @@ -437,7 +439,7 @@
- perr("Cannot create output file");
- PRIV_START
- if (fchown(fd_out, uid, ngid) == -1)
- - syslog(LOG_WARNING, "Warning: could not change owner of output file for job %li to %i:%i: %s",
- + syslog(LOG_WARNING, "Warning: could not change owner of output file for job %li to %i:%i : %s",
- jobno, uid, ngid, strerror(errno));
- PRIV_END
- @@ -445,6 +447,8 @@
- write_string(fd_out, jobbuf);
- write_string(fd_out, "\nTo: ");
- write_string(fd_out, mailname);
- + write_string(fd_out, "\nX-Atd-Job: ");
- + write_string(fd_out, jobbuf);
- write_string(fd_out, "\n\n");
- fstat(fd_out, &buf);
- size = buf.st_size;
- @@ -514,8 +518,8 @@
- chdir("/");
- - if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0)
- - perr("Exec failed for /bin/sh");
- + if (execle(shell_path, shell_path, (char *) NULL, nenvp) != 0)
- + perr("Exec failed for %s", shell_path);
- PRIV_END
- }
- @@ -601,6 +605,7 @@
- struct dirent *dirent;
- struct stat buf;
- unsigned long ctm;
- + unsigned int ctmsec;
- unsigned long jobno;
- char queue;
- char batch_queue = '\0';
- @@ -651,8 +656,12 @@
- while ((dirent = readdir(spool)) != NULL) {
- /* Avoid the stat if this doesn't look like a job file */
- - if (sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm) != 3)
- - continue;
- + if (sscanf(dirent->d_name, "%c%5lx%8lx%2u", &queue, &jobno, &ctm, &ctmsec) != 4)
- + {
- + ctmsec = 0;
- + if (sscanf(dirent->d_name, "%c%5lx%8lx", &queue, &jobno, &ctm) != 3)
- + continue;
- + }
- /* Chances are a '=' file has been deleted from under us.
- * Ignore.
- @@ -669,7 +678,7 @@
- continue;
- }
- - run_time = (time_t) ctm *60;
- + run_time = (time_t) ctm * 60 + ctmsec;
- /* Skip lock files */
- if (queue == '=') {
Add Comment
Please, Sign In to add comment