Annotation of researchv10no/cmd/dist/lib/scanq.c, revision 1.1

1.1     ! root        1: #define _POSIX_SOURCE
        !             2: #include <dirent.h>
        !             3: #include <limits.h>
        !             4: #include <stdio.h>
        !             5: #include <stdlib.h>
        !             6: #include <string.h>
        !             7: #include <time.h>
        !             8: #include <unistd.h>
        !             9: #include "../paths.h"
        !            10: #include "lib.h"
        !            11: 
        !            12: static char *
        !            13: copy(char *s)
        !            14: {
        !            15:        char *r;
        !            16: 
        !            17:        r = xmalloc(strlen(s) + 1);
        !            18:        if (r)
        !            19:                strcpy(r, s);
        !            20:        return r;
        !            21: }
        !            22: 
        !            23: static void
        !            24: removeq(char *name)
        !            25: {
        !            26:        DIR *dp;
        !            27:        struct dirent *d;
        !            28:        char file[2 * MAXNAME + 1];
        !            29: 
        !            30:        name = copy(name);      /* readdir bug?!? */
        !            31:        if (fork() == 0) {
        !            32:                setuid(getuid());
        !            33:                execl(LDIR "/genmail", "genmail", "-f", name, (char *) 0);
        !            34:                exit(0);
        !            35:        } else
        !            36:                wait(0);
        !            37:        if (!(dp = opendir(name)))
        !            38:                return;
        !            39:        while (d = readdir(dp)) {
        !            40:                if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
        !            41:                        continue;
        !            42:                sprintf(file, "%s/%.*s", name, MAXNAME, d->d_name);
        !            43:                remove(file);
        !            44:        }
        !            45:        closedir(dp);
        !            46:        rmdir(name);
        !            47:        free(name);
        !            48: }
        !            49: 
        !            50: void
        !            51: scanq(char *remsys, void (*func)(char *, int, char *))
        !            52: {
        !            53:        DIR *dp;
        !            54:        struct dirent *d;
        !            55:        FILE *fp;
        !            56:        char sys[MAXLINE], cansys[MAXLINE], file[MAXNAME];
        !            57:        int num, zapq;
        !            58: 
        !            59:        if (remsys)
        !            60:                canonsys(remsys, cansys);
        !            61: 
        !            62:        if (chdir(SDIR) < 0) {
        !            63:                eprintf("can't chdir %s", SDIR);
        !            64:                exit(1);
        !            65:        }
        !            66: 
        !            67:        if (!(dp = opendir("."))) {
        !            68:                eprintf("can't read spool directory!");
        !            69:                exit(1);
        !            70:        }
        !            71: 
        !            72:        while (d = readdir(dp))
        !            73:                if (strncmp(d->d_name, "Q.", 2) == 0) {
        !            74:                        zapq = 1;
        !            75:                        if (chdir(d->d_name) < 0) {
        !            76:                                eprintf("can't chdir %s/%s", SDIR, d->d_name);
        !            77:                                continue;
        !            78:                        }
        !            79:                        if (fp = fopen("ctl", "r")) {
        !            80:                                while (fscanf(fp, "%d%s", &num, sys) == 2) {
        !            81:                                        sprintf(file, "%d.done", num);
        !            82:                                        if (access(file, F_OK) == 0)
        !            83:                                                continue;
        !            84:                                        if (remsys && strcmp(sys, cansys) != 0) {
        !            85:                                                zapq = 0;
        !            86:                                                continue;
        !            87:                                        }
        !            88:                                        if (func)
        !            89:                                                (*func)(d->d_name, num, sys);
        !            90:                                        if (access(file, F_OK) != 0)
        !            91:                                                zapq = 0;
        !            92:                                }
        !            93:                                fclose(fp);
        !            94:                        } else
        !            95:                                eprintf("can't read %s/%s", d->d_name, "ctl");
        !            96:                        chdir("..");
        !            97:                        if (zapq)
        !            98:                                removeq(d->d_name);
        !            99:                }
        !           100: 
        !           101:        closedir(dp);
        !           102: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.