What steps will reproduce the problem?
1. pwd # :prosody-0.10.2
2. ./configure --ostype=macosx
3. make
What is the expected output?
Build completed successfully.
What do you see instead?
pposix.c:433:8: warning: implicit declaration of function 'initgroups' is invalid in C99 [-Wimplicit-function-declaration]
ret = initgroups(lua_tostring(L, 1), gid);
^
pposix.c:523:10: error: use of undeclared identifier 'RLIMIT_MEMLOCK'
return RLIMIT_MEMLOCK;
^
pposix.c:527:10: error: use of undeclared identifier 'RLIMIT_NPROC'
return RLIMIT_NPROC;
^
pposix.c:531:10: error: use of undeclared identifier 'RLIMIT_RSS'
return RLIMIT_RSS;
What version of the product are you using? On what operating system?
prosody 0.10.2 on MacOSX High Sierra (10.13.6)
Please provide any additional information below.
The same errors could be obtained with clang (llvm) 9.1.0 and gcc 8.2.0
Other reporters already noticed this problem:
https://github.com/bjc/prosody/issues/16https://github.com/prosody/homebrew-prosody/issues/11
Fabrice Ducos
on
Zach's solution to https://github.com/prosody/homebrew-prosody/issues/11 fixes the errors with RLIMIT_XXX, but not the warning on initgroups.
Strangely, <unistd.h> (where initgroups is declared) is properly included in pposix.c. Seems to be some conditional declaration issue.
Zash
on
Thanks for the report and for testing that patch.
Pushed it as https://hg.prosody.im/0.10/rev/8f9e18d4fe50
Could you check if adding #define _BSD_SOURCE affects that warning?
Changes
tags Milestone-0.10 Status-Started
Fabrice Ducos
on
Dear Zash, thank you for your quick reply.
Defining _BSD_SOURCE has no effect.
However, with the following patch in pposix.c, it works properly with clang and gcc (at least on High Sierra, not tested for older versions of OSX)
#if defined(__APPLE__)
#define _POSIX_C_SOURCE __DARWIN_C_FULL
#else
#define _POSIX_C_SOURCE 200809L
#endif
Cheers,
Fabrice
Zash
on
Is there some kind of documentation that explains what this does?
Fabrice Ducos
on
I know no documentation about this, therefore I had to dive in the system headers.
initgroups() is not POSIX.1 (reference: Advanced Programming in the Unix Environment, 3rd edition, p. 184). As you suggested, it should be made available with _BSD_SOURCE, but this macro doesn't seem to be tested in OSX system header files.
In order to enable extensions, one needs to set up __DARWIN_C_LEVEL on Apple's systems.
When one examines unistd.h (where initgroups is defined), one sees that it is defined conditionally within a snippet:
/* Darwin extensions */
#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
__DARWIN_C_FULL itself is defined in /usr/include/sys/cdefs.h (on OSX systems).
/*
* Set a single macro which will always be defined and can be used to determine
* the appropriate namespace. For POSIX, these values will correspond to
* _POSIX_C_SOURCE value. Currently there are two additional levels corresponding
* to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
*/
#define __DARWIN_C_ANSI 010000L
#define __DARWIN_C_FULL 900000L
#if defined(_ANSI_SOURCE)
#define __DARWIN_C_LEVEL __DARWIN_C_ANSI
#elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
#define __DARWIN_C_LEVEL _POSIX_C_SOURCE
#else
#define __DARWIN_C_LEVEL __DARWIN_C_FULL
#endif
Regards
Fabrice Ducos
on
A better way is not to hack the _POSIX_C_SOURCE macro (as I did in my first proposition) and to define _DARWIN_C_SOURCE instead.
#if defined(__APPLE__)
#define _DARWIN_C_SOURCE
#endif
#define _POSIX_C_SOURCE 200809L
Has been tested and works.
What steps will reproduce the problem? 1. pwd # :prosody-0.10.2 2. ./configure --ostype=macosx 3. make What is the expected output? Build completed successfully. What do you see instead? pposix.c:433:8: warning: implicit declaration of function 'initgroups' is invalid in C99 [-Wimplicit-function-declaration] ret = initgroups(lua_tostring(L, 1), gid); ^ pposix.c:523:10: error: use of undeclared identifier 'RLIMIT_MEMLOCK' return RLIMIT_MEMLOCK; ^ pposix.c:527:10: error: use of undeclared identifier 'RLIMIT_NPROC' return RLIMIT_NPROC; ^ pposix.c:531:10: error: use of undeclared identifier 'RLIMIT_RSS' return RLIMIT_RSS; What version of the product are you using? On what operating system? prosody 0.10.2 on MacOSX High Sierra (10.13.6) Please provide any additional information below. The same errors could be obtained with clang (llvm) 9.1.0 and gcc 8.2.0 Other reporters already noticed this problem: https://github.com/bjc/prosody/issues/16 https://github.com/prosody/homebrew-prosody/issues/11
Zach's solution to https://github.com/prosody/homebrew-prosody/issues/11 fixes the errors with RLIMIT_XXX, but not the warning on initgroups. Strangely, <unistd.h> (where initgroups is declared) is properly included in pposix.c. Seems to be some conditional declaration issue.
Thanks for the report and for testing that patch. Pushed it as https://hg.prosody.im/0.10/rev/8f9e18d4fe50 Could you check if adding #define _BSD_SOURCE affects that warning?
ChangesDear Zash, thank you for your quick reply. Defining _BSD_SOURCE has no effect. However, with the following patch in pposix.c, it works properly with clang and gcc (at least on High Sierra, not tested for older versions of OSX) #if defined(__APPLE__) #define _POSIX_C_SOURCE __DARWIN_C_FULL #else #define _POSIX_C_SOURCE 200809L #endif Cheers, Fabrice
Is there some kind of documentation that explains what this does?
I know no documentation about this, therefore I had to dive in the system headers. initgroups() is not POSIX.1 (reference: Advanced Programming in the Unix Environment, 3rd edition, p. 184). As you suggested, it should be made available with _BSD_SOURCE, but this macro doesn't seem to be tested in OSX system header files. In order to enable extensions, one needs to set up __DARWIN_C_LEVEL on Apple's systems. When one examines unistd.h (where initgroups is defined), one sees that it is defined conditionally within a snippet: /* Darwin extensions */ #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL __DARWIN_C_FULL itself is defined in /usr/include/sys/cdefs.h (on OSX systems). /* * Set a single macro which will always be defined and can be used to determine * the appropriate namespace. For POSIX, these values will correspond to * _POSIX_C_SOURCE value. Currently there are two additional levels corresponding * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE) */ #define __DARWIN_C_ANSI 010000L #define __DARWIN_C_FULL 900000L #if defined(_ANSI_SOURCE) #define __DARWIN_C_LEVEL __DARWIN_C_ANSI #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE) #define __DARWIN_C_LEVEL _POSIX_C_SOURCE #else #define __DARWIN_C_LEVEL __DARWIN_C_FULL #endif Regards
A better way is not to hack the _POSIX_C_SOURCE macro (as I did in my first proposition) and to define _DARWIN_C_SOURCE instead. #if defined(__APPLE__) #define _DARWIN_C_SOURCE #endif #define _POSIX_C_SOURCE 200809L Has been tested and works.
I committed that as https://hg.prosody.im/0.10/rev/37b796cc366a Thanks!
Changes