[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [mosquitto-dev] visibility defines
|
Hi Greg,
For the most part the non-Linux contributions have come via other
people when they've had problems. If removing the visibility macro is
fine for you that seems like the best solution. It seems to be fine on
FreeBSD as well. (I think it may be time to remove the Symbian
specific defines)
Regards,
Roger
On Sun, 13 Oct 2024 at 17:24, Greg Troxel via mosquitto-dev
<mosquitto-dev@xxxxxxxxxxx> wrote:
>
> 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.
>
> _______________________________________________
> mosquitto-dev mailing list
> mosquitto-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/mosquitto-dev