Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

New RLIMIT_* configuration code



So far I've got a message from Bart saying the awk script looked OK,
and one from Geoff saying autoincrement was kosher in awk.  Taking
this as encouragement, this patch alters configure to check for the
location of the RLIMIT_* macros and builtin.c to use the awk-generated
rlimits.h.

The code should now be more graceful about failures.  If a particular
RLIMIT_* macro is not recognised, make prints a message, but the
compilation continues and the name used is the trailing part of the
macro name.  Locating the header with the definitions is probably the
worst problem; I simply copied the locations of possible signal.h
files and changed it to resource.h.  This list may need adding to.  If
the file is not found but getrlimit() is being used, configure prints
a warning (which may possibly get lost amid the other output) and uses
/dev/null as the awk input, so that an empty list of limits is
generated but the shell will compile.  If getrlimit() is not found, no
attempt is made to make rlimits.h at all.

Apart from that, the main remaining problem is likely to be more awk
lossage, and just possibly vendors getting too clever with RLIMIT
definitions.

There's no patch to configure:  you have to regenerate it with
autoconf if you want to try this out.  I've tried it on IRIX and
Solaris 2, though as I said yesterday the awk script is known to work
on SunOS 4.1.3, HPUX random and OSF/1 3ish.

I made not have applied the last RLIMIT_ patch to the undiff'd file,
so the hunk junking all the builtin.c definitions may fail.  The idea
is that `static char *recs[] {...};' needs to be replaced by `#include
"rlimits.h"'. 

*** Src/Makefile.in.rlim	Fri Jun 28 14:43:49 1996
--- Src/Makefile.in	Fri Dec 13 11:31:23 1996
***************
*** 72,83 ****
  # this header file is parsed to generate signal names (signames.h)
  SIGNAL_H = @SIGNAL_H@
  
  # headers included in distribution
  DIST_HDRS = version.h globals.h hashtable.h prototypes.h signals.h \
  system.h zle.h zsh.h ztype.h
  
  # generated headers
! GEN_HDRS = signames.h ../config.h
  
  # zsh headers necessary for compilation
  HDRS = $(DIST_HDRS) $(GEN_HDRS)
--- 72,86 ----
  # this header file is parsed to generate signal names (signames.h)
  SIGNAL_H = @SIGNAL_H@
  
+ # this header file is parsed to generate limits, if available
+ RLIMITS_INC_H = @RLIMITS_INC_H@
+ 
  # headers included in distribution
  DIST_HDRS = version.h globals.h hashtable.h prototypes.h signals.h \
  system.h zle.h zsh.h ztype.h
  
  # generated headers
! GEN_HDRS = signames.h ../config.h @RLIMITS_SRC_H@
  
  # zsh headers necessary for compilation
  HDRS = $(DIST_HDRS) $(GEN_HDRS)
***************
*** 106,112 ****
  $Uzle_vi.o $Uzle_word.o
  
  # auxiliary files
! AUX = Makefile.in .indent.pro signames.awk makepro.sed ansi2knr.c TAGS tags
  
  # all files in this directory included in the distribution
  DIST = $(DIST_HDRS) $(SRCS) $(AUX)
--- 109,116 ----
  $Uzle_vi.o $Uzle_word.o
  
  # auxiliary files
! AUX = Makefile.in .indent.pro signames.awk rlimits.awk makepro.sed \
!       ansi2knr.c TAGS tags
  
  # all files in this directory included in the distribution
  DIST = $(DIST_HDRS) $(SRCS) $(AUX)
***************
*** 125,130 ****
--- 129,141 ----
  signames.h: signames.awk
  	$(AWK) -f $(srcdir)/signames.awk $(SIGNAL_H) > signames.h
  
+ # this file will not be made if limits are unavailable:
+ # silent so the warning doesn't appear unless necessary
+ rlimits.h : $(RLIMITS_INC_H)
+ 	@echo Generating rlimits.h...
+ 	@$(AWK) -f $(srcdir)/rlimits.awk $(RLIMITS_INC_H) > rlimits.h || \
+ 	echo WARNING: unknown limits:  mail rlimits.h to developers
+ 
  $(OBJS): $(HDRS)
  
  $(PROTO): makepro.sed
***************
*** 221,227 ****
  	rm -f core *.o *~
  
  clean: mostlyclean
! 	rm -f zsh ansi2knr signames.h _*.c *.pro
  
  distclean: clean
  	rm -f Makefile
--- 232,238 ----
  	rm -f core *.o *~
  
  clean: mostlyclean
! 	rm -f zsh ansi2knr signames.h rlimits.h _*.c *.pro
  
  distclean: clean
  	rm -f Makefile
*** Src/builtin.c.rlim	Wed Dec 11 09:36:13 1996
--- Src/builtin.c	Fri Dec 13 10:37:24 1996
***************
*** 3599,3607 ****
  
  /**** resource limit builtins ****/
  
- /* Array of resource names, required for the limit builtin.  They must *
-  * appear in this array in numerical order of the RLIMIT_* macros.     */
- 
  #ifdef HAVE_GETRLIMIT
  
  #ifdef RLIM_T_IS_QUAD_T
--- 3599,3604 ----
***************
*** 3610,3693 ****
  # define ZSTRTORLIMT(a, b, c)	zstrtol((a), (b), (c))
  #endif
  
! static char *recs[] =
! {
!     "cputime", "filesize", "datasize", "stacksize", "coredumpsize",
! # define NEXT_RLIM 5
! # if defined RLIMIT_RSS && RLIMIT_RSS == 5
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_RSS + 1)
! #  ifdef RLIMIT_MEMLOCK
!     "memoryuse",
! #  else
!     "resident",
! #  endif /* RLIMIT_MEMLOCK */
! # endif /* RLIMIT_RSS */
! # if defined RLIMIT_MEMLOCK && RLIMIT_MEMLOCK == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_MEMLOCK + 1)
!     "memorylocked",
! # endif /* RLIMIT_MEMLOCK */
! # if defined RLIMIT_NPROC && RLIMIT_NPROC == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_NPROC + 1)
!     "maxproc",
! # endif /* RLIMIT_NPROC */
! # if defined RLIMIT_NOFILE && RLIMIT_NOFILE == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_NOFILE + 1)
!     "descriptors",
! # endif /* RLIMIT_NOFILE */
! # if defined RLIMIT_VMEM && RLIMIT_VMEM == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_VMEM + 1)
!     "vmemorysize",
! # endif /* RLIMIT_VMEM */
! # if defined RLIMIT_RSS && RLIMIT_RSS == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_RSS + 1)
! #  ifdef RLIMIT_MEMLOCK
!     "memoryuse",
! #  else
!     "resident",
! #  endif /* RLIMIT_MEMLOCK */
! # endif /* RLIMIT_RSS */
! # if defined RLIMIT_MEMLOCK && RLIMIT_MEMLOCK == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_MEMLOCK + 1)
!     "memorylocked",
! # endif /* RLIMIT_MEMLOCK */
! # if defined RLIMIT_AS && RLIMIT_AS == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_AS + 1)
!     "addressspace",
! # endif /* RLIMIT_AS */
! # if defined RLIMIT_NPROC && RLIMIT_NPROC == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_NPROC + 1)
!     "maxproc",
! # endif /* RLIMIT_NPROC */
! # if defined RLIMIT_MEMLOCK && RLIMIT_MEMLOCK == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_MEMLOCK + 1)
!     "memorylocked",
! # endif /* RLIMIT_MEMLOCK */
! # if defined RLIMIT_NOFILE && RLIMIT_NOFILE == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_NOFILE + 1)
!     "descriptors",
! # endif /* RLIMIT_NOFILE */
! # if defined RLIMIT_TCACHE && RLIMIT_TCACHE == NEXT_RLIM
! #  undef NEXT_RLIM
! #  define NEXT_RLIM (RLIMIT_TCACHE + 1)
!     "cachedthreads",
! # endif /* RLIMIT_TCACHE */
! # if NEXT_RLIM != RLIM_NLIMITS
!    #error there are some unknown limits.  Fix me!
! # endif
! # undef NEXT_RLIM
!     NULL
! };
  #endif /* HAVE_GETRLIMIT */
  
  /* limit: set or show resource limits.  The variable hard indicates *
--- 3607,3618 ----
  # define ZSTRTORLIMT(a, b, c)	zstrtol((a), (b), (c))
  #endif
  
! /* Generated rec array containing limits required for the limit builtin.
!  * They must appear in this array in numerical order of the RLIMIT_* macros.
!  */
! 
! #include "rlimits.h"
! 
  #endif /* HAVE_GETRLIMIT */
  
  /* limit: set or show resource limits.  The variable hard indicates *
*** configure.in.rlim	Wed Dec 11 09:36:19 1996
--- configure.in	Fri Dec 13 11:42:14 1996
***************
*** 488,493 ****
--- 488,525 ----
  SIGNAL_H=$zsh_cv_path_signal_h
  AC_SUBST(SIGNAL_H)dnl
  
+ dnl -----------------------------------------------------
+ dnl Look for the file containing the RLIMIT_* definitions
+ dnl -----------------------------------------------------
+ dnl CALL FOR MORE (FEWER?) LOCATIONS:  I've just copied the signal checking.
+ AC_CACHE_CHECK(where the RLIMIT macros are located,zsh_cv_path_rlimit_h,
+ [for RESOURCE_H in /usr/include/bsd/sys/resource.h   dnl
+                    /usr/include/asm/resource.h	     dnl
+                    /usr/include/linux/resource.h     dnl
+                    /usr/include/sys/resource.h       dnl
+                    /dev/null;
+ do
+   test -f $RESOURCE_H && \
+   grep '#[ 	]*define[ 	][ 	]*RLIMIT_[A-Z]*[ 	]*[0-9][0-9]*' $RESOURCE_H > /dev/null && \
+   break
+ done
+ zsh_cv_path_rlimit_h=$RESOURCE_H
+ if test $RESOURCE_H = "/dev/null" -a $ac_cv_func_getrlimit = yes; then
+   echo "RLIMIT MACROS NOT FOUND:  please report to developers"
+ fi])
+ RLIMITS_INC_H=$zsh_cv_path_rlimit_h
+ dnl rlimits.h only appears in dependencies if we are actually using it.
+ dnl We are using it any time we have getrlimit, though if the macros were
+ dnl not found we simply awk through /dev/null and fail to find them.
+ dnl Thus, limit won't work, but at least the shell will compile.
+ if test $zsh_cv_path_rlimit_h = /dev/null -a $ac_cv_func_getrlimit = no; then
+   RLIMITS_SRC_H=
+ else
+   RLIMITS_SRC_H=rlimits.h
+ fi
+ AC_SUBST(RLIMITS_SRC_H)dnl
+ AC_SUBST(RLIMITS_INC_H)dnl
+ 
  dnl ----------------------------
  dnl CHECK FOR /dev/fd FILESYSTEM
  dnl ----------------------------
*** /dev/null	Fri Dec 13 11:40:04 1996
--- Src/rlimits.awk	Fri Dec 13 11:47:08 1996
***************
*** 0 ****
--- 1,61 ----
+ # 
+ # $Id:$
+ #
+ # rlimits.awk: {g,n}awk script to generate rlimits.h
+ # rewritten by Peter Stephenson <pws@xxxxxx> from Geoff Wing
+ # <mason@xxxxxxxxxxxxxxxxxxx>'s signames.awk
+ # NB: On SunOS 4.1.3 - user-functions don't work properly, also \" problems
+ # Without 0 + hacks some nawks compare numbers as strings
+ #
+ /^[\t ]*#[\t ]*define[\t _]*RLIMIT_[A-Z]*[\t ]*[0-9][0-9]*/ { 
+     limindex = index($0, "RLIMIT_")
+     limtail = substr($0, limindex, 80)
+     split(limtail, tmp)
+     limnam = substr(tmp[1], 8, 20)
+     limnum = tmp[2]
+     limrev[limnam] = limnum
+     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 == "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] = "cachethreads" }
+         }
+     }
+ }
+ /^[\t ]*#[\t ]*define[\t _]*RLIM_NLIMITS[\t ]*[0-9][0-9]*/ {
+     limindex = index($0, "RLIM_")
+     limtail = substr($0, limindex, 80)
+     split(limtail, tmp)
+     nlimits = tmp[2]
+ }
+ 
+ END {
+     if (limrev["MEMLOCK"] != "") {
+         irss = limrev["RSS"]
+         msg[irss] = "memoryuse"
+     }
+     ps = "%s"
+ 
+     printf("%s\n%s\n\n%s\n", "/** rlimits.h                                 **/", "/** architecture-customized limits for zsh **/", "static char *recs[RLIM_NLIMITS+1] = {")
+ 
+     for (i = 0; i < 0 + nlimits; i++)
+ 	if (msg[i] == "") {
+             badlimit++
+             printf("\t%c%s%c,\n", 034, lim[i], 034)
+ 	} else
+ 	    printf("\t%c%s%c,\n", 034, msg[i], 034)
+     print "\tNULL"
+     print "};"
+     print ""
+     exit(badlimit)
+ }

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author