|
|
1.1 ! root 1: /* ! 2: ulimit -- handle "ulimit" builtin ! 3: ! 4: Eric Gisin, September 1988 ! 5: Adapted to PD KornShell. Removed AT&T code. ! 6: ! 7: last edit: 06-Jun-1987 D A Gwyn ! 8: ! 9: This started out as the BRL UNIX System V system call emulation ! 10: for 4.nBSD, and was later extended by Doug Kingston to handle ! 11: the extended 4.nBSD resource limits. It now includes the code ! 12: that was originally under case SYSULIMIT in source file "xec.c". ! 13: */ ! 14: ! 15: static char *RCSid = "$Header: ulimit.c,v 3.1 88/11/03 09:18:11 egisin Exp $"; ! 16: ! 17: #include <stddef.h> ! 18: #include <errno.h> ! 19: #include <signal.h> ! 20: #include <setjmp.h> ! 21: #if defined(_BSD) || defined(_BSD_SYSV) ! 22: #include <sys/time.h> ! 23: #include <sys/resource.h> ! 24: #else ! 25: #define RLIMIT_FSIZE 2 ! 26: #endif ! 27: #include "sh.h" ! 28: ! 29: extern long ulimit(); ! 30: ! 31: int ! 32: do_ulimit(a1, a2) ! 33: char *a1, *a2; ! 34: { ! 35: register int c; ! 36: long i; ! 37: #if defined(_BSD) || defined(_BSD_SYSV) ! 38: struct rlimit limit; /* data being gotten/set */ ! 39: int softonly = 0; /* set => soft limit, clear => hard limit */ ! 40: int factor = 1024; /* unit scaling (1K or 1) */ ! 41: #endif ! 42: int command = RLIMIT_FSIZE; ! 43: ! 44: if (a1 && (*a1 == '-')) /* DAG -- Gould added first test */ ! 45: { c = *++a1; /* DAG */ ! 46: #if defined(_BSD) || defined(_BSD_SYSV) ! 47: if (c >= 'A' && c <= 'Z') ! 48: { ! 49: ++softonly; ! 50: c += 'a' - 'A'; /* DAG -- map to lower-case */ ! 51: } ! 52: #endif ! 53: switch(c) ! 54: { ! 55: #if defined(_BSD) || defined(_BSD_SYSV) ! 56: case 'c': ! 57: command = RLIMIT_CORE; ! 58: break; ! 59: case 'd': ! 60: command = RLIMIT_DATA; ! 61: break; ! 62: case 'm': ! 63: command = RLIMIT_RSS; ! 64: break; ! 65: case 's': ! 66: command = RLIMIT_STACK; ! 67: break; ! 68: case 't': ! 69: factor = 1; ! 70: command = RLIMIT_CPU; ! 71: break; ! 72: #endif /* _BSD || _BSD_SYSV */ ! 73: case 'f': ! 74: command = RLIMIT_FSIZE; ! 75: #if _BSD_SYSV ! 76: factor = 512; ! 77: #endif ! 78: break; ! 79: default: ! 80: #if _BSD ! 81: errorf("Usage: %s [-cdmstf] [limit]\n", "ulimit"); ! 82: #else ! 83: errorf("Usage: %s [-f] [limit]\n", "ulimit"); ! 84: #endif ! 85: } ! 86: a1 = a2; ! 87: } ! 88: if (a1) ! 89: { ! 90: i = 0; ! 91: while ((c = *a1++) >= '0' && c <= '9') ! 92: { ! 93: i = (i * 10) + (long)(c - '0'); ! 94: if (i < 0) ! 95: goto Error; ! 96: } ! 97: if (c || i < 0) ! 98: goto Error; ! 99: } ! 100: #if !(defined(_BSD) || defined(_BSD_SYSV)) ! 101: else ! 102: { ! 103: i = -1; ! 104: command--; ! 105: } ! 106: ! 107: #if !COHERENT ! 108: if ((i = ulimit(command, i)) < 0L) ! 109: goto Error; ! 110: if (command != RLIMIT_FSIZE) ! 111: shellf("%ld\n", i); ! 112: #endif ! 113: #else /* DPK -- generalized for 4.nBSD: */ ! 114: if (getrlimit(command, &limit)) ! 115: goto Error; /* errno is already set */ ! 116: ! 117: if (a1) ! 118: { ! 119: limit.rlim_cur = i * factor; ! 120: ! 121: if (!softonly) ! 122: limit.rlim_max = limit.rlim_cur; ! 123: ! 124: if (setrlimit(command, &limit)) ! 125: goto Error; ! 126: } ! 127: else ! 128: { ! 129: i = softonly ? limit.rlim_cur : limit.rlim_max; ! 130: #if _BSD /* DAG -- System V always prints an integer */ ! 131: if (i == RLIM_INFINITY) ! 132: shellf("unlimited\n"); ! 133: else ! 134: #endif ! 135: shellf("%ld\n", i/factor); ! 136: } ! 137: #endif /* _BSD || _BSD_SYSV */ ! 138: return 0; ! 139: ! 140: Error: ! 141: errorf("bad ulimit\n"); ! 142: } ! 143:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.