Return-Path: dgaudet@arctic.org 
Received: from tln.lib.mi.us
	by netgod.net (fetchmail-4.3.4 POP3 run for johnie)
	for <johnie@localhost> (single-drop); Thu, 18 Dec 1997 22:09:40 EST
Received: by tln for johnie
 (with Cubic Circle's cucipop (v1.20 1997/08/01); Thu Dec 18 22:06:31 1997)
X-From_: dgaudet@arctic.org  Thu Dec 18 21:18:37 1997
Return-Path: <dgaudet@arctic.org>
Received: from pub1.tln.lib.mi.us (root@pub1.tln.lib.mi.us [206.187.91.11])
	by debian.tln.org (8.8.8/8.8.7/Debian/Owns/U) with ESMTP id VAA01785
	for <johnie@tln.lib.mi.us>; Thu, 18 Dec 1997 21:18:36 -0500
Received: from debian.novare.net (debian.novare.net [205.229.104.5])
	by pub1.tln.lib.mi.us (8.8.8/8.8.8/Debian/GNU) with SMTP id UAA23602
	for <johnie@tln.lib.mi.us>; Thu, 18 Dec 1997 20:49:11 -0500
Received: (qmail 31347 invoked by uid 942); 19 Dec 1997 02:10:39 -0000
Delivered-To: johnie@debian.org
Received: (qmail 31344 invoked from network); 19 Dec 1997 02:10:39 -0000
Received: from twinlark.arctic.org (twinlark.arctic.org@204.62.130.91)
  by 205.229.104.5 with SMTP; 19 Dec 1997 02:10:38 -0000
Received: (qmail 31659 invoked by uid 500); 19 Dec 1997 02:23:57 -0000
Date: Thu, 18 Dec 1997 18:23:57 -0800 (PST)
From: Dean Gaudet <dgaudet@arctic.org>
To: johnie@debian.org
Subject: [PATCH] Re: os-linux/1542: /usr/include/bits/resource.h:113: conflicting types for `rlim_t' (fwd)
Message-ID: <Pine.LNX.3.95dg3.971218182238.26855R-100000@twinlark.arctic.org>
X-Comment: Visit http://www.arctic.org/~dgaudet/legal for information regarding copyright and disclaimer.
Organization: Transmeta Corp.
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Status: RO
X-Status: 

Give this a try if you can... tell me if I really flubbed up.  I tested on
a ppc glibc 2.0.4 system, an alpha 2.0.5c redhat 5.0 system, and a libc5
i386 system.  I wandered through all the relevant header files though so
it *should* work elsewhere. 

Dean

---------- Forwarded message ----------
Date: Mon, 15 Dec 1997 23:33:31 -0800 (PST)
From: Dean Gaudet <dgaudet@arctic.org>
To: TLOSAP <new-httpd@apache.org>
Subject: [PATCH] Re: os-linux/1542: /usr/include/bits/resource.h:113: conflicting types for `rlim_t' (fwd)
X-Comment: Visit http://www.arctic.org/~dgaudet/legal for information regarding copyright and disclaimer.
Organization: Transmeta Corp.
Reply-To: new-httpd@apache.org

On Wed, 10 Dec 1997, Marc Slemko wrote:

> I would suggest that the time for automatic rlim_t testing is near.
> 
> It is easy to add a "type" test to TestCompile, but the trouble is what
> include files do you use?  For rlim_t, it should be sys/resource.h
> normally but how do you generalize that?
> 
> It may be possible to hardcode rlim_t, but we need to know exactly what
> version of glibc has it, etc.  A pain.

I spent time looking into this.  glibc has a few gotches that are
annoying.  I don't think we can support -Wall warning free compilation
on all versions of glibc...

For example, 2.0.0 through 2.0.4 use "size_t *"  for the third paramter
to accept() and other network functions, whereas 2.0.5 and later use
"socklen_t *".  This is due to evolution of the POSIX spec.  (Using size_t
is broken broken broken, and was a hideous mistake in the spec, it breaks
all old programs that assume that paramter is an "int *" when compiled
on 64-bit systems.  socklen_t is essentially an int.)  However, there is
no way to detect 2.0.x < 2.0.5.

Thankfully rlim_t appears only in glibc 2.1.x, and not earlier.

The following patch is a reasonable attempt to get us -Wall free compiles
on 2.0.5 (and later) and 2.1.x glibc.  The rlim_t change is required
to compile on 2.1.x.  I've tested on glibc 2.0.5 alpha and ppc systems,
and libc5 i386 systems.  The rest I gleaned from looking at various
versions of glibc.

Dean

Index: conf.h
===================================================================
RCS file: /export/home/cvs/apachen/src/main/conf.h,v
retrieving revision 1.162
diff -u -r1.162 conf.h
--- conf.h	1997/12/01 12:10:14	1.162
+++ conf.h	1997/12/16 07:27:14
@@ -310,22 +310,50 @@
 #define HAVE_SYSLOG
 
 #elif defined(LINUX)
+
 #if LINUX > 1
 #include <features.h>
+
+/* libc4 systems probably still work, it probably doesn't define
+ *  __GNU_LIBRARY__
+ * libc5 systems define __GNU_LIBRARY__ == 1, but don't define __GLIBC__
+ * glibc 2.x and later systems define __GNU_LIBRARY__ == 6, but list it as
+ * "deprecated in favour of __GLIBC__"; the value 6 will never be changed.
+ * glibc 1.x systems (i.e. redhat 4.x on sparc/alpha) should have
+ * __GLIBC__ < 2
+ * all glibc based systems need crypt.h
+ */
 #if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
-/* it's a glibc host */
 #include <crypt.h>
-#define NET_SIZE_T size_t
 #endif
+
+/* glibc 2.0.0 through 2.0.4 need size_t * here, where 2.0.5 needs socklen_t *
+ * there's no way to discern between these two libraries.  But using int should
+ * be portable because otherwise these libs would be hopelessly broken with
+ * reams of existing networking code.  We'll use socklen_t * for 2.1.x and
+ * later.
+ *
+ * int works for all the earlier libs, and is picked up by default later.
+ */
+#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
+#define NET_SIZE_T socklen_t
+#endif
+
 #define HAVE_SHMGET
 #define USE_MMAP_FILES
 #define HAVE_SYS_RESOURCE_H
+
+/* glibc 2.1 and later finally define rlim_t */
+#if !defined(__GLIBC__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
 typedef int rlim_t;
+#endif
 /* flock is faster ... but hasn't been tested on 1.x systems */
 #define USE_FLOCK_SERIALIZED_ACCEPT
+
 #else
 #define USE_FCNTL_SERIALIZED_ACCEPT
 #endif
+
 #undef HAVE_GMTOFF
 #undef NO_KILLPG
 #undef NO_SETSID

