|
|
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: ! 56: resetmaps(); ! 57: for(i=0; files[i].file; i++) { ! 58: if((fp=fopen(files[i].file, "r"))==NULL) ! 59: continue; ! 60: stat(files[i].file, &st); ! 61: files[i].last = st.st_mtime; ! 62: readfile(fp, &files[i]); ! 63: fclose(fp); ! 64: } ! 65: startsvcs(); ! 66: } ! 67: ! 68: /* ! 69: * Read and parse a file ! 70: */ ! 71: readfile(fp, ap) ! 72: FILE *fp; ! 73: struct afile *ap; ! 74: { ! 75: char buf[256]; ! 76: char *cp; ! 77: int *op; ! 78: ! 79: while(fgets(buf, sizeof(buf), fp)!=NULL) { ! 80: cp = strchr(buf, '\n'); ! 81: if(cp==NULL) ! 82: logevent("%s: line too long\n", ap->file); ! 83: else ! 84: *cp = '\0'; ! 85: if(buf[0]=='#') ! 86: continue; /* comment */ ! 87: op = (*(ap->new))(buf); ! 88: if(op!=NULL) ! 89: (*(ap->add))(op); ! 90: } ! 91: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.