BSD 4 release
[unix-history] / usr / src / cmd / atrun.c
index e997fad..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.
  */
@@ -20,8 +21,8 @@ char **argv;
 {
        int tt, day, year, uniq;
        struct direct dirent;
 {
        int tt, day, year, uniq;
        struct direct dirent;
-       char file[DIRSIZ+1];
        FILE *dirf;
        FILE *dirf;
+       char file[DIRSIZ+1];
 
        chdir(DIR);
        makenowtime();
 
        chdir(DIR);
        makenowtime();
@@ -32,7 +33,7 @@ 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;
-               strncpy(file, dirent.d_name, DIRSIZ);
+               strcpyn(file, dirent.d_name, DIRSIZ);
                file[DIRSIZ] = '\0';
                if (sscanf(file, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
                        continue;
                file[DIRSIZ] = '\0';
                if (sscanf(file, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
                        continue;
@@ -81,18 +82,18 @@ char *file;
        register pid, i;
        char sbuf[64];
 
        register pid, i;
        char sbuf[64];
 
+       /* printf("running %s\n", file); */
        if (fork()!=0)
                return;
        for (i=0; i<15; i++)
                close(i);
        dup(dup(open("/dev/null", 0)));
        if (fork()!=0)
                return;
        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);
-       setgid(stbuf.st_gid);
-       setuid(stbuf.st_uid);
        if (pid = fork()) {
                if (pid == -1)
                        exit(1);
        if (pid = fork()) {
                if (pid == -1)
                        exit(1);
@@ -100,7 +101,8 @@ char *file;
                unlink(file);
                exit(0);
        }
                unlink(file);
                exit(0);
        }
-       nice(3);
+       setgid(stbuf.st_gid);
+       setuid(stbuf.st_uid);
        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");