|
|
1.1 ! root 1: /* /sccs/src/cmd/uucp/s.uusched.c ! 2: uusched.c 1.5 8/30/84 17:38:12 ! 3: */ ! 4: #include "uucp.h" ! 5: VERSION(@(#)uusched.c 1.5); ! 6: ! 7: #define USAGE "[-xNUM] [-uNUM]" ! 8: ! 9: struct m { ! 10: char mach[15]; ! 11: int ccount; ! 12: } M[UUSTAT_TBL+2]; ! 13: ! 14: short Uopt; ! 15: void cleanup(); ! 16: ! 17: void logent(){} /* to load ulockf.c */ ! 18: ! 19: main(argc, argv, envp) ! 20: char *argv[]; ! 21: char **envp; ! 22: { ! 23: struct m *m, *machine(); ! 24: DIR *spooldir, *subdir; ! 25: char *str, *rindex(); ! 26: char f[256], subf[256]; ! 27: short num, snumber; ! 28: char lckname[MAXFULLNAME]; ! 29: int i, maxnumb; ! 30: FILE *fp; ! 31: ! 32: Uopt = 0; ! 33: Env = envp; ! 34: ! 35: (void) strcpy(Progname, "uusched"); ! 36: while ((i = getopt(argc, argv, "u:x:")) != EOF) { ! 37: switch(i){ ! 38: case 'x': ! 39: Debug = atoi(optarg); ! 40: if (Debug <= 0) ! 41: Debug = 1; ! 42: break; ! 43: case 'u': ! 44: Uopt = atoi(optarg); ! 45: if (Uopt <= 0) ! 46: Uopt = 1; ! 47: break; ! 48: default: ! 49: (void) fprintf(stderr, "\tusage: %s %s\n", ! 50: Progname, USAGE); ! 51: cleanup(1); ! 52: } ! 53: } ! 54: if (argc != optind) { ! 55: (void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE); ! 56: cleanup(1); ! 57: } ! 58: ! 59: DEBUG(9, "Progname (%s): STARTED\n", Progname); ! 60: fp = fopen(LMTUUSCHED, "r"); ! 61: if (fp == NULL) { ! 62: DEBUG(1, "No limitfile - %s\n", LMTUUSCHED); ! 63: } else { ! 64: (void) fscanf(fp, "%d", &maxnumb); ! 65: (void) fclose(fp); ! 66: DEBUG(4, "Uusched limit %d -- ", maxnumb); ! 67: ! 68: for (i=0; i<maxnumb; i++) { ! 69: (void) sprintf(lckname, "%s.%d", S_LOCK, i); ! 70: if ( ulockf(lckname, (time_t) X_LOCKTIME) == 0) ! 71: break; ! 72: } ! 73: if (i == maxnumb) { ! 74: DEBUG(4, "found %d -- cleanuping\n ", maxnumb); ! 75: cleanup(0); ! 76: } ! 77: DEBUG(4, "continuing\n", maxnumb); ! 78: } ! 79: ! 80: if (chdir(SPOOL) != 0 || (spooldir = opendir(SPOOL)) == NULL) ! 81: cleanup(101); /* good old code 101 */ ! 82: while (gnamef(spooldir, f) == TRUE) { ! 83: if (EQUALSN("LCK..", f, 5)) ! 84: continue; ! 85: ! 86: if (DIRECTORY(f) && (subdir = opendir(f))) { ! 87: while (gnamef(subdir, subf) == TRUE) ! 88: if (subf[1] == '.') { ! 89: if (subf[0] == CMDPRE) { ! 90: /* Note - we can break now, but the ! 91: * count may be useful for enhanced ! 92: * scheduling ! 93: */ ! 94: machine(f)->ccount++; ! 95: } ! 96: } ! 97: closedir(subdir); ! 98: } ! 99: } ! 100: ! 101: /* Make sure the overflow entry is null since it may be incorrect */ ! 102: M[UUSTAT_TBL].mach[0] = NULLCHAR; ! 103: ! 104: /* count the number of systems */ ! 105: for (num=0, m=M; m->mach[0] != '\0'; m++, num++) { ! 106: DEBUG(5, "machine: %s, ", M[num].mach); ! 107: DEBUG(5, "ccount: %d\n", M[num].ccount); ! 108: } ! 109: ! 110: DEBUG(5, "Execute num=%d \n", num); ! 111: while (num > 0) { ! 112: snumber = (time((long *) 0) % (long) (num)); /* random num */ ! 113: (void) strcpy(Rmtname, M[snumber].mach); ! 114: DEBUG(5, "num=%d, ", num); ! 115: DEBUG(5, "snumber=%d, ", snumber); ! 116: DEBUG(5, "Rmtname=%s\n", Rmtname); ! 117: (void) sprintf(lckname, "%s.%s", LOCKPRE, Rmtname); ! 118: if (checkLock(lckname) != FAIL && callok(Rmtname) == 0) { ! 119: /* no lock file and status time ok */ ! 120: DEBUG(5, "call exuucico(%s)\n", Rmtname); ! 121: exuucico(Rmtname); ! 122: } ! 123: else { ! 124: /* system locked - skip it */ ! 125: DEBUG(5, "system %s locked or inappropriate status--skip it\n", ! 126: Rmtname); ! 127: } ! 128: ! 129: M[snumber] = M[num-1]; ! 130: num--; ! 131: } ! 132: cleanup(0); ! 133: } ! 134: ! 135: struct m * ! 136: machine(name) ! 137: char *name; ! 138: { ! 139: struct m *m; ! 140: int namelen; ! 141: ! 142: namelen = strlen(name); ! 143: DEBUG(9, "machine(%s) called\n", name); ! 144: for (m = M; m->mach[0] != '\0'; m++) ! 145: /* match on overlap? */ ! 146: if (EQUALSN(name, m->mach, SYSNSIZE)) { ! 147: /* use longest name */ ! 148: if (namelen > strlen(m->mach)) ! 149: (void) strcpy(m->mach, name); ! 150: return(m); ! 151: } ! 152: ! 153: /* ! 154: * The table is set up with 2 extra entries ! 155: * When we go over by one, output error to errors log ! 156: * When more than one over, just reuse the previous entry ! 157: */ ! 158: if (m-M >= UUSTAT_TBL) { ! 159: if (m-M == UUSTAT_TBL) { ! 160: errent("MACHINE TABLE FULL", "", UUSTAT_TBL, ! 161: sccsid, __FILE__, __LINE__); ! 162: } ! 163: else ! 164: /* use the last entry - overwrite it */ ! 165: m = &M[UUSTAT_TBL]; ! 166: } ! 167: ! 168: (void) strcpy(m->mach, name); ! 169: m->ccount = 0; ! 170: return(m); ! 171: } ! 172: ! 173: exuucico(name) ! 174: char *name; ! 175: { ! 176: char cmd[BUFSIZ]; ! 177: short ret; ! 178: char uopt[5]; ! 179: char sopt[BUFSIZ]; ! 180: ! 181: (void) sprintf(sopt, "-s%s", name); ! 182: if (Uopt) ! 183: (void) sprintf(uopt, "-x%.1d", Uopt); ! 184: ! 185: if (vfork() == 0) { ! 186: if (Uopt) ! 187: (void) execle(UUCICO, "UUCICO", "-r1", uopt, sopt, 0, Env); ! 188: else ! 189: (void) execle(UUCICO, "UUCICO", "-r1", sopt, 0, Env); ! 190: ! 191: cleanup(100); ! 192: } ! 193: (void) wait(&ret); ! 194: ! 195: DEBUG(3, "ret=%d, ", ret); ! 196: DEBUG(3, "errno=%d\n", errno); ! 197: } ! 198: ! 199: ! 200: void ! 201: cleanup(code) ! 202: int code; ! 203: { ! 204: rmlock(CNULL); ! 205: exit(code); ! 206: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.