about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Builtins/rlimits.awk62
-rw-r--r--Src/Builtins/rlimits.c35
-rw-r--r--Src/Builtins/rlimits.mdd10
3 files changed, 55 insertions, 52 deletions
diff --git a/Src/Builtins/rlimits.awk b/Src/Builtins/rlimits.awk
index 56bd574e0..9d412eded 100644
--- a/Src/Builtins/rlimits.awk
+++ b/Src/Builtins/rlimits.awk
@@ -6,7 +6,7 @@
 #
 BEGIN {limidx = 0}
 
-/^[\t ]*(#[\t ]*define[\t _]*RLIMIT_[A-Z_]*[\t ]*[0-9][0-9]*|RLIMIT_[A-Z]*,[\t ]*)/ {
+/^[\t ]*(#[\t ]*define[\t _]*RLIMIT_[A-Z_]*[\t ]*[0-9][0-9]*|RLIMIT_[A-Z_]*,[\t ]*)/ {
     limindex = index($0, "RLIMIT_")
     limtail = substr($0, limindex, 80)
     split(limtail, tmp)
@@ -22,22 +22,22 @@ BEGIN {limidx = 0}
     if (lim[limnum] == "") {
 	lim[limnum] = limnam
 	if (limnum ~ /^[0-9]*$/) {
-	    if (limnam == "MEMLOCK") { msg[limnum] = "memorylocked" }
-	    if (limnam == "RSS")     { msg[limnum] = "resident" }
-	    if (limnam == "VMEM")    { msg[limnum] = "vmemorysize" }
-	    if (limnam == "NOFILE")  { msg[limnum] = "descriptors" }
-	    if (limnam == "OFILE")   { msg[limnum] = "descriptors" }
-	    if (limnam == "CORE")    { msg[limnum] = "coredumpsize" }
-	    if (limnam == "STACK")   { msg[limnum] = "stacksize" }
-	    if (limnam == "DATA")    { msg[limnum] = "datasize" }
-	    if (limnam == "FSIZE")   { msg[limnum] = "filesize" }
-	    if (limnam == "CPU")     { msg[limnum] = "cputime" }
-	    if (limnam == "NPROC")   { msg[limnum] = "maxproc" }
-	    if (limnam == "AS")      { msg[limnum] = "addressspace" }
-	    if (limnam == "TCACHE")  { msg[limnum] = "cachedthreads" }
-	    if (limnam == "AIO_OPS") { msg[limnum] = "aiooperations" }
-	    if (limnam == "AIO_MEM") { msg[limnum] = "aiomemorylocked" }
-	    if (limnam == "SBSIZE")  { msg[limnum] = "sbsize" }
+	    if (limnam == "AIO_MEM") { msg[limnum] = "Maiomemorylocked" }
+	    if (limnam == "AIO_OPS") { msg[limnum] = "Naiooperations" }
+	    if (limnam == "AS")      { msg[limnum] = "Maddressspace" }
+	    if (limnam == "CORE")    { msg[limnum] = "Mcoredumpsize" }
+	    if (limnam == "CPU")     { msg[limnum] = "Tcputime" }
+	    if (limnam == "DATA")    { msg[limnum] = "Mdatasize" }
+	    if (limnam == "FSIZE")   { msg[limnum] = "Mfilesize" }
+	    if (limnam == "MEMLOCK") { msg[limnum] = "Mmemorylocked" }
+	    if (limnam == "NOFILE")  { msg[limnum] = "Ndescriptors" }
+	    if (limnam == "NPROC")   { msg[limnum] = "Nmaxproc" }
+	    if (limnam == "OFILE")   { msg[limnum] = "Ndescriptors" }
+	    if (limnam == "RSS")     { msg[limnum] = "Mresident" }
+	    if (limnam == "SBSIZE")  { msg[limnum] = "Msktbuffersize" }
+	    if (limnam == "STACK")   { msg[limnum] = "Mstacksize" }
+	    if (limnam == "TCACHE")  { msg[limnum] = "Ncachedthreads" }
+	    if (limnam == "VMEM")    { msg[limnum] = "Mvmemorysize" }
         }
     }
 }
@@ -55,21 +55,33 @@ BEGIN {limidx = 0}
 END {
     if (limrev["MEMLOCK"] != "") {
         irss = limrev["RSS"]
-        msg[irss] = "memoryuse"
+        msg[irss] = "Mmemoryuse"
     }
     ps = "%s"
 
     printf("%s\n%s\n\n", "/** rlimits.h                              **/", "/** architecture-customized limits for zsh **/")
-    printf("#define ZSH_NLIMITS %d\n\nstatic char *recs[ZSH_NLIMITS+1] = {\n", 0 + nlimits)
+    printf("#define ZSH_NLIMITS %d\n\nstatic char const *recs[ZSH_NLIMITS] = {\n", 0 + nlimits)
 
     for (i = 0; i < 0 + nlimits; i++)
-	if (msg[i] == "") {
-            badlimit++
+	if (msg[i] == "")
             printf("\t%c%s%c,\n", 34, lim[i], 34)
-	} else
-	    printf("\t%c%s%c,\n", 34, msg[i], 34)
-    print "\tNULL"
+	else
+	    printf("\t%c%s%c,\n", 34, substr(msg[i], 2, 30), 34)
     print "};"
     print ""
-    exit(badlimit)
+    print "static int limtype[ZSH_NLIMITS] = {"
+    for (i = 0; i < 0 + nlimits; i++) {
+	if (msg[i] == "")
+	    limtype = "UNKNOWN"
+	else {
+	    limtype = substr(msg[i], 1, 1)
+	    if(limtype == "M") { limtype = "MEMORY" }
+	    if(limtype == "N") { limtype = "NUMBER" }
+	    if(limtype == "T") { limtype = "TIME" }
+	}
+	printf("\tZLIMTYPE_%s,\n", limtype)
+    }
+    print "};"
+
+    exit(0)
 }
diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index 8ffcf5cdf..3f0ad7ed5 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -32,6 +32,13 @@
 
 #if defined(HAVE_GETRLIMIT) && defined(RLIM_INFINITY)
 
+enum {
+    ZLIMTYPE_MEMORY,
+    ZLIMTYPE_NUMBER,
+    ZLIMTYPE_TIME,
+    ZLIMTYPE_UNKNOWN
+};
+
 /* Generated rec array containing limits required for the limit builtin.     *
  * They must appear in this array in numerical order of the RLIMIT_* macros. */
 
@@ -85,22 +92,15 @@ showlimits(int hard, int lim)
 	    val = (hard) ? limits[rt].rlim_max : limits[rt].rlim_cur;
 	    if (val == RLIM_INFINITY)
 		printf("unlimited\n");
-	    else if (rt==RLIMIT_CPU)
+	    else if (limtype[rt] == ZLIMTYPE_TIME) {
 		/* time-type resource -- display as hours, minutes and
 		seconds. */
 		printf("%d:%02d:%02d\n", (int)(val / 3600),
 		       (int)(val / 60) % 60, (int)(val % 60));
-# ifdef RLIMIT_NPROC
-	    else if (rt == RLIMIT_NPROC)
+	    } else if (limtype[rt] == ZLIMTYPE_NUMBER || limtype[rt] == ZLIMTYPE_UNKNOWN) {
 		/* pure numeric resource */
 		printf("%d\n", (int)val);
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_NOFILE
-	    else if (rt == RLIMIT_NOFILE)
-		/* pure numeric resource */
-		printf("%d\n", (int)val);
-# endif /* RLIMIT_NOFILE */
-	    else if (val >= 1024L * 1024L)
+	    } else if (val >= 1024L * 1024L)
 		/* memory resource -- display with `K' or `M' modifier */
 # ifdef RLIM_T_IS_QUAD_T
 		printf("%qdMB\n", val / (1024L * 1024L));
@@ -297,7 +297,7 @@ bin_limit(char *nam, char **argv, char *ops, int func)
 	    showlimits(hard, lim);
 	    return 0;
 	}
-	if (lim==RLIMIT_CPU) {
+	if (limtype[lim] == ZLIMTYPE_TIME) {
 	    /* time-type resource -- may be specified as seconds, or minutes or *
 	     * hours with the `m' and `h' modifiers, and `:' may be used to add *
 	     * together more than one of these.  It's easier to understand from *
@@ -315,20 +315,11 @@ bin_limit(char *nam, char **argv, char *ops, int func)
 		    return 1;
 		}
 	    }
-	}
-# ifdef RLIMIT_NPROC
-	else if (lim == RLIMIT_NPROC)
-	    /* pure numeric resource -- only a straight decimal number is
-	    permitted. */
-	    val = zstrtorlimt(s, &s, 10);
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_NOFILE
-	else if (lim == RLIMIT_NOFILE)
+	} else if (limtype[lim] == ZLIMTYPE_NUMBER || limtype[lim] == ZLIMTYPE_UNKNOWN) {
 	    /* pure numeric resource -- only a straight decimal number is
 	    permitted. */
 	    val = zstrtorlimt(s, &s, 10);
-# endif /* RLIMIT_NOFILE */
-	else {
+	} else {
 	    /* memory-type resource -- `k' and `M' modifiers are permitted,
 	    meaning (respectively) 2^10 and 2^20. */
 	    val = zstrtorlimt(s, &s, 10);
diff --git a/Src/Builtins/rlimits.mdd b/Src/Builtins/rlimits.mdd
index f0e41b73e..129adf901 100644
--- a/Src/Builtins/rlimits.mdd
+++ b/Src/Builtins/rlimits.mdd
@@ -5,12 +5,12 @@ objects="rlimits.o"
 :<<\Make
 rlimits.o rlimits..o: rlimits.h
 
-# this file will not be made if limits are unavailable:
-# silent so the warning doesn't appear unless necessary
+# this file will not be made if limits are unavailable
 rlimits.h: rlimits.awk @RLIMITS_INC_H@
-	@echo '$(AWK) -f $(sdir)/rlimits.awk @RLIMITS_INC_H@ > rlimits.h'; \
-	$(AWK) -f $(sdir)/rlimits.awk @RLIMITS_INC_H@ > rlimits.h || \
-	    echo WARNING: unknown limits:  mail rlimits.h to developers
+	$(AWK) -f $(sdir)/rlimits.awk @RLIMITS_INC_H@ > rlimits.h
+	@if grep ZLIMTYPE_UNKNOWN rlimits.h >/dev/null; then \
+	    echo >&2 WARNING: unknown limits: mail rlimits.h to developers; \
+	else :; fi
 
 clean-here: clean.rlimits
 clean.rlimits: