#84 Fix compilation on Darwin

u2.10.12
open
nobody
5
2013-10-07
2009-03-28
David Herrmann
No

On Darwin (at least Mac OS X 10.5 and higher) the "getrusage()" function
is available but the "struct rusage" is not defined correctly, therefore, the
built failes.

This can be fixed by defining _DARWIN_C_SOURCE before including resource.h:

--- configure.in (Revision 157)
+++ configure.in (Arbeitskopie)
@@ -189,6 +189,7 @@
*-darwin*)
AC_MSG_RESULT([Darwin (Mac OS X) ($host) found.])
unet_poll_syscall=no
+ AC_DEFINE([_DARWIN_C_SOURCE], 1, [Define to enable POSIX compatibility on Darwin.])
;;

*)

Discussion

  • Anders Bergh
    Anders Bergh
    2010-03-07

    This solves compilation on Darwin, is it going to be added?

     
  • Anders Bergh
    Anders Bergh
    2013-10-07

    This patch is also necessary to make os_set_fdlimit() work. From the Darwin setrlimit man page:

    COMPATIBILITY
    setrlimit() now returns with errno set to EINVAL in places that historically succeeded. It no longer accepts
    "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE. Use "rlim_cur = min(OPEN_MAX, rlim_max)".

    diff -r 059a1d81b9fb -r e2a5a28939e7 ircd/os_generic.c
    --- a/ircd/os_generic.c Wed Jul 03 19:00:21 2013 +0200
    +++ b/ircd/os_generic.c Mon Oct 07 14:17:43 2013 +0200
    @@ -407,10 +407,14 @@
     #ifdef RLIMIT_OPEN_MAX
     #define RLIMIT_FD_MAX RLIMIT_OPEN_MAX
     #else
    +#ifdef RLIMIT_NOFILE
    +#define RLIMIT_FD_MAX RLIMIT_NOFILE
    +#else
     #undef RLIMIT_FD_MAX
     #endif
     #endif
     #endif
    +#endif
    
     /** Set file descriptor limit for the process.
      * @param[in] max_descriptors Ideal number of file descriptors.
    @@ -425,7 +429,7 @@
       if (!getrlimit(RLIMIT_FD_MAX, &limit)) {
         if (limit.rlim_max < max_descriptors)
           return limit.rlim_max;
    -    limit.rlim_cur = limit.rlim_max;    /* make soft limit the max */
    +    limit.rlim_cur = IRCD_MIN(max_descriptors, limit.rlim_max);
         return setrlimit(RLIMIT_FD_MAX, &limit);
       }
     #endif /* defined(HAVE_SETRLIMIT) && defined(RLIMIT_FD_MAX) */
    
     
    Last edit: Anders Bergh 2013-10-07