Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Musl libc incompatibilities
TEMP_FAILURE_RETRY is not available on Musl, so I've taken the Bionic
implementation (BSD-3, should be compatible with LGPL-2.1?) and included
it when glibc is undefined.

Furthermore _PATH_UTMPX and _PATH_WTMPX do not exist on Musl, however it
has _PATH_UTMP and _PATH_WTMP stubbed which can be used instead to make
it compile.

Then I've changed the old uint* for their uint*_t replacements.

Lastly there we some wrong includes

Signed-off-by: Bart Ribbers <bribbers@disroot.org>
  • Loading branch information
PureTryOut committed Jun 15, 2020
1 parent 059b03b commit aa30ffa
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 26 deletions.
4 changes: 4 additions & 0 deletions dsme/dsme-wdd-wd.h
Expand Up @@ -31,6 +31,10 @@

#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!
#define DSME_SHORTEST_WD_PERIOD 20 // seconds
Expand Down
6 changes: 3 additions & 3 deletions dsme/modulebase.c
Expand Up @@ -55,7 +55,7 @@ struct module_t {
Registered handler information.
*/
typedef struct {
u_int32_t msg_type;
uint32_t msg_type;
size_t msg_size;
const module_t* owner;
handler_fn_t* callback;
Expand Down Expand Up @@ -162,7 +162,7 @@ static const struct ucred bogus_ucred = {
static int msg_comparator(gconstpointer a, gconstpointer b)
{
const msg_handler_info_t* handler = (msg_handler_info_t*)a;
u_int32_t msg_type = GPOINTER_TO_UINT(b);
uint32_t msg_type = GPOINTER_TO_UINT(b);

return compare(handler->msg_type, msg_type);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ static int name_comparator(const module_t* node, const char* name)
#endif


static int modulebase_add_single_handler(u_int32_t msg_type,
static int modulebase_add_single_handler(uint32_t msg_type,
size_t msg_size,
handler_fn_t* callback,
const module_t* owner)
Expand Down
2 changes: 1 addition & 1 deletion include/dsme/modules.h
Expand Up @@ -66,7 +66,7 @@ typedef void (handler_fn_t)(endpoint_t* sender, const dsmemsg_generic_t* msg);
Handler information entry in module.
*/
typedef struct {
u_int32_t msg_type;
uint32_t msg_type;
handler_fn_t* callback;
size_t msg_size;
} module_fn_info_t;
Expand Down
10 changes: 10 additions & 0 deletions include/dsme/musl-compatibility.h
@@ -0,0 +1,10 @@
/* 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

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

#ifndef __GLIBC__
#include "../include/dsme/temp-failure-retry.h"
#endif

#include <dsme/state.h>

#include <glib.h>
Expand Down
4 changes: 4 additions & 0 deletions modules/diskmonitor.c
Expand Up @@ -55,6 +55,10 @@
#include <time.h>
#include <mntent.h>

#ifndef __GLIBC__
#include <paths.h>
#endif

#include <glib.h>

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

#ifndef __GLIBC__
#include "../include/dsme/temp-failure-retry.h"
#endif

#include "dbusproxy.h"

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

#ifndef __GLIBC__
# include <utmp.h>
# if defined _PATH_UTMP && !defined _PATH_UTMPX
# define _PATH_UTMPX _PATH_UTMP
# endif
# if defined _PATH_WTMP && !defined _PATH_WTMPX
# define _PATH_WTMPX _PATH_WTMP
# endif
#endif


static bool save_state_for_getbootstate(dsme_runlevel_t runlevel);
static bool telinit_internal(dsme_runlevel_t runlevel);
Expand Down
5 changes: 5 additions & 0 deletions modules/validatorlistener.c
Expand Up @@ -34,6 +34,11 @@
#include "malf.h"
#include "../include/dsme/modules.h"
#include "../include/dsme/logging.h"
#include "../include/dsme/modulebase.h"

#ifndef __GLIBC__
#include "../include/dsme/temp-failure-retry.h"
#endif

#include <string.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion test/dsmetest.c
Expand Up @@ -31,7 +31,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
Expand Down
38 changes: 17 additions & 21 deletions test/dummy_bme.c
Expand Up @@ -34,7 +34,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/poll.h>
#include <poll.h>
#include <sys/syslog.h>


Expand All @@ -52,34 +52,30 @@
#define bme_log(L, FMT ...) fprintf(stderr, FMT);

#include <sys/types.h>
typedef __uint8_t uint8;
typedef __uint16_t uint16;
typedef __uint32_t uint32;

typedef struct {
uint16 type, subtype;
uint16_t type, subtype;
} tBMEmsgGeneric;


struct emsg_battery_info_req {
uint16 type, subtype;
uint32 flags;
uint16_t type, subtype;
uint32_t flags;
};

/* Battery info reply */
struct emsg_battery_info_reply {
uint32 a;
uint32 flags;
uint16 c;
uint16 d;
uint16 temp;
uint16 f;
uint16 g;
uint16 h;
uint16 i;
uint16 j;
uint16 k;
uint16 l;
uint32_t a;
uint32_t flags;
uint16_t c;
uint16_t d;
uint16_t temp;
uint16_t f;
uint16_t g;
uint16_t h;
uint16_t i;
uint16_t j;
uint16_t k;
uint16_t l;
};

union emsg_battery_info {
Expand Down Expand Up @@ -204,7 +200,7 @@ int bme_handle_new_client(int fd)
int em_srv_battery_info_req(struct emsg_battery_info_req *reqp, int client)
{
struct emsg_battery_info_reply reply;
uint32 flags;
uint32_t flags;

memset(&reply, 0, sizeof(reply));
flags = reply.flags = reqp->flags;
Expand Down

0 comments on commit aa30ffa

Please sign in to comment.