Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: RLIMITS macros
- X-seq: zsh-workers 18430
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: Re: PATCH: RLIMITS macros
- Date: Wed, 02 Apr 2003 10:46:56 +0100
- In-reply-to: ""Bart Schaefer""'s message of "Wed, 02 Apr 2003 03:25:19 -0000." <1030402032519.ZM6980@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
"Bart Schaefer" wrote:
> } It's possible to skip the multiplication by 1024 if RLIMIT_AS is defined
> } and is not the same as RLIMIT_RSS, but I didn't think that was the case
> } here.
>
> That's *exactly* the case here.
Aha. In that case the following revised version should work.
> The following is all inside enum { }:
>
> /usr/include/bits/resource.h: RLIMIT_RSS = 5,
> /usr/include/bits/resource.h:#define RLIMIT_RSS RLIMIT_RSS
> /usr/include/bits/resource.h: RLIMIT_AS = 9,
> /usr/include/bits/resource.h:#define RLIMIT_AS RLIMIT_AS
That makes the HAVE_RLIMIT_RSS stuff redundant, but I'm inclined to
leave it in for future-proofing.
Index: acconfig.h
===================================================================
RCS file: /cvsroot/zsh/zsh/acconfig.h,v
retrieving revision 1.14
diff -u -r1.14 acconfig.h
--- acconfig.h 6 May 2002 14:50:10 -0000 1.14
+++ acconfig.h 2 Apr 2003 09:45:13 -0000
@@ -238,6 +238,48 @@
/* Define to the type used in struct rlimit */
#undef rlim_t
+/* Define to 1 if RLIMIT_AIO_MEM is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_AIO_MEM
+
+/* Define to 1 if RLIMIT_AIO_OPS is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_AIO_OPS
+
+/* Define to 1 if RLIMIT_AS is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_AS
+
+/* Define to 1 if RLIMIT_LOCKS is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_LOCKS
+
+/* Define to 1 if RLIMIT_MEMLOCK is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_MEMLOCK
+
+/* Define to 1 if RLIMIT_NPROC is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_NPROC
+
+/* Define to 1 if RLIMIT_NOFILE is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_NOFILE
+
+/* Define to 1 if RLIMIT_PTHREAD is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_PTHREAD
+
+/* Define to 1 if RLIMIT_RSS is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_RSS
+
+/* Define to 1 if RLIMIT_SBSIZE is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_SBSIZE
+
+/* Define to 1 if RLIMIT_TCACHE is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_TCACHE
+
+/* Define to 1 if RLIMIT_VMEM is present (whether or not as a macro) */
+#undef HAVE_RLIMIT_VMEM
+
+/* Define to 1 if RLIMIT_VMEM and RLIMIT_RSS both exist and are equal */
+#undef RLIMIT_VMEM_IS_RSS
+
+/* Define to 1 if RLIMIT_VMEM and RLIMIT_AS both exist and are equal */
+#undef RLIMIT_VMEM_IS_AS
+
/* Define to 1 if /bin/sh does not interpret \ escape sequences */
#undef SH_USE_BSD_ECHO
Index: aczsh.m4
===================================================================
RCS file: /cvsroot/zsh/zsh/aczsh.m4,v
retrieving revision 1.14
diff -u -r1.14 aczsh.m4
--- aczsh.m4 22 Oct 2001 17:18:29 -0000 1.14
+++ aczsh.m4 2 Apr 2003 09:45:13 -0000
@@ -710,3 +710,21 @@
AC_DEFINE_UNQUOTED([SOCKLEN_T], [$zsh_cv_type_socklen_t])]
)
+dnl Check for limit $1 e.g. RLIMIT_RSS.
+AC_DEFUN(zsh_LIMIT_PRESENT,
+[AC_CACHE_CHECK([for limit $1],
+zsh_cv_have_$1,
+[AC_TRY_COMPILE([
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <sys/resource.h>],
+[$1],
+ zsh_cv_have_$1=yes,
+ zsh_cv_have_$1=no)])
+
+if test $zsh_cv_have_$1 = yes; then
+ AC_DEFINE(HAVE_$1)
+fi])
+
Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.35
diff -u -r1.35 zshconfig.ac
--- zshconfig.ac 24 Mar 2003 12:56:59 -0000 1.35
+++ zshconfig.ac 2 Apr 2003 09:45:13 -0000
@@ -1221,6 +1221,75 @@
AC_DEFINE_UNQUOTED(rlim_t, $DEFAULT_RLIM_T)
fi
+
+dnl On some systems the RLIMIT_* don't evaluate to integers at compile time
+dnl (they may be enums). In this case we are not able to do preprocessor
+dnl comparisions and need our tests to determine what values exist and
+dnl if there are clashing definitions.
+
+zsh_LIMIT_PRESENT(RLIMIT_AIO_MEM)
+zsh_LIMIT_PRESENT(RLIMIT_AIO_OPS)
+zsh_LIMIT_PRESENT(RLIMIT_AS)
+zsh_LIMIT_PRESENT(RLIMIT_LOCKS)
+zsh_LIMIT_PRESENT(RLIMIT_MEMLOCK)
+zsh_LIMIT_PRESENT(RLIMIT_NPROC)
+zsh_LIMIT_PRESENT(RLIMIT_NOFILE)
+zsh_LIMIT_PRESENT(RLIMIT_PTHREAD)
+zsh_LIMIT_PRESENT(RLIMIT_RSS)
+zsh_LIMIT_PRESENT(RLIMIT_SBSIZE)
+zsh_LIMIT_PRESENT(RLIMIT_TCACHE)
+zsh_LIMIT_PRESENT(RLIMIT_VMEM)
+
+AC_CACHE_CHECK(if RLIMIT_VMEM and RLIMIT_RSS are the same,
+zsh_cv_rlimit_vmem_is_rss,
+[AC_TRY_RUN([
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <sys/resource.h>
+int main()
+{
+int ret = 1;
+#if defined(HAVE_RLIMIT_VMEM) && defined(HAVE_RLIMIT_RSS)
+if (RLIMIT_RSS == RLIMIT_VMEM) ret = 0;
+#endif
+return ret;
+}],
+ zsh_cv_rlimit_vmem_is_rss=yes,
+ zsh_cv_rlimit_vmem_is_rss=no,
+ zsh_cv_rlimit_vmem_is_rss=no)])
+
+if test $zsh_cv_rlimit_vmem_is_rss = yes; then
+ AC_DEFINE(RLIMIT_VMEM_IS_RSS)
+fi
+
+
+AC_CACHE_CHECK(if RLIMIT_VMEM and RLIMIT_AS are the same,
+zsh_cv_rlimit_vmem_is_as,
+[AC_TRY_RUN([
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <sys/resource.h>
+int main()
+{
+int ret = 1;
+#if defined(HAVE_RLIMIT_VMEM) && defined(HAVE_RLIMIT_AS)
+if (RLIMIT_AS == RLIMIT_VMEM) ret = 0;
+#endif
+return ret;
+}],
+ zsh_cv_rlimit_vmem_is_as=yes,
+ zsh_cv_rlimit_vmem_is_as=no,
+ zsh_cv_rlimit_vmem_is_as=no)])
+
+if test $zsh_cv_rlimit_vmem_is_as = yes; then
+ AC_DEFINE(RLIMIT_VMEM_IS_AS)
+fi
+
+
dnl ----------------------------
dnl CHECK FOR /dev/fd FILESYSTEM
dnl ----------------------------
Index: Src/Builtins/rlimits.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Builtins/rlimits.c,v
retrieving revision 1.8
diff -u -r1.8 rlimits.c
--- Src/Builtins/rlimits.c 9 Feb 2003 01:12:38 -0000 1.8
+++ Src/Builtins/rlimits.c 2 Apr 2003 09:45:13 -0000
@@ -175,38 +175,38 @@
break;
/* If RLIMIT_VMEM and RLIMIT_RSS are defined and equal, avoid *
* duplicate case statement. Observed on QNX Neutrino 6.1.0. */
-# if defined(RLIMIT_RSS) && (!defined(RLIMIT_VMEM) || RLIMIT_VMEM != RLIMIT_RSS)
+# if defined(HAVE_RLIMIT_RSS) && !defined(RLIMIT_VMEM_IS_RSS)
case RLIMIT_RSS:
if (head)
printf("resident set size (kbytes) ");
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_RSS */
-# ifdef RLIMIT_MEMLOCK
+# endif /* HAVE_RLIMIT_RSS */
+# ifdef HAVE_RLIMIT_MEMLOCK
case RLIMIT_MEMLOCK:
if (head)
printf("locked-in-memory size (kb) ");
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_MEMLOCK */
-# ifdef RLIMIT_NPROC
+# endif /* HAVE_RLIMIT_MEMLOCK */
+# ifdef HAVE_RLIMIT_NPROC
case RLIMIT_NPROC:
if (head)
printf("processes ");
break;
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_NOFILE
+# endif /* HAVE_RLIMIT_NPROC */
+# ifdef HAVE_RLIMIT_NOFILE
case RLIMIT_NOFILE:
if (head)
printf("file descriptors ");
break;
-# endif /* RLIMIT_NOFILE */
-# ifdef RLIMIT_VMEM
+# endif /* HAVE_RLIMIT_NOFILE */
+# ifdef HAVE_RLIMIT_VMEM
case RLIMIT_VMEM:
if (head)
-# if defined(RLIMIT_RSS) && RLIMIT_VMEM == RLIMIT_RSS
+# if defined(HAVE_RLIMIT_RSS) && defined(RLIMIT_VMEM_IS_RSS)
printf("memory size (kb) ");
# else
printf("virtual memory size (kb) ");
@@ -214,55 +214,55 @@
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_VMEM */
-# if defined RLIMIT_AS && RLIMIT_AS != RLIMIT_VMEM
+# endif /* HAVE_RLIMIT_VMEM */
+# if defined HAVE_RLIMIT_AS && !defined(RLIMIT_VMEM_IS_AS)
case RLIMIT_AS:
if (head)
printf("address space (kb) ");
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_AS */
-# ifdef RLIMIT_TCACHE
+# endif /* HAVE_RLIMIT_AS */
+# ifdef HAVE_RLIMIT_TCACHE
case RLIMIT_TCACHE:
if (head)
printf("cached threads ");
break;
-# endif /* RLIMIT_TCACHE */
-# ifdef RLIMIT_AIO_OPS
+# endif /* HAVE_RLIMIT_TCACHE */
+# ifdef HAVE_RLIMIT_AIO_OPS
case RLIMIT_AIO_OPS:
if (head)
printf("AIO operations ");
break;
-# endif /* RLIMIT_AIO_OPS */
-# ifdef RLIMIT_AIO_MEM
+# endif /* HAVE_RLIMIT_AIO_OPS */
+# ifdef HAVE_RLIMIT_AIO_MEM
case RLIMIT_AIO_MEM:
if (head)
printf("AIO locked-in-memory (kb) ");
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_AIO_MEM */
-# ifdef RLIMIT_SBSIZE
+# endif /* HAVE_RLIMIT_AIO_MEM */
+# ifdef HAVE_RLIMIT_SBSIZE
case RLIMIT_SBSIZE:
if (head)
printf("socket buffer size (kb) ");
if (limit != RLIM_INFINITY)
limit /= 1024;
break;
-# endif /* RLIMIT_SBSIZE */
-# ifdef RLIMIT_PTHREAD
+# endif /* HAVE_RLIMIT_SBSIZE */
+# ifdef HAVE_RLIMIT_PTHREAD
case RLIMIT_PTHREAD:
if (head)
printf("threads per process ");
break;
-# endif /* RLIMIT_PTHREAD */
-# ifdef RLIMIT_LOCKS
+# endif /* HAVE_RLIMIT_PTHREAD */
+# ifdef HAVE_RLIMIT_LOCKS
case RLIMIT_LOCKS:
if (head)
printf("file locks ");
break;
-# endif /* RLIMIT_LOCKS */
+# endif /* HAVE_RLIMIT_LOCKS */
}
/* display the limit */
if (limit == RLIM_INFINITY)
@@ -509,31 +509,31 @@
case 'c':
res = RLIMIT_CORE;
break;
-# ifdef RLIMIT_RSS
+# ifdef HAVE_RLIMIT_RSS
case 'm':
res = RLIMIT_RSS;
break;
-# endif /* RLIMIT_RSS */
-# ifdef RLIMIT_MEMLOCK
+# endif /* HAVE_RLIMIT_RSS */
+# ifdef HAVE_RLIMIT_MEMLOCK
case 'l':
res = RLIMIT_MEMLOCK;
break;
-# endif /* RLIMIT_MEMLOCK */
-# ifdef RLIMIT_NOFILE
+# endif /* HAVE_RLIMIT_MEMLOCK */
+# ifdef HAVE_RLIMIT_NOFILE
case 'n':
res = RLIMIT_NOFILE;
break;
-# endif /* RLIMIT_NOFILE */
-# ifdef RLIMIT_NPROC
+# endif /* HAVE_RLIMIT_NOFILE */
+# ifdef HAVE_RLIMIT_NPROC
case 'u':
res = RLIMIT_NPROC;
break;
-# endif /* RLIMIT_NPROC */
-# ifdef RLIMIT_VMEM
+# endif /* HAVE_RLIMIT_NPROC */
+# ifdef HAVE_RLIMIT_VMEM
case 'v':
res = RLIMIT_VMEM;
break;
-# endif /* RLIMIT_VMEM */
+# endif /* HAVE_RLIMIT_VMEM */
default:
/* unrecognised limit */
zwarnnam(name, "bad option: -%c", NULL, *options);
@@ -571,20 +571,24 @@
break;
case RLIMIT_DATA:
case RLIMIT_STACK:
-# ifdef RLIMIT_RSS
+# ifdef HAVE_RLIMIT_RSS
case RLIMIT_RSS:
-# endif /* RLIMIT_RSS */
-# ifdef RLIMIT_MEMLOCK
+# endif /* HAVE_RLIMIT_RSS */
+# ifdef HAVE_RLIMIT_MEMLOCK
case RLIMIT_MEMLOCK:
-# endif /* RLIMIT_MEMLOCK */
+# endif /* HAVE_RLIMIT_MEMLOCK */
/* If RLIMIT_VMEM and RLIMIT_RSS are defined and equal, avoid *
* duplicate case statement. Observed on QNX Neutrino 6.1.0. */
-# if defined(RLIMIT_VMEM) && (!defined(RLIMIT_RSS) || RLIMIT_RSS != RLIMIT_VMEM)
+# if defined(HAVE_RLIMIT_VMEM) && !defined(RLIMIT_VMEM_IS_RSS)
case RLIMIT_VMEM:
-# endif /* RLIMIT_VMEM */
-# ifdef RLIMIT_AIO_MEM
+# endif /* HAVE_RLIMIT_VMEM */
+/* ditto RLIMIT_VMEM and RLIMIT_AS */
+# if defined(HAVE_RLIMIT_AS) && !defined(RLIMIT_VMEM_IS_AS)
+ case RLIMIT_AS:
+# endif /* HAVE_RLIMIT_AS */
+# ifdef HAVE_RLIMIT_AIO_MEM
case RLIMIT_AIO_MEM:
-# endif /* RLIMIT_AIO_MEM */
+# endif /* HAVE_RLIMIT_AIO_MEM */
limit *= 1024;
break;
}
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author