BSD 4 release
[unix-history] / usr / src / cmd / atrun.c
index 401862a..7e8c225 100644 (file)
@@ -1,3 +1,4 @@
+static char *sccsid = "@(#)atrun.c     4.2 (Berkeley) 10/21/80";
 /*
  * Run programs submitted by at.
  */
 /*
  * Run programs submitted by at.
  */
@@ -21,9 +22,8 @@ char **argv;
        int tt, day, year, uniq;
        struct direct dirent;
        FILE *dirf;
        int tt, day, year, uniq;
        struct direct dirent;
        FILE *dirf;
+       char file[DIRSIZ+1];
 
 
-       setuid(0);
-       setgid(0);
        chdir(DIR);
        makenowtime();
        if ((dirf = fopen(".", "r")) == NULL) {
        chdir(DIR);
        makenowtime();
        if ((dirf = fopen(".", "r")) == NULL) {
@@ -33,7 +33,9 @@ char **argv;
        while (fread((char *)&dirent, sizeof(dirent), 1, dirf) == 1) {
                if (dirent.d_ino==0)
                        continue;
        while (fread((char *)&dirent, sizeof(dirent), 1, dirf) == 1) {
                if (dirent.d_ino==0)
                        continue;
-               if (sscanf(dirent.d_name, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
+               strcpyn(file, dirent.d_name, DIRSIZ);
+               file[DIRSIZ] = '\0';
+               if (sscanf(file, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
                        continue;
                if (nowyear < year)
                        continue;
                        continue;
                if (nowyear < year)
                        continue;
@@ -41,7 +43,7 @@ char **argv;
                        continue;
                if (nowyear==year && nowdate==day && nowtime < tt)
                        continue;
                        continue;
                if (nowyear==year && nowdate==day && nowtime < tt)
                        continue;
-               run(dirent.d_name);
+               run(file);
        }
        fclose(dirf);
        updatetime(nowtime);
        }
        fclose(dirf);
        updatetime(nowtime);
@@ -86,8 +88,9 @@ char *file;
        for (i=0; i<15; i++)
                close(i);
        dup(dup(open("/dev/null", 0)));
        for (i=0; i<15; i++)
                close(i);
        dup(dup(open("/dev/null", 0)));
-       sprintf(sbuf, "/bin/mv %.14s %s", file, PDIR);
-       system(sbuf);
+       sprintf(sbuf, "%s/%s", PDIR, file);
+       link(file, sbuf);
+       unlink(file);
        chdir(PDIR);
        if (stat(file, &stbuf) == -1)
                exit(1);
        chdir(PDIR);
        if (stat(file, &stbuf) == -1)
                exit(1);
@@ -100,7 +103,6 @@ char *file;
        }
        setgid(stbuf.st_gid);
        setuid(stbuf.st_uid);
        }
        setgid(stbuf.st_gid);
        setuid(stbuf.st_uid);
-       nice(3);
        execl("/bin/sh", "sh", file, 0);
        execl("/usr/bin/sh", "sh", file, 0);
        fprintf(stderr, "Can't execl shell\n");
        execl("/bin/sh", "sh", file, 0);
        execl("/usr/bin/sh", "sh", file, 0);
        fprintf(stderr, "Can't execl shell\n");