1: /*
   2:  * Run programs submitted by at.
   3:  */
   4: /*! Modified by PLWard, 10/30/80, USGS for csh and mail options */
   5: 
   6: #include <stdio.h>
   7: #include <sys/types.h>
   8: #include <sys/dir.h>
   9: #include <time.h>
  10: #include <sys/stat.h>
  11: 
  12: # define DIR    "/usr/spool/at"
  13: # define PDIR   "past"
  14: # define LASTF  "/usr/spool/at/lasttimedone"
  15: #define MV      "mv"
  16: 
  17: int nowtime;
  18: int nowdate;
  19: int nowyear;
  20: 
  21: main(argc, argv)
  22: char **argv;
  23: {
  24:     int tt, day, year, uniq;
  25:     struct direct dirent;
  26:     char file[DIRSIZ+1];
  27:     FILE *dirf;
  28: 
  29:     chdir(DIR);
  30:     makenowtime();
  31:     if ((dirf = fopen(".", "r")) == NULL) {
  32:         fprintf(stderr, "Cannot read at directory\n");
  33:         exit(1);
  34:     }
  35:     while (fread((char *)&dirent, sizeof(dirent), 1, dirf) == 1) {
  36:         if (dirent.d_ino==0)
  37:             continue;
  38:         strncpy(file, dirent.d_name, DIRSIZ);
  39:         file[DIRSIZ] = '\0';
  40:         if (sscanf(file, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
  41:             continue;
  42:         if (nowyear < year)
  43:             continue;
  44:         if (nowyear==year && nowdate < day)
  45:             continue;
  46:         if (nowyear==year && nowdate==day && nowtime < tt)
  47:             continue;
  48:         run(file);
  49:     }
  50:     fclose(dirf);
  51:     updatetime(nowtime);
  52:     exit(0);
  53: }
  54: 
  55: makenowtime()
  56: {
  57:     long t;
  58:     struct tm *localtime();
  59:     register struct tm *tp;
  60: 
  61:     time(&t);
  62:     tp = localtime(&t);
  63:     nowtime = tp->tm_hour*100 + tp->tm_min;
  64:     nowdate = tp->tm_yday;
  65:     nowyear = tp->tm_year;
  66: }
  67: 
  68: updatetime(t)
  69: {
  70:     FILE *tfile;
  71: 
  72:     tfile = fopen(LASTF, "w");
  73:     if (tfile == NULL) {
  74:         fprintf(stderr, "can't write lastfile\n");
  75:         exit(1);
  76:     }
  77:     fprintf(tfile, "%04d\n", t);
  78: }
  79: 
  80: run(file)
  81: char *file;
  82: {
  83:     struct stat stbuf;
  84:     register pid, i;
  85:     char sbuf[64];
  86:     char outfile[DIRSIZ+1];
  87:     extern ctime(),time();
  88: 
  89:     if (stat(file, &stbuf) == -1) exit(1);
  90:     if (stbuf.st_nlink != 1) {
  91:         fprintf(stderr, "atrun:  %s:  st_nlink != 1\n", file);
  92:         unlink(file);
  93:         exit(1);
  94:     }
  95:     setgid(stbuf.st_gid);
  96:     setuid(stbuf.st_uid);
  97:     strcpy(outfile,file);
  98:     outfile[0]='M';
  99:     if (fork()!=0)
 100:         return;
 101:     for (i=0; i<15; i++)
 102:         close(i);
 103:     sprintf(sbuf, "%s %.14s %s", MV, file, PDIR);
 104:     if (system(sbuf)<0)
 105:         perror("mv");
 106:     chdir(PDIR);
 107:     open("/dev/null",0);
 108:     dup(creat(outfile,0666));
 109:     if (pid = fork()) {
 110:         if (pid == -1)
 111:             exit(1);
 112:         wait((int *)0);
 113:         unlink(file);
 114:         exit(0);
 115:     }
 116: /*	nice(3); executed by chron which has nice of 20 already. PLW */
 117:     execl("/bin/csh", "csh","-f", file, 0);
 118:     execl("/usr/bin/csh", "csh","-f", file, 0);
 119:     fprintf(stderr, "Can't execl shell\n");
 120:     exit(1);
 121: }

Defined functions

main defined in line 21; never used
makenowtime defined in line 55; used 1 times
  • in line 30
run defined in line 80; used 1 times
  • in line 48
updatetime defined in line 68; used 1 times
  • in line 51

Defined variables

nowdate defined in line 18; used 3 times
nowtime defined in line 17; used 3 times
nowyear defined in line 19; used 4 times

Defined macros

DIR defined in line 12; used 1 times
  • in line 29
LASTF defined in line 14; used 1 times
  • in line 72
MV defined in line 15; used 1 times
PDIR defined in line 13; used 2 times
Last modified: 1983-06-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 985
Valid CSS Valid XHTML 1.0 Strict