14b88c807SRodney W. Grimes /*- 24b88c807SRodney W. Grimes * Copyright (c) 1991, 1993 34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes * 54b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes * Kenneth Almquist. 74b88c807SRodney W. Grimes * 84b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes * are met: 114b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 174b88c807SRodney W. Grimes * must display the following acknowledgement: 184b88c807SRodney W. Grimes * This product includes software developed by the University of 194b88c807SRodney W. Grimes * California, Berkeley and its contributors. 204b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 214b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 224b88c807SRodney W. Grimes * without specific prior written permission. 234b88c807SRodney W. Grimes * 244b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 254b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 264b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 274b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 284b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 294b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 304b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 314b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 324b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 334b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 344b88c807SRodney W. Grimes * SUCH DAMAGE. 3589730b29SDavid Greenman * 364e4e0959SPeter Wemm * $Id: miscbltin.c,v 1.7 1996/09/03 14:15:54 peter Exp $ 374b88c807SRodney W. Grimes */ 384b88c807SRodney W. Grimes 394b88c807SRodney W. Grimes #ifndef lint 40aa9caaf6SPeter Wemm static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; 414b88c807SRodney W. Grimes #endif /* not lint */ 424b88c807SRodney W. Grimes 434b88c807SRodney W. Grimes /* 444b88c807SRodney W. Grimes * Miscelaneous builtins. 454b88c807SRodney W. Grimes */ 464b88c807SRodney W. Grimes 47aa9caaf6SPeter Wemm #include <sys/types.h> 48aa9caaf6SPeter Wemm #include <sys/stat.h> 49aa9caaf6SPeter Wemm #include <sys/time.h> 50aa9caaf6SPeter Wemm #include <sys/resource.h> 51aa9caaf6SPeter Wemm #include <unistd.h> 52aa9caaf6SPeter Wemm #include <ctype.h> 5316992ff4SPeter Wemm #include <errno.h> 544417f629SPeter Wemm #include <stdio.h> 55aa9caaf6SPeter Wemm 564b88c807SRodney W. Grimes #include "shell.h" 574b88c807SRodney W. Grimes #include "options.h" 584b88c807SRodney W. Grimes #include "var.h" 594b88c807SRodney W. Grimes #include "output.h" 604b88c807SRodney W. Grimes #include "memalloc.h" 614b88c807SRodney W. Grimes #include "error.h" 624b88c807SRodney W. Grimes #include "mystring.h" 634b88c807SRodney W. Grimes 644b88c807SRodney W. Grimes #undef eflag 654b88c807SRodney W. Grimes 664b88c807SRodney W. Grimes extern char **argptr; /* argument list for builtin command */ 674b88c807SRodney W. Grimes 684b88c807SRodney W. Grimes 694b88c807SRodney W. Grimes /* 704b88c807SRodney W. Grimes * The read builtin. The -e option causes backslashes to escape the 714b88c807SRodney W. Grimes * following character. 724b88c807SRodney W. Grimes * 734b88c807SRodney W. Grimes * This uses unbuffered input, which may be avoidable in some cases. 744b88c807SRodney W. Grimes */ 754b88c807SRodney W. Grimes 76aa9caaf6SPeter Wemm int 77aa9caaf6SPeter Wemm readcmd(argc, argv) 78aa9caaf6SPeter Wemm int argc; 79aa9caaf6SPeter Wemm char **argv; 80aa9caaf6SPeter Wemm { 814b88c807SRodney W. Grimes char **ap; 824b88c807SRodney W. Grimes int backslash; 834b88c807SRodney W. Grimes char c; 844b88c807SRodney W. Grimes int eflag; 854b88c807SRodney W. Grimes char *prompt; 864b88c807SRodney W. Grimes char *ifs; 874b88c807SRodney W. Grimes char *p; 884b88c807SRodney W. Grimes int startword; 894b88c807SRodney W. Grimes int status; 904b88c807SRodney W. Grimes int i; 914b88c807SRodney W. Grimes 924b88c807SRodney W. Grimes eflag = 0; 934b88c807SRodney W. Grimes prompt = NULL; 944b88c807SRodney W. Grimes while ((i = nextopt("ep:")) != '\0') { 954b88c807SRodney W. Grimes if (i == 'p') 964b88c807SRodney W. Grimes prompt = optarg; 974b88c807SRodney W. Grimes else 984b88c807SRodney W. Grimes eflag = 1; 994b88c807SRodney W. Grimes } 1004b88c807SRodney W. Grimes if (prompt && isatty(0)) { 1014b88c807SRodney W. Grimes out2str(prompt); 1024b88c807SRodney W. Grimes flushall(); 1034b88c807SRodney W. Grimes } 1044b88c807SRodney W. Grimes if (*(ap = argptr) == NULL) 1054b88c807SRodney W. Grimes error("arg count"); 1064b88c807SRodney W. Grimes if ((ifs = bltinlookup("IFS", 1)) == NULL) 1074b88c807SRodney W. Grimes ifs = nullstr; 1084b88c807SRodney W. Grimes status = 0; 1094b88c807SRodney W. Grimes startword = 1; 1104b88c807SRodney W. Grimes backslash = 0; 1114b88c807SRodney W. Grimes STARTSTACKSTR(p); 1124b88c807SRodney W. Grimes for (;;) { 1134b88c807SRodney W. Grimes if (read(0, &c, 1) != 1) { 1144b88c807SRodney W. Grimes status = 1; 1154b88c807SRodney W. Grimes break; 1164b88c807SRodney W. Grimes } 1174b88c807SRodney W. Grimes if (c == '\0') 1184b88c807SRodney W. Grimes continue; 1194b88c807SRodney W. Grimes if (backslash) { 1204b88c807SRodney W. Grimes backslash = 0; 1214b88c807SRodney W. Grimes if (c != '\n') 1224b88c807SRodney W. Grimes STPUTC(c, p); 1234b88c807SRodney W. Grimes continue; 1244b88c807SRodney W. Grimes } 1254b88c807SRodney W. Grimes if (eflag && c == '\\') { 1264b88c807SRodney W. Grimes backslash++; 1274b88c807SRodney W. Grimes continue; 1284b88c807SRodney W. Grimes } 1294b88c807SRodney W. Grimes if (c == '\n') 1304b88c807SRodney W. Grimes break; 1314b88c807SRodney W. Grimes if (startword && *ifs == ' ' && strchr(ifs, c)) { 1324b88c807SRodney W. Grimes continue; 1334b88c807SRodney W. Grimes } 1344b88c807SRodney W. Grimes startword = 0; 1354b88c807SRodney W. Grimes if (backslash && c == '\\') { 1364b88c807SRodney W. Grimes if (read(0, &c, 1) != 1) { 1374b88c807SRodney W. Grimes status = 1; 1384b88c807SRodney W. Grimes break; 1394b88c807SRodney W. Grimes } 1404b88c807SRodney W. Grimes STPUTC(c, p); 1414b88c807SRodney W. Grimes } else if (ap[1] != NULL && strchr(ifs, c) != NULL) { 1424b88c807SRodney W. Grimes STACKSTRNUL(p); 1434b88c807SRodney W. Grimes setvar(*ap, stackblock(), 0); 1444b88c807SRodney W. Grimes ap++; 1454b88c807SRodney W. Grimes startword = 1; 1464b88c807SRodney W. Grimes STARTSTACKSTR(p); 1474b88c807SRodney W. Grimes } else { 1484b88c807SRodney W. Grimes STPUTC(c, p); 1494b88c807SRodney W. Grimes } 1504b88c807SRodney W. Grimes } 1514b88c807SRodney W. Grimes STACKSTRNUL(p); 1524b88c807SRodney W. Grimes setvar(*ap, stackblock(), 0); 1534b88c807SRodney W. Grimes while (*++ap != NULL) 1544b88c807SRodney W. Grimes setvar(*ap, nullstr, 0); 1554b88c807SRodney W. Grimes return status; 1564b88c807SRodney W. Grimes } 1574b88c807SRodney W. Grimes 1584b88c807SRodney W. Grimes 1594b88c807SRodney W. Grimes 160aa9caaf6SPeter Wemm int 161aa9caaf6SPeter Wemm umaskcmd(argc, argv) 162aa9caaf6SPeter Wemm int argc; 163aa9caaf6SPeter Wemm char **argv; 164aa9caaf6SPeter Wemm { 165aa9caaf6SPeter Wemm char *ap; 1664b88c807SRodney W. Grimes int mask; 1674b88c807SRodney W. Grimes int i; 168aa9caaf6SPeter Wemm int symbolic_mode = 0; 1694b88c807SRodney W. Grimes 170aa9caaf6SPeter Wemm while ((i = nextopt("S")) != '\0') { 171aa9caaf6SPeter Wemm symbolic_mode = 1; 172aa9caaf6SPeter Wemm } 173aa9caaf6SPeter Wemm 1744b88c807SRodney W. Grimes INTOFF; 1754b88c807SRodney W. Grimes mask = umask(0); 1764b88c807SRodney W. Grimes umask(mask); 1774b88c807SRodney W. Grimes INTON; 178aa9caaf6SPeter Wemm 179aa9caaf6SPeter Wemm if ((ap = *argptr) == NULL) { 180aa9caaf6SPeter Wemm if (symbolic_mode) { 181aa9caaf6SPeter Wemm char u[4], g[4], o[4]; 182aa9caaf6SPeter Wemm 183aa9caaf6SPeter Wemm i = 0; 184aa9caaf6SPeter Wemm if ((mask & S_IRUSR) == 0) 185aa9caaf6SPeter Wemm u[i++] = 'r'; 186aa9caaf6SPeter Wemm if ((mask & S_IWUSR) == 0) 187aa9caaf6SPeter Wemm u[i++] = 'w'; 188aa9caaf6SPeter Wemm if ((mask & S_IXUSR) == 0) 189aa9caaf6SPeter Wemm u[i++] = 'x'; 190aa9caaf6SPeter Wemm u[i] = '\0'; 191aa9caaf6SPeter Wemm 192aa9caaf6SPeter Wemm i = 0; 193aa9caaf6SPeter Wemm if ((mask & S_IRGRP) == 0) 194aa9caaf6SPeter Wemm g[i++] = 'r'; 195aa9caaf6SPeter Wemm if ((mask & S_IWGRP) == 0) 196aa9caaf6SPeter Wemm g[i++] = 'w'; 197aa9caaf6SPeter Wemm if ((mask & S_IXGRP) == 0) 198aa9caaf6SPeter Wemm g[i++] = 'x'; 199aa9caaf6SPeter Wemm g[i] = '\0'; 200aa9caaf6SPeter Wemm 201aa9caaf6SPeter Wemm i = 0; 202aa9caaf6SPeter Wemm if ((mask & S_IROTH) == 0) 203aa9caaf6SPeter Wemm o[i++] = 'r'; 204aa9caaf6SPeter Wemm if ((mask & S_IWOTH) == 0) 205aa9caaf6SPeter Wemm o[i++] = 'w'; 206aa9caaf6SPeter Wemm if ((mask & S_IXOTH) == 0) 207aa9caaf6SPeter Wemm o[i++] = 'x'; 208aa9caaf6SPeter Wemm o[i] = '\0'; 209aa9caaf6SPeter Wemm 210aa9caaf6SPeter Wemm out1fmt("u=%s,g=%s,o=%s\n", u, g, o); 2114b88c807SRodney W. Grimes } else { 212aa9caaf6SPeter Wemm out1fmt("%.4o\n", mask); 213aa9caaf6SPeter Wemm } 214aa9caaf6SPeter Wemm } else { 215aa9caaf6SPeter Wemm if (isdigit(*ap)) { 2164b88c807SRodney W. Grimes mask = 0; 2174b88c807SRodney W. Grimes do { 218aa9caaf6SPeter Wemm if (*ap >= '8' || *ap < '0') 2194b88c807SRodney W. Grimes error("Illegal number: %s", argv[1]); 220aa9caaf6SPeter Wemm mask = (mask << 3) + (*ap - '0'); 221aa9caaf6SPeter Wemm } while (*++ap != '\0'); 2224b88c807SRodney W. Grimes umask(mask); 223aa9caaf6SPeter Wemm } else { 224aa9caaf6SPeter Wemm void *set; 225aa9caaf6SPeter Wemm if ((set = setmode (ap)) == 0) 226aa9caaf6SPeter Wemm error("Illegal number: %s", ap); 227aa9caaf6SPeter Wemm 228aa9caaf6SPeter Wemm mask = getmode (set, ~mask & 0777); 229aa9caaf6SPeter Wemm umask(~mask & 0777); 230aa9caaf6SPeter Wemm } 2314b88c807SRodney W. Grimes } 2324b88c807SRodney W. Grimes return 0; 2334b88c807SRodney W. Grimes } 2347a2afe64SJoerg Wunsch 235aa9caaf6SPeter Wemm /* 236aa9caaf6SPeter Wemm * ulimit builtin 237aa9caaf6SPeter Wemm * 238aa9caaf6SPeter Wemm * This code, originally by Doug Gwyn, Doug Kingston, Eric Gisin, and 239aa9caaf6SPeter Wemm * Michael Rendell was ripped from pdksh 5.0.8 and hacked for use with 240aa9caaf6SPeter Wemm * ash by J.T. Conklin. 241aa9caaf6SPeter Wemm * 242aa9caaf6SPeter Wemm * Public domain. 243aa9caaf6SPeter Wemm */ 2447a2afe64SJoerg Wunsch 245aa9caaf6SPeter Wemm struct limits { 246aa9caaf6SPeter Wemm const char *name; 24716992ff4SPeter Wemm const char *units; 248aa9caaf6SPeter Wemm int cmd; 249aa9caaf6SPeter Wemm int factor; /* multiply by to get rlim_{cur,max} values */ 250aa9caaf6SPeter Wemm char option; 2517a2afe64SJoerg Wunsch }; 2527a2afe64SJoerg Wunsch 253aa9caaf6SPeter Wemm static const struct limits limits[] = { 254aa9caaf6SPeter Wemm #ifdef RLIMIT_CPU 25516992ff4SPeter Wemm { "cpu time", "seconds", RLIMIT_CPU, 1, 't' }, 256aa9caaf6SPeter Wemm #endif 257aa9caaf6SPeter Wemm #ifdef RLIMIT_FSIZE 25816992ff4SPeter Wemm { "file size", "512-blocks", RLIMIT_FSIZE, 512, 'f' }, 259aa9caaf6SPeter Wemm #endif 260aa9caaf6SPeter Wemm #ifdef RLIMIT_DATA 26116992ff4SPeter Wemm { "data seg size", "kbytes", RLIMIT_DATA, 1024, 'd' }, 262aa9caaf6SPeter Wemm #endif 263aa9caaf6SPeter Wemm #ifdef RLIMIT_STACK 26416992ff4SPeter Wemm { "stack size", "kbytes", RLIMIT_STACK, 1024, 's' }, 265aa9caaf6SPeter Wemm #endif 266aa9caaf6SPeter Wemm #ifdef RLIMIT_CORE 26716992ff4SPeter Wemm { "core file size", "512-blocks", RLIMIT_CORE, 512, 'c' }, 268aa9caaf6SPeter Wemm #endif 269aa9caaf6SPeter Wemm #ifdef RLIMIT_RSS 27016992ff4SPeter Wemm { "max memory size", "kbytes", RLIMIT_RSS, 1024, 'm' }, 271aa9caaf6SPeter Wemm #endif 272aa9caaf6SPeter Wemm #ifdef RLIMIT_MEMLOCK 27316992ff4SPeter Wemm { "locked memory", "kbytes", RLIMIT_MEMLOCK, 1024, 'l' }, 274aa9caaf6SPeter Wemm #endif 275aa9caaf6SPeter Wemm #ifdef RLIMIT_NPROC 27616992ff4SPeter Wemm { "max user processes", (char *)0, RLIMIT_NPROC, 1, 'u' }, 277aa9caaf6SPeter Wemm #endif 278aa9caaf6SPeter Wemm #ifdef RLIMIT_NOFILE 27916992ff4SPeter Wemm { "open files", (char *)0, RLIMIT_NOFILE, 1, 'n' }, 280aa9caaf6SPeter Wemm #endif 281aa9caaf6SPeter Wemm #ifdef RLIMIT_VMEM 28216992ff4SPeter Wemm { "virtual mem size", "kbytes", RLIMIT_VMEM, 1024, 'v' }, 283aa9caaf6SPeter Wemm #endif 284aa9caaf6SPeter Wemm #ifdef RLIMIT_SWAP 28516992ff4SPeter Wemm { "swap limit", "kbytes", RLIMIT_SWAP, 1024, 'w' }, 286aa9caaf6SPeter Wemm #endif 28716992ff4SPeter Wemm { (char *) 0, (char *)0, 0, 0, '\0' } 2887a2afe64SJoerg Wunsch }; 2897a2afe64SJoerg Wunsch 290aa9caaf6SPeter Wemm int 291aa9caaf6SPeter Wemm ulimitcmd(argc, argv) 292aa9caaf6SPeter Wemm int argc; 293aa9caaf6SPeter Wemm char **argv; 294aa9caaf6SPeter Wemm { 295aa9caaf6SPeter Wemm register int c; 2964417f629SPeter Wemm quad_t val = 0; 297aa9caaf6SPeter Wemm enum { SOFT = 0x1, HARD = 0x2 } 298aa9caaf6SPeter Wemm how = SOFT | HARD; 299aa9caaf6SPeter Wemm const struct limits *l; 300aa9caaf6SPeter Wemm int set, all = 0; 301aa9caaf6SPeter Wemm int optc, what; 302aa9caaf6SPeter Wemm struct rlimit limit; 3037a2afe64SJoerg Wunsch 304aa9caaf6SPeter Wemm what = 'f'; 30516992ff4SPeter Wemm while ((optc = nextopt("HSatfdsmcnul")) != '\0') 306aa9caaf6SPeter Wemm switch (optc) { 3077a2afe64SJoerg Wunsch case 'H': 308aa9caaf6SPeter Wemm how = HARD; 3097a2afe64SJoerg Wunsch break; 3107a2afe64SJoerg Wunsch case 'S': 311aa9caaf6SPeter Wemm how = SOFT; 3127a2afe64SJoerg Wunsch break; 3137a2afe64SJoerg Wunsch case 'a': 314aa9caaf6SPeter Wemm all = 1; 3157a2afe64SJoerg Wunsch break; 316aa9caaf6SPeter Wemm default: 317aa9caaf6SPeter Wemm what = optc; 3187a2afe64SJoerg Wunsch } 3197a2afe64SJoerg Wunsch 320aa9caaf6SPeter Wemm for (l = limits; l->name && l->option != what; l++) 321aa9caaf6SPeter Wemm ; 322aa9caaf6SPeter Wemm if (!l->name) 32316992ff4SPeter Wemm error("internal error (%c)", what); 3247a2afe64SJoerg Wunsch 325aa9caaf6SPeter Wemm set = *argptr ? 1 : 0; 326aa9caaf6SPeter Wemm if (set) { 327aa9caaf6SPeter Wemm char *p = *argptr; 328aa9caaf6SPeter Wemm 329aa9caaf6SPeter Wemm if (all || argptr[1]) 33016992ff4SPeter Wemm error("too many arguments"); 331aa9caaf6SPeter Wemm if (strcmp(p, "unlimited") == 0) 3327a2afe64SJoerg Wunsch val = RLIM_INFINITY; 3337a2afe64SJoerg Wunsch else { 334aa9caaf6SPeter Wemm val = (quad_t) 0; 335aa9caaf6SPeter Wemm 336aa9caaf6SPeter Wemm while ((c = *p++) >= '0' && c <= '9') 337aa9caaf6SPeter Wemm { 338aa9caaf6SPeter Wemm val = (val * 10) + (long)(c - '0'); 339aa9caaf6SPeter Wemm if (val < (quad_t) 0) 340aa9caaf6SPeter Wemm break; 3417a2afe64SJoerg Wunsch } 342aa9caaf6SPeter Wemm if (c) 34316992ff4SPeter Wemm error("bad number"); 344aa9caaf6SPeter Wemm val *= l->factor; 345aa9caaf6SPeter Wemm } 346aa9caaf6SPeter Wemm } 347aa9caaf6SPeter Wemm if (all) { 348aa9caaf6SPeter Wemm for (l = limits; l->name; l++) { 34916992ff4SPeter Wemm char optbuf[40]; 35016992ff4SPeter Wemm if (getrlimit(l->cmd, &limit) < 0) 35116992ff4SPeter Wemm error("can't get limit: %s", strerror(errno)); 352aa9caaf6SPeter Wemm if (how & SOFT) 353aa9caaf6SPeter Wemm val = limit.rlim_cur; 354aa9caaf6SPeter Wemm else if (how & HARD) 355aa9caaf6SPeter Wemm val = limit.rlim_max; 356aa9caaf6SPeter Wemm 35716992ff4SPeter Wemm if (l->units) 35816992ff4SPeter Wemm snprintf(optbuf, sizeof(optbuf), 3594e4e0959SPeter Wemm "(%s, -%c) ", l->units, l->option); 36016992ff4SPeter Wemm else 36116992ff4SPeter Wemm snprintf(optbuf, sizeof(optbuf), 3624e4e0959SPeter Wemm "(-%c) ", l->option); 3634e4e0959SPeter Wemm out1fmt("%-18s %18s ", l->name, optbuf); 364aa9caaf6SPeter Wemm if (val == RLIM_INFINITY) 365aa9caaf6SPeter Wemm out1fmt("unlimited\n"); 366aa9caaf6SPeter Wemm else 367aa9caaf6SPeter Wemm { 368aa9caaf6SPeter Wemm val /= l->factor; 3694417f629SPeter Wemm out1fmt("%qd\n", (quad_t) val); 3707a2afe64SJoerg Wunsch } 3717a2afe64SJoerg Wunsch } 3727a2afe64SJoerg Wunsch return 0; 3737a2afe64SJoerg Wunsch } 374aa9caaf6SPeter Wemm 37516992ff4SPeter Wemm if (getrlimit(l->cmd, &limit) < 0) 37616992ff4SPeter Wemm error("can't get limit: %s", strerror(errno)); 377aa9caaf6SPeter Wemm if (set) { 378aa9caaf6SPeter Wemm if (how & SOFT) 379aa9caaf6SPeter Wemm limit.rlim_cur = val; 380aa9caaf6SPeter Wemm if (how & HARD) 381aa9caaf6SPeter Wemm limit.rlim_max = val; 382aa9caaf6SPeter Wemm if (setrlimit(l->cmd, &limit) < 0) 38316992ff4SPeter Wemm error("bad limit: %s", strerror(errno)); 384aa9caaf6SPeter Wemm } else { 385aa9caaf6SPeter Wemm if (how & SOFT) 386aa9caaf6SPeter Wemm val = limit.rlim_cur; 387aa9caaf6SPeter Wemm else if (how & HARD) 388aa9caaf6SPeter Wemm val = limit.rlim_max; 389aa9caaf6SPeter Wemm } 390aa9caaf6SPeter Wemm 391aa9caaf6SPeter Wemm if (!set) { 392aa9caaf6SPeter Wemm if (val == RLIM_INFINITY) 393aa9caaf6SPeter Wemm out1fmt("unlimited\n"); 394aa9caaf6SPeter Wemm else 395aa9caaf6SPeter Wemm { 396aa9caaf6SPeter Wemm val /= l->factor; 3974417f629SPeter Wemm out1fmt("%qd\n", (quad_t) val); 398aa9caaf6SPeter Wemm } 399aa9caaf6SPeter Wemm } 400aa9caaf6SPeter Wemm return 0; 401aa9caaf6SPeter Wemm } 402