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