|
|
1.1 ! root 1: /* ! 2: ** Set up parameters for share scheduler ! 3: */ ! 4: ! 5: #include <shares.h> ! 6: #include <sys/share.h> ! 7: #include <signal.h> ! 8: #include <setjmp.h> ! 9: #include <stdio.h> ! 10: #include <errno.h> ! 11: ! 12: #define DEFSHARES 1 /* Default number of shares for a group 0 user */ ! 13: #define SYSERROR (-1) ! 14: #ifndef ETOOMANYU ! 15: #define ETOOMANYU ENOSPC /* Must go in errno.h or lnode.h */ ! 16: #endif ! 17: ! 18: static int catchsys(); ! 19: static jmp_buf Sigsysbuf; ! 20: ! 21: int ! 22: setupshares(uid, efp) ! 23: int uid; ! 24: void (*efp)(); ! 25: { ! 26: register int (*oldsig)(); ! 27: register unsigned long extime; ! 28: struct sh_consts shconsts; ! 29: struct lnode share; ! 30: extern unsigned long time(); ! 31: ! 32: if ( uid == 0 ) ! 33: return 0; /* root needs no set-up */ ! 34: ! 35: oldsig = signal(SIGSYS, catchsys); ! 36: ! 37: if ! 38: ( ! 39: setjmp(Sigsysbuf) ! 40: || ! 41: limits((struct lnode *)&shconsts, L_GETCOSTS) == SYSERROR ! 42: || ! 43: (Shareflags & NOSHARE) ! 44: ) ! 45: { ! 46: (void)signal(SIGSYS, oldsig); ! 47: return 0; /* Share not installed/active */ ! 48: } ! 49: ! 50: (void)signal(SIGSYS, oldsig); ! 51: ! 52: if ( (extime = getshares(&share, uid, 0)) == 0 ) ! 53: { ! 54: if ( uid == IDLEUID ) ! 55: { ! 56: share.l_shares = IDLESHARES; ! 57: share.l_group = IDLEGROUP; ! 58: } ! 59: else ! 60: if ( uid == OTHERUID ) ! 61: { ! 62: share.l_shares = OTHERSHARES; ! 63: share.l_group = OTHERGROUP; ! 64: } ! 65: else ! 66: { ! 67: if ( efp != (void (*)())0 ) ! 68: (*efp)("Cannot get shares for uid %d -- using defaults.", uid); ! 69: share.l_shares = DEFSHARES; ! 70: } ! 71: } ! 72: else ! 73: if ( limits(&share, L_OTHLIM) == SYSERROR ) ! 74: { ! 75: /* ! 76: ** Decay usage by time since last access. ! 77: */ ! 78: ! 79: if ( (extime = (time((long *)0) - extime) / Delta) > 0 ) ! 80: { ! 81: extern double pow(); ! 82: ! 83: share.l_usage *= pow(DecayUsage, (float)extime); ! 84: } ! 85: } ! 86: ! 87: if ( setlimits(&share) == SYSERROR ) ! 88: { ! 89: if ( errno == ETOOMANYU ) ! 90: { ! 91: char * cp = "other"; ! 92: ! 93: share.l_uid = OTHERUID; ! 94: ! 95: if ( limits(&share, L_OTHLIM) != SYSERROR ) ! 96: (void)setlimits(&share); ! 97: else ! 98: cp = "root"; ! 99: ! 100: if ( efp != (void (*)())0 ) ! 101: (*efp)("Warning: system out of share structures, using \"%s\".\n", cp); ! 102: } ! 103: else ! 104: { ! 105: if ( efp != (void (*)())0 ) ! 106: (*efp)("setlimits(3) error"); ! 107: closeshares(); ! 108: return 1; ! 109: } ! 110: } ! 111: ! 112: closeshares(); ! 113: ! 114: return 0; ! 115: } ! 116: ! 117: static int ! 118: catchsys(sig) ! 119: { ! 120: longjmp(Sigsysbuf, 1); ! 121: abort(); ! 122: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.