summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sys/param.h18
-rw-r--r--libc/sysdeps/linux/common/bits/local_lim.h10
-rw-r--r--libc/unistd/sysconf.c15
3 files changed, 37 insertions, 6 deletions
diff --git a/include/sys/param.h b/include/sys/param.h
index 0b0424eb9..19c119a2c 100644
--- a/include/sys/param.h
+++ b/include/sys/param.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,2000,2001,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1995-1997,2000,2001,2003,2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,10 +19,20 @@
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H 1
+#ifndef ARG_MAX
+# define __undef_ARG_MAX
+#endif
+
#include <limits.h>
#include <linux/limits.h>
#include <linux/param.h>
+/* The kernel headers defines ARG_MAX. The value is wrong, though. */
+#ifndef __undef_ARG_MAX
+# undef ARG_MAX
+# undef __undef_ARG_MAX
+#endif
+
/* BSD names for some <limits.h> values. */
#define NBBY CHAR_BIT
@@ -31,12 +41,12 @@
#endif
#define MAXSYMLINKS 20
#define CANBSIZ MAX_CANON
-#define NCARGS ARG_MAX
#define MAXPATHLEN PATH_MAX
-/* The following is not really correct but it is a value we used for a
+/* The following are not really correct but it is a value we used for a
long time and which seems to be usable. People should not use NOFILE
- anyway. */
+ and NCARGS anyway. */
#define NOFILE 256
+#define NCARGS 131072
#include <sys/types.h>
diff --git a/libc/sysdeps/linux/common/bits/local_lim.h b/libc/sysdeps/linux/common/bits/local_lim.h
index 023ebf3d0..a263b5d28 100644
--- a/libc/sysdeps/linux/common/bits/local_lim.h
+++ b/libc/sysdeps/linux/common/bits/local_lim.h
@@ -1,5 +1,5 @@
/* Minimum guaranteed maximum values for system limits. Linux version.
- Copyright (C) 1993-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
+ Copyright (C) 1993-1998,2000,2002-2004,2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -31,6 +31,9 @@
#ifndef OPEN_MAX
# define __undef_OPEN_MAX
#endif
+#ifndef ARG_MAX
+# define __undef_ARG_MAX
+#endif
/* The kernel sources contain a file with all the needed information. */
#include <linux/limits.h>
@@ -50,6 +53,11 @@
# undef OPEN_MAX
# undef __undef_OPEN_MAX
#endif
+/* Have to remove ARG_MAX? */
+#ifdef __undef_ARG_MAX
+# undef ARG_MAX
+# undef __undef_ARG_MAX
+#endif
/* The number of data keys per process. */
#define _POSIX_THREAD_KEYS_MAX 128
diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c
index b7cb4946f..d118f1b95 100644
--- a/libc/unistd/sysconf.c
+++ b/libc/unistd/sysconf.c
@@ -36,6 +36,8 @@
#endif
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <sysdep.h>
+#include <sys/resource.h>
+
#endif
#ifndef num_present_cpus
@@ -81,9 +83,16 @@
#define RETURN_FUNCTION(f) return f;
#endif /* _UCLIBC_GENERATE_SYSCONF_ARCH */
+/* Legacy value of ARG_MAX. The macro is now not defined since the
+ actual value varies based on the stack size. */
+#define legacy_ARG_MAX 131072
+
/* Get the value of the system variable NAME. */
long int sysconf(int name)
{
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+ struct rlimit rlimit;
+#endif
switch (name)
{
default:
@@ -91,7 +100,11 @@ long int sysconf(int name)
return -1;
case _SC_ARG_MAX:
-#ifdef ARG_MAX
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+ /* Use getrlimit to get the stack limit. */
+ if (getrlimit (RLIMIT_STACK, &rlimit) == 0)
+ return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
+#elif defined ARG_MAX
return ARG_MAX;
#else
RETURN_NEG_1;