Skip to content

Commit

Permalink
[musl] Fix __GLIBC__ tests. JB#49555
Browse files Browse the repository at this point in the history
The __GLIBC__ macro gets defined when some suitable libc header file
is included. Thus such test will produce false negatives if performed
before including appropriate headers.

Move all musl-libc compatibility handling to occur after all other
header files have been included. In case of unique tests, make sure
there is #include <features.h> before the ifdef test. And in case of
musl-compatibility.h - which is included from multiple places - move
the testing within the header to avoid copy paste tests.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 24, 2020
1 parent b65ad9c commit a0a9f9b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
16 changes: 16 additions & 0 deletions .depend
Expand Up @@ -28,26 +28,30 @@ dsme/dsme-server.pic.o:\

dsme/dsme-wdd-wd.o:\
dsme/dsme-wdd-wd.c\
include/dsme/musl-compatibility.h\
dsme/dsme-rd-mode.h\
dsme/dsme-wdd-wd.h\
dsme/dsme-wdd.h\

dsme/dsme-wdd-wd.pic.o:\
dsme/dsme-wdd-wd.c\
include/dsme/musl-compatibility.h\
dsme/dsme-rd-mode.h\
dsme/dsme-wdd-wd.h\
dsme/dsme-wdd.h\

dsme/dsme-wdd.o:\
dsme/dsme-wdd.c\
include/dsme/logging.h\
include/dsme/musl-compatibility.h\
include/dsme/oom.h\
dsme/dsme-wdd-wd.h\
dsme/dsme-wdd.h\

dsme/dsme-wdd.pic.o:\
dsme/dsme-wdd.c\
include/dsme/logging.h\
include/dsme/musl-compatibility.h\
include/dsme/oom.h\
dsme/dsme-wdd-wd.h\
dsme/dsme-wdd.h\
Expand Down Expand Up @@ -146,6 +150,7 @@ modules/abootsettings.o:\
include/dsme/modulebase.h\
include/dsme/modules.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
modules/dbusproxy.h\
modules/dsme_dbus.h\

Expand All @@ -155,6 +160,7 @@ modules/abootsettings.pic.o:\
include/dsme/modulebase.h\
include/dsme/modules.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
modules/dbusproxy.h\
modules/dsme_dbus.h\

Expand Down Expand Up @@ -318,6 +324,7 @@ modules/heartbeat.pic.o:\

modules/iphb.o:\
modules/iphb.c\
include/dsme/musl-compatibility.h\
dsme/dsme-server.h\
dsme/dsme-wdd-wd.h\
dsme/utility.h\
Expand All @@ -333,6 +340,7 @@ modules/iphb.o:\

modules/iphb.pic.o:\
modules/iphb.c\
include/dsme/musl-compatibility.h\
dsme/dsme-server.h\
dsme/dsme-wdd-wd.h\
dsme/utility.h\
Expand Down Expand Up @@ -574,6 +582,7 @@ modules/thermalsensor_generic.o:\
modules/thermalsensor_generic.c\
include/dsme/logging.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
include/dsme/timers.h\
modules/dbusproxy.h\
modules/thermalmanager.h\
Expand All @@ -582,6 +591,7 @@ modules/thermalsensor_generic.pic.o:\
modules/thermalsensor_generic.c\
include/dsme/logging.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
include/dsme/timers.h\
modules/dbusproxy.h\
modules/thermalmanager.h\
Expand Down Expand Up @@ -629,13 +639,19 @@ modules/usbtracker.pic.o:\
modules/validatorlistener.o:\
modules/validatorlistener.c\
include/dsme/logging.h\
include/dsme/modulebase.h\
include/dsme/modules.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
modules/malf.h\

modules/validatorlistener.pic.o:\
modules/validatorlistener.c\
include/dsme/logging.h\
include/dsme/modulebase.h\
include/dsme/modules.h\
include/dsme/modules.h\
include/dsme/musl-compatibility.h\
modules/malf.h\

modules/vibrafeedback.o:\
Expand Down
2 changes: 0 additions & 2 deletions dsme/dsme-wdd-wd.h
Expand Up @@ -31,9 +31,7 @@

#include <stdbool.h>

#ifndef __GLIBC__
#include "../include/dsme/musl-compatibility.h"
#endif

// Period for kicking; i.e. how soon the quickest watchdog will bite.
// NOTE: This must be picked from the wd[] array in dsme-wdd-wd.c!
Expand Down
27 changes: 23 additions & 4 deletions include/dsme/musl-compatibility.h
@@ -1,9 +1,28 @@
/* Used to retry syscalls that can return EINTR. Taken from bionic unistd.h */
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) ({ \
#ifndef DSME_MUSL_COMPATIBILITY_H_
# define DSME_MUSL_COMPATIBILITY_H_

/* Whether __GLIBC__ gets defined when compiling against gnu libc,
* depends on what - if any - libc header files have been included
* so far. To be sure, include features.h that contains the define.
*/
# include <features.h>

/* Define equivalents for glibc macros that dsme sources are using,
* but are not defined in musl libc headers.
*/
# ifndef __GLIBC__

/* Used to retry syscalls that can return EINTR. Taken from bionic unistd.h
*/
# ifndef TEMP_FAILURE_RETRY
# define TEMP_FAILURE_RETRY(exp) ({ \
__typeof__(exp) _rc; \
do { \
_rc = (exp); \
} while (_rc == -1 && errno == EINTR); \
_rc; })
#endif
# endif

# endif /* not __GLIBC__ */

#endif /* DSME_MUSL_COMPATIBILITY_H_ */
6 changes: 2 additions & 4 deletions modules/abootsettings.c
Expand Up @@ -32,10 +32,6 @@
#include "../include/dsme/modulebase.h"
#include "../include/dsme/logging.h"

#ifndef __GLIBC__
#include "../include/dsme/musl-compatibility.h"
#endif

#include <dsme/state.h>

#include <glib.h>
Expand All @@ -48,6 +44,8 @@
#include <fcntl.h>
#include <linux/fs.h>

#include "../include/dsme/musl-compatibility.h"

#define PFIX "abootsettings: "
// Device info magic string (from aboot)
#define DEVICE_MAGIC "ANDROID-BOOT!"
Expand Down
8 changes: 5 additions & 3 deletions modules/diskmonitor.c
Expand Up @@ -55,12 +55,14 @@
#include <time.h>
#include <mntent.h>

#include <glib.h>

/* musl-libc compatibility */
#include <features.h> // for __GLIBC__
#ifndef __GLIBC__
#include <paths.h>
# include <paths.h>
#endif

#include <glib.h>

/* ========================================================================= *
* TYPES
* ========================================================================= */
Expand Down
6 changes: 2 additions & 4 deletions modules/thermalsensor_generic.c
Expand Up @@ -32,10 +32,6 @@
#include "../include/dsme/timers.h"
#include "../include/dsme/logging.h"

#ifndef __GLIBC__
#include "../include/dsme/musl-compatibility.h"
#endif

#include "dbusproxy.h"

/* ========================================================================= *
Expand All @@ -57,6 +53,8 @@

#include <glib.h>

#include "../include/dsme/musl-compatibility.h"

/* ========================================================================= *
* DIAGNOSTIC_LOGGING
* ========================================================================= */
Expand Down
2 changes: 2 additions & 0 deletions modules/upstart.c
Expand Up @@ -42,6 +42,8 @@
#include <sys/utsname.h>
#include <sys/time.h>

/* musl-libc compatibility */
#include <features.h> // for __GLIBC__
#ifndef __GLIBC__
# include <utmp.h>
# if defined _PATH_UTMP && !defined _PATH_UTMPX
Expand Down
5 changes: 1 addition & 4 deletions modules/validatorlistener.c
Expand Up @@ -36,10 +36,6 @@
#include "../include/dsme/logging.h"
#include "../include/dsme/modulebase.h"

#ifndef __GLIBC__
#include "../include/dsme/musl-compatibility.h"
#endif

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -50,6 +46,7 @@
#include <ctype.h>
#include <errno.h>

#include "../include/dsme/musl-compatibility.h"

#define DSME_STATIC_STRLEN(s) (sizeof(s) - 1)

Expand Down

0 comments on commit a0a9f9b

Please sign in to comment.