[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[mosquitto-dev] visibility defines
|
I'm seeing a build warning that initgroups is not defined
[ 55%] Building C object src/CMakeFiles/mosquitto.dir/mosquitto.c.o
/n0/gdt/SOFTWARE/IOT/MQTT/mosquitto/src/mosquitto.c: In function ‘drop_privileges’:
/n0/gdt/SOFTWARE/IOT/MQTT/mosquitto/src/mosquitto.c:113:7: warning: implicit declaration of function ‘initgroups’; did you mean ‘getgroups’? [-Wimplicit-function-declaration]
113 | if(initgroups(config->user, pwd->pw_gid) == -1){
| ^~~~~~~~~~
| getgroups
yet unistd.h is included, which matches the man page.
initgroups was first defined in 4.2BSD, and is not specified by POSIX.
The problem is that mosquitto sets visibility defines, and once any
visibility define is set, then all symbols not required by a visibility
define must be hidden.
On NetBSD, extensions not specified by any standard are made available
by _NETBSD_SOURCE (on by default -- unless there is a visibility
define). Thus this fix resolves the warning (and any errors from lack
of type promotion):
diff --git a/config.h b/config.h
index 9f614f8c..7708ecbc 100644
--- a/config.h
+++ b/config.h
@@ -9,6 +9,7 @@
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SYMBIAN32__)
# define _XOPEN_SOURCE 700
# define __BSD_VISIBLE 1
+# define _NETBSD_SOURCE
# define HAVE_NETINET_IN_H
#elif defined(__QNX__)
# define _XOPEN_SOURCE 600
Alternatively, simply removing the visibility defines leads to a
warning-free build:
diff --git a/config.h b/config.h
index 9f614f8c..b25bea31 100644
--- a/config.h
+++ b/config.h
@@ -7,8 +7,6 @@
#ifdef __APPLE__
# define __DARWIN_C_SOURCE
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SYMBIAN32__)
-# define _XOPEN_SOURCE 700
-# define __BSD_VISIBLE 1
# define HAVE_NETINET_IN_H
#elif defined(__QNX__)
# define _XOPEN_SOURCE 600
I'm unclear on the grand plan. Generally my view is that programs
should stick to POSIX, and that operating systems should make POSIX
available by default, and then any issues should be addressed as point
fixes only for environments that need them. I also think that a
program that sets a POSIX visibility define should not use any
interfaces except those defined by that POSIX version.
I also seen in config.h
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
which is a pretty big hammer.
__BSD_VISIBLE seems to be a FreeBSD thing, and AFAICT conceptually
similar to _NETBSD_SOURCE.
Here's a suggestion, to bring the build on NetBSD more in line with my
visibility define theory while not changing other systems:
diff --git a/config.h b/config.h
index 9f614f8c..57792e06 100644
--- a/config.h
+++ b/config.h
@@ -6,10 +6,12 @@
#ifdef __APPLE__
# define __DARWIN_C_SOURCE
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SYMBIAN32__)
+#elif defined(__FreeBSD__) || defined(__SYMBIAN32__)
# define _XOPEN_SOURCE 700
# define __BSD_VISIBLE 1
# define HAVE_NETINET_IN_H
+#elif defined(__NetBSD__)
+# define HAVE_NETINET_IN_H
#elif defined(__QNX__)
# define _XOPEN_SOURCE 600
# define __BSD_VISIBLE 1
I would also suggest only setting _GNU_SOURCE on systems known to use
glibc, or whereever it is actually needed. (I have the impression that
on Linux, a number of things specified by POSIX are not available unless
you specifically enable them. I don't understand why that is the case
but am guessing it's an artifact of history.)
I do find in NetBSD that clone() is made available via <sched.h> if
_GNU_SOURCE is defined, but that seems like an older interface not
specified by POSIX.