Annotation of researchv10no/cmd/uucp/uusched.c, revision 1.1

1.1     ! root        1: #include "uucp.h"
        !             2: 
        !             3: #define USAGE  "[-xNUM] [-uNUM]"
        !             4: 
        !             5: short Uopt;
        !             6: void cleanup();
        !             7: 
        !             8: void logent(){}                /* to load ulockf.c */
        !             9: 
        !            10: main(argc, argv, envp)
        !            11: char *argv[];
        !            12: char **envp;
        !            13: {
        !            14:        register int i;
        !            15: 
        !            16:        Uopt = 0;
        !            17:        Env = envp;
        !            18: 
        !            19:        (void) strcpy(Progname, "uusched");
        !            20:        while ((i = getopt(argc, argv, "u:x:")) != EOF) {
        !            21:                switch(i){
        !            22:                case 'x':
        !            23:                        Debug = atoi(optarg);
        !            24:                        if (Debug <= 0)
        !            25:                                Debug = 1;
        !            26:                        break;
        !            27:                case 'u':
        !            28:                        Uopt = atoi(optarg);
        !            29:                        if (Uopt <= 0)
        !            30:                                Uopt = 1;
        !            31:                        break;
        !            32:                default:
        !            33:                        (void) fprintf(stderr, "\tusage: %s %s\n",
        !            34:                            Progname, USAGE);
        !            35:                        cleanup(1);
        !            36:                }
        !            37:        }
        !            38:        if (argc != optind) {
        !            39:                (void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
        !            40:                cleanup(1);
        !            41:        }
        !            42:        if (toomany())
        !            43:                cleanup(0);
        !            44:        if (chdir(SPOOL) < 0) {
        !            45:                DEBUG(4, "can't chdir to spooldir\n", 0);
        !            46:                cleanup(101);
        !            47:        }
        !            48:        while (work())
        !            49:                ;               /* keep going till nothing to do */
        !            50:        cleanup(0);
        !            51: }
        !            52: 
        !            53: /*
        !            54:  * are there too many uuscheds already?
        !            55:  */
        !            56: toomany()
        !            57: {
        !            58:        FILE *fp;
        !            59:        int maxnum;
        !            60:        char lockname[MAXNAMESIZE];
        !            61: 
        !            62:        if ((fp = fopen(LMTUUSCHED, "r")) == NULL) {
        !            63:                DEBUG(4, "%s not found\n", LMTUUSCHED);
        !            64:                return (0);     /* assume OK */
        !            65:        }
        !            66:        if (fscanf(fp, "%d", &maxnum) != 1) {
        !            67:                DEBUG(4, "%s contains nonsense\n", LMTUUSCHED);
        !            68:                fclose(fp);
        !            69:                return (0);
        !            70:        }
        !            71:        fclose(fp);
        !            72:        DEBUG(4, "limit %d scheds\n", maxnum);
        !            73:        while (--maxnum >= 0) {
        !            74:                sprintf(lockname, "%s.%d", S_LOCK, maxnum);
        !            75:                if (ulockf(lockname, (time_t)X_LOCKTIME) == 0) {
        !            76:                        DEBUG(4, "grabbed lock %d\n", maxnum);
        !            77:                        return (0);
        !            78:                }
        !            79:        }
        !            80:        DEBUG(4, "too many scheds\n", 0);
        !            81:        return (1);
        !            82: }
        !            83: 
        !            84: /*
        !            85:  * one pass through the spool directory
        !            86:  * return nonzero if we did some work
        !            87:  */
        !            88: work()
        !            89: {
        !            90:        DIR *spool;
        !            91:        int ndone;
        !            92:        char ent[NAMESIZE];
        !            93: 
        !            94:        DEBUG(4, "work\n", 0);
        !            95:        ndone = 0;
        !            96:        if ((spool = opendir(".")) == NULL) {
        !            97:                DEBUG(4, "can't opendir .\n", 0);
        !            98:                cleanup(101);
        !            99:        }
        !           100:        while (gnamef(spool, ent) == TRUE) {
        !           101:                if (strncmp(ent, "LCK.", 4) == 0)
        !           102:                        continue;
        !           103:                if (!DIRECTORY(ent))
        !           104:                        continue;
        !           105:                DEBUG(4, "try %s: ", ent);
        !           106:                ndone += onework(ent);
        !           107:        }
        !           108:        closedir(spool);
        !           109:        return (ndone);
        !           110: }
        !           111: 
        !           112: onework(dir)
        !           113: char *dir;
        !           114: {
        !           115:        DIR *dp;
        !           116:        char file[NAMESIZE];
        !           117:        char lockname[MAXNAMESIZE];
        !           118: 
        !           119:        if (callok(dir) != 0) {
        !           120:                DEBUG(4, "not ok to call\n", 0);
        !           121:                return (0);
        !           122:        }
        !           123:        if ((dp = opendir(dir)) == NULL) {
        !           124:                DEBUG(4, "can't open\n", 0);
        !           125:                return (0);
        !           126:        }
        !           127:        while (gnamef(dp, file) == TRUE) {
        !           128:                if (file[0] == CMDPRE && file[1] == '.') {
        !           129:                        DEBUG(4, "found work ...", 0);
        !           130:                        closedir(dp);
        !           131:                        sprintf(lockname, "%s.%s", LOCKPRE, dir);
        !           132:                        if (checkLock(lockname) == FAIL) {
        !           133:                                DEBUG(4, "locked\n", 0);
        !           134:                                return (0);
        !           135:                        }
        !           136:                        DEBUG(4, "call it\n", 0);
        !           137:                        return (exuucico(dir));
        !           138:                }
        !           139:        }
        !           140:        DEBUG(4, "no work\n", 0);
        !           141:        closedir(dp);
        !           142:        return (0);
        !           143: }
        !           144: 
        !           145: exuucico(name)
        !           146: char *name;
        !           147: {
        !           148:        char cmd[BUFSIZ];
        !           149:        int ret;
        !           150:        char uopt[5];
        !           151:        char sopt[BUFSIZ];
        !           152:        int pid, rpid;
        !           153: 
        !           154:        (void) sprintf(sopt, "-s%s", name);
        !           155:        if (Uopt)
        !           156:            (void) sprintf(uopt, "-x%.1d", Uopt);
        !           157: 
        !           158:        if ((pid = fork()) == 0) {
        !           159:            if (Uopt)
        !           160:                (void) execle(UUCICO, "UucicO", "-r1", uopt, sopt, (char *)0, Env);
        !           161:            else
        !           162:                (void) execle(UUCICO, "UucicO", "-r1", sopt, (char *)0, Env);
        !           163: 
        !           164:            cleanup(100);
        !           165:        }
        !           166:        while ((rpid = wait(&ret)) > 0 && rpid != pid)
        !           167:                ;
        !           168: 
        !           169:        DEBUG(3, "ret=%d, ", ret);
        !           170:        DEBUG(3, "errno=%d\n", errno);
        !           171:        return (ret == 0);
        !           172: }
        !           173: 
        !           174: 
        !           175: void
        !           176: cleanup(code)
        !           177: int    code;
        !           178: {
        !           179:        DEBUG(4, "cleanup %d\n", code);
        !           180:        rmlock(CNULL);
        !           181:        exit(code);
        !           182: }

unix.superglobalmegacorp.com

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