|
|
1.1 ! root 1: /* ! 2: * read in the control files; ! 3: * deal with the tables ! 4: */ ! 5: ! 6: #include "mgr.h" ! 7: #include <sys/types.h> ! 8: #include <sys/stat.h> ! 9: #include <setjmp.h> ! 10: ! 11: typedef int *(*PTOI)(); ! 12: struct afile { ! 13: char *file; ! 14: int *(*new)(); ! 15: int (*add)(); ! 16: long last; ! 17: } files[] = { ! 18: {"/usr/ipc/lib/serv.local", (PTOI)newservice, addservice}, ! 19: {"/usr/ipc/lib/serv", (PTOI)newservice, addservice}, ! 20: {"/usr/ipc/lib/auth.local", (PTOI)newmap, addmap}, ! 21: {"/usr/ipc/lib/auth", (PTOI)newmap, addmap}, ! 22: {NULL} ! 23: }; ! 24: ! 25: /* ! 26: * stuff concerning the service tables ! 27: */ ! 28: statfiles() ! 29: { ! 30: register int i; ! 31: struct stat st; ! 32: ! 33: for (i = 0; files[i].file; i++) ! 34: if (stat(files[i].file, &st) >= 0) ! 35: files[i].last = st.st_mtime; ! 36: } ! 37: ! 38: checkfiles() ! 39: { ! 40: register int i; ! 41: struct stat st; ! 42: ! 43: for(i=0; files[i].file; i++) ! 44: if (stat(files[i].file, &st) >= 0 ! 45: && st.st_mtime > files[i].last) ! 46: return (1); ! 47: return (0); ! 48: } ! 49: ! 50: readfiles() ! 51: { ! 52: FILE *fp; ! 53: int i; ! 54: struct stat st; ! 55: char buf[64]; ! 56: ! 57: resetmaps(); ! 58: for(i=0; files[i].file; i++) { ! 59: if((fp=fopen(files[i].file, "r"))==NULL) ! 60: continue; ! 61: stat(files[i].file, &st); ! 62: files[i].last = st.st_mtime; ! 63: readfile(fp, &files[i]); ! 64: fclose(fp); ! 65: } ! 66: strcpy(buf, "readfiles readfiles"); ! 67: addservice(newservice(buf)); ! 68: startsvcs(); ! 69: } ! 70: ! 71: /* ! 72: * Read and parse a file ! 73: */ ! 74: readfile(fp, ap) ! 75: FILE *fp; ! 76: struct afile *ap; ! 77: { ! 78: char buf[256]; ! 79: char *cp; ! 80: int *op; ! 81: ! 82: while(fgets(buf, sizeof(buf), fp)!=NULL) { ! 83: cp = strchr(buf, '\n'); ! 84: if(cp==NULL) ! 85: logevent("%s: line too long\n", ap->file); ! 86: else ! 87: *cp = '\0'; ! 88: if(buf[0]=='#') ! 89: continue; /* comment */ ! 90: op = (*(ap->new))(buf); ! 91: if(op!=NULL) ! 92: (*(ap->add))(op); ! 93: } ! 94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.