rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit e354cf4fd756584239e7778217ee8860009e6728
parent bc11ebf09feec23608459c8e632f30369c6bae49
Author: Toby Goodwin <tjg@star.le.ac.uk>
Date:   Fri,  8 Feb 2002 14:48:47 +0000

candidate: rc-1.6c6

Diffstat:
MChangeLog | 11+++++++++++
MNEWS | 7++++---
MREADME | 4++--
Mbuiltins.c | 79++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mconfigure.ac | 2+-
Mexec.c | 5+++++
Mexecve.c | 3++-
Minput.c | 3++-
Mrc.1 | 11+++--------
Mrlimit.h | 11+++++++++++
Msystem-bsd.c | 3++-
Mwait.c | 1-
12 files changed, 87 insertions(+), 53 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -757,3 +757,14 @@ Changes since rc-1.5b2 more examples. Release: rc-1.6c5. + +2001-11-23 + + Bug: parselimit() was broken in various ways (thanks Chris + Siebenmann). + +2002-02-08 + + Bug: yet more wrongly ordered header file includes. + + Release: rc-1.6c6. diff --git a/NEWS b/NEWS @@ -7,12 +7,13 @@ Bug fixes. A number of bugs have been fixed. The serious ones were: a core dump, triggered by `~ () '*''; premature exit, triggered by sourcing a file which could be open()ed but not read() (such as a directory on many systems); uninterruptible looping, triggered by -semantic errors in `fn prompt'. +semantic errors in `fn prompt'; deficiencies in the `limit' builtin. New features. The following features are new: the `$version' variable replaces the `-V' flag; the `-I' flag (definitively not interactive) was added for compatibility with the Plan 9 rc; ASCII SOH (^A) is now -handled transparently. +handled transparently; support for large files; support for more +limits. Documentation. Distributions of this rc used to include a PostScript paper given by Tom Duff to the UKUUG, describing the Plan 9 rc. This @@ -21,4 +22,4 @@ the web, both in its original PostScript version, and an updated HTML version. Tim Goodwin -2001-10-05 +2002-02-08 diff --git a/README b/README @@ -1,8 +1,8 @@ -This is release candidate rc-1.6c5. +This is release candidate rc-1.6c6. See COPYING for copying information. All files are - Copyright 1991, 2001 Byron Rakitzis. + Copyright 1991, 2001, 2002 Byron Rakitzis. See INSTALL for build and installation information. diff --git a/builtins.c b/builtins.c @@ -423,14 +423,7 @@ static void b_newpgrp(char **av) { /* Berkeley limit support was cleaned up by Paul Haahr. */ #if HAVE_SETRLIMIT -typedef struct Suffix Suffix; -struct Suffix { - const Suffix *next; - long amount; - char *name; -}; - -static const Suffix +static const struct Suffix kbsuf = { NULL, 1024, "k" }, mbsuf = { &kbsuf, 1024*1024, "m" }, gbsuf = { &mbsuf, 1024*1024*1024, "g" }, @@ -439,32 +432,39 @@ static const Suffix htsuf = { &mtsuf, 60*60, "h" }; #define SIZESUF &gbsuf #define TIMESUF &htsuf -#define NOSUF ((Suffix *) NULL) /* for RLIMIT_NOFILE on SunOS 4.1 */ +#define NOSUF ((struct Suffix *) NULL) /* for RLIMIT_NOFILE on SunOS 4.1 */ -typedef struct { - char *name; - int flag; - const Suffix *suffix; -} Limit; -static const Limit limits[] = { +static const struct Limit limits[] = { { "cputime", RLIMIT_CPU, TIMESUF }, { "filesize", RLIMIT_FSIZE, SIZESUF }, { "datasize", RLIMIT_DATA, SIZESUF }, { "stacksize", RLIMIT_STACK, SIZESUF }, { "coredumpsize", RLIMIT_CORE, SIZESUF }, -#ifdef RLIMIT_RSS /* SysVr4 does not have this */ - { "memoryuse", RLIMIT_RSS, SIZESUF }, +#ifdef RLIMIT_NOFILE /* SUSv2, but not universal */ + { "descriptors", RLIMIT_NOFILE, NOSUF }, #endif -#ifdef RLIMIT_VMEM /* instead, they have this! */ - { "vmemory", RLIMIT_VMEM, SIZESUF }, +#ifdef RLIMIT_AS /* SUSv2, but not universal */ + { "memoryuse", RLIMIT_AS, SIZESUF }, #endif -#ifdef RLIMIT_NOFILE /* SunOS 4.1 adds a limit on file descriptors */ - { "descriptors", RLIMIT_NOFILE, NOSUF }, +#if defined(RLIMIT_VMEM) && !defined(RLIMIT_AS) /* old name for AS */ + { "memoryuse", RLIMIT_VMEM, SIZESUF }, +#endif +#ifdef RLIMIT_RSS + { "memoryrss", RLIMIT_RSS, SIZESUF }, +#endif +#ifdef RLIMIT_NPROC + { "maxproc", RLIMIT_NPROC, NOSUF }, +#endif +#ifdef RLIMIT_MEMLOCK + { "memorylocked", RLIMIT_MEMLOCK, SIZESUF }, +#endif +#ifdef RLIMIT_LOCKS + { "filelocks", RLIMIT_LOCKS, NOSUF }, #endif { NULL, 0, NULL } }; -static void printlimit(const Limit *limit, bool hard) { +static void printlimit(const struct Limit *limit, bool hard) { struct rlimit rlim; rlim_t lim; getrlimit(limit->flag, &rlim); @@ -475,7 +475,7 @@ static void printlimit(const Limit *limit, bool hard) { if (lim == RLIM_INFINITY) fprint(1, "%s \tunlimited\n", limit->name); else { - const Suffix *suf; + const struct Suffix *suf; for (suf = limit->suffix; suf != NULL; suf = suf->next) if (lim % suf->amount == 0 && (lim != 0 || suf->amount > 1)) { lim /= suf->amount; @@ -485,30 +485,39 @@ static void printlimit(const Limit *limit, bool hard) { } } -static rlim_t parselimit(const Limit *limit, char *s) { +static bool parselimit(const struct Limit *resource, rlim_t *limit, char *s) { char *t; int len = strlen(s); - long lim = 1; - const Suffix *suf = limit->suffix; - if (streq(s, "unlimited")) - return RLIM_INFINITY; + const struct Suffix *suf = resource->suffix; + + *limit = 1; + if (streq(s, "unlimited")) { + *limit = RLIM_INFINITY; + return TRUE; + } if (suf == TIMESUF && (t = strchr(s, ':')) != NULL) { + int min, sec; *t++ = '\0'; - lim = 60 * a2u(s) + a2u(t); + min = a2u(s); sec = a2u(t); + if (min == -1 || sec == -1) return FALSE; + *limit = 60 * min + sec; } else { + int n; for (; suf != NULL; suf = suf->next) if (streq(suf->name, s + len - strlen(suf->name))) { s[len - strlen(suf->name)] = '\0'; - lim *= suf->amount; + *limit *= suf->amount; break; } - lim *= a2u(s); + n = a2u(s); + if (n == -1) return FALSE; + *limit *= n; } - return lim; + return TRUE; } static void b_limit(char **av) { - const Limit *lp = limits; + const struct Limit *lp = limits; bool hard = FALSE; if (*++av != NULL && streq(*av, "-h")) { av++; @@ -532,9 +541,9 @@ static void b_limit(char **av) { printlimit(lp, hard); else { struct rlimit rlim; - long pl; + rlim_t pl; getrlimit(lp->flag, &rlim); - if ((pl = parselimit(lp, *av)) < 0) { + if (!parselimit(lp, &pl, *av)) { fprint(2, "bad limit\n"); set(FALSE); return; diff --git a/configure.ac b/configure.ac @@ -8,7 +8,7 @@ dnl Automake stuff. dnl Use this one for snapshots... dnl AM_INIT_AUTOMAKE(rc, 1.6s`echo $RELDATE |sed 's/-//g'`) dnl ...and this one for releases -AM_INIT_AUTOMAKE(rc, 1.6c5) +AM_INIT_AUTOMAKE(rc, 1.6c6) AM_CONFIG_HEADER(config.h) diff --git a/exec.c b/exec.c @@ -7,6 +7,11 @@ #include "wait.h" +#include <errno.h> +#include <signal.h> + +#include "wait.h" + #include "rc.h" #include "wait.h" /* diff --git a/execve.c b/execve.c @@ -5,9 +5,10 @@ spots before av[][] so that execve does not have to call malloc. */ -#include <errno.h> #include "rc.h" +#include <errno.h> + #define giveupif(x) { if (x) goto fail; } extern int rc_execve(char *path, char **av, char **ev) { diff --git a/input.c b/input.c @@ -1,8 +1,9 @@ /* input.c: i/o routines for files and pseudo-files (strings) */ +#include "rc.h" + #include <errno.h> -#include "rc.h" #include "jbwrap.h" /* diff --git a/rc.1 b/rc.1 @@ -161,7 +161,7 @@ .if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" .if "\\$4"" \\$3\fR\s10 .. -.TH RC 1 "2001-11-20" +.TH RC 1 "2002-02-08" .SH NAME rc \- shell .SH SYNOPSIS @@ -1273,11 +1273,6 @@ prints .Cr "bqstatus=1" .De .TP -.Cr bqstatus -The exit status of the -.I rc -forked to execute the most recent backquote substitution. -.TP .Cr cdpath A list of directories to search for the target of a .B cd @@ -1429,9 +1424,9 @@ The first element of this list variable is a string which identifies this version of .IR rc . The second element is a string which can be found by -.IR ident +.B ident and -.IR "sccs what" . +.BR "sccs what" . .PP The values of .Cr "$path" , diff --git a/rlimit.h b/rlimit.h @@ -39,4 +39,15 @@ typedef long rlim_t; #define RLIMIT_NOFILE RLIMIT_OFILE #endif +struct Suffix { + const struct Suffix *next; + long amount; + char *name; +}; + +struct Limit { + char *name; + int flag; + const struct Suffix *suffix; +}; #endif /* HAVE_SETRLIMIT */ diff --git a/system-bsd.c b/system-bsd.c @@ -1,9 +1,10 @@ /* signal-safe read and write (for BSD slow devices). writeall() also allows partial writes */ +#include "rc.h" + #include <errno.h> -#include "rc.h" #include "jbwrap.h" #include "wait.h" diff --git a/wait.c b/wait.c @@ -1,6 +1,5 @@ #include <errno.h> -#include "rc.h" #include "wait.h" bool forked = FALSE;