VMware Cloud Community
h2o_hyperic
Contributor
Contributor

Linux / glibc 2.8: ARG_MAX undeclard?

Sigar is very cool and everything runs out of the box, so I wanted to rebuild from scratch and maybe provide a Gentoo package. But not so fast cowboy:

[cc] /tmp/hyperic-sigar-1.6.0-src/src/os/linux/linux_sigar.c: In function 'sigar_proc_env_get':
[cc] /tmp/hyperic-sigar-1.6.0-src/src/os/linux/linux_sigar.c:889: error: 'ARG_MAX' undeclared (first use in this function)

This looks interesting, because limits.h pulls in sys/params.h which includes linux/limits.h and then successfully UNdefines ARG_MAX again because it thinks it knows better:

--snip--

#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

--snip--

..and so I end up with no ARG_MAX. I know that directly defining values from linux/* is bad, but in this case it looks like a valid workaround. Sure enough, adding the following after all includes:

#ifndef ARG_MAX
#define ARG_MAX 131072
#endif

..fixes things to build & run fine, as expected.

This is with glibc 2.8_p20080602 - arguably a "testing" version, but since this is Gentoo practically everything is built from source, and this is the very first time I ran into this particular error.

Any other suggestions? Should I file this into JIRA?

thanks for an awesome package,
Holger

fixed include brackets


Message was edited by: h2o
Reply
0 Kudos
3 Replies
h2o_hyperic
Contributor
Contributor

After some more googling, I learned that apparently this is not a bug but a feature called sysconf(3). Damn newfangled stuff..

holger>cat argmax.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char** argv)
{
printf("ARG_MAX=%d\n", sysconf(_SC_ARG_MAX));
exit(0);
}

holger>gcc argmax.c -o argmax
holger>./argmax
ARG_MAX=2097152

So ARG_MAX should be obtained via sysconf, if possible.
Reply
0 Kudos
dougm_hyperic
VMware Employee
VMware Employee

Hi Holger,

Thanks for the report and investigation. I've opened http://jira.hyperic.com/browse/SIGAR-122 and applied your #ifndef fix. Need to get a glibc 2.8 system myself to test further.
Reply
0 Kudos
h2o_hyperic
Contributor
Contributor

Hi Doug,

thanks for looking into this. AFAIK newer Fedora systems should have glibc 2.8; we had similar problems when compiling the Erlang VM. 😉
Btw - just to make sure - I think the original allocation was on the stack. This might end in unhappy ways when the returned value is too large.

cheers
Holger
Reply
0 Kudos