Skip to content

Commit c1951db

Browse files
authored
musl compat (#314)
* include: use __swab i/o __bswap_constant Some C standard libs like musl don't support __bswap_constant_{16,32}. Importing the "simple" macros could be enough, but they are under LGPL. Using __swab from linux/swab.h seems easier. Suggested-by: Ossama Othman <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> * mptcpize: define error() if not available Some libc like musl don't support it. It is easy enough to define a simple version for our need. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> * config: special case for default logger The current version taking an unlimited number of args, and with multiple levels of helpers doesn't seem to be supported on some embedded environments, e.g. Alpine Linux: configuration.c: In function 'mptcpd_config_create': configuration.c:54:47: error: pasting "l_log_set_" and "(" does not give a valid preprocessing token 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~ configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ | ^ configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~~~~ configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. | ^~~~~~~~~~~~~~~~~~~~~~~ configuration.c:54:47: error: implicit declaration of function 'l_log_set_'; did you mean 'l_log_set_null'? [-Werror=implicit-function-declaration] 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~ configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ | ^ configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~~~~ configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. | ^~~~~~~~~~~~~~~~~~~~~~~ configuration.c:54:47: error: called object is not a function or function pointer 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~ configuration.c:42:36: note: in definition of macro 'MPTCPD_CONCAT_IMPL' 42 | #define MPTCPD_CONCAT_IMPL(x, ...) x ## __VA_ARGS__ | ^ configuration.c:54:33: note: in expansion of macro 'MPTCPD_CONCAT' 54 | #define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER) | ^~~~~~~~~~~~~ configuration.c:802:9: note: in expansion of macro 'MPTCPD_SET_LOG_FUNCTION' 802 | MPTCPD_SET_LOG_FUNCTION(); // For early logging. | ^~~~~~~~~~~~~~~~~~~~~~~ It is not clear to me why it is failing, and simplifying the concatenation to two items, plus modifying the main helper to take the prefix in argument don't seem to help . A simple workaround is to have a special case for the default value, and do the concatenation only with the other cases. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> * scripts: use short stat options Busybox's stat doesn't understand the long options: stat: unrecognized option: dereference But it does support '-L'. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> --------- Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 48942b2 commit c1951db

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ AC_DEFINE_UNQUOTED([MPTCPD_LOGGER],
108108
[Log message destination.])
109109
AC_SUBST([mptcpd_logger],[$enable_logging])
110110

111+
AH_TEMPLATE([MPTCPD_LOGGER_STDERR],
112+
[Define to 1 if the stderr logger is used.])
113+
AS_IF([test "x$enable_logging" = "xstderr"],
114+
[AC_DEFINE([MPTCPD_LOGGER_STDERR])
115+
AC_MSG_NOTICE([default logger: stderr])],
116+
[AC_MSG_NOTICE([custom logger: $enable_logging])])
117+
111118
# Allow the user to choose support for either the upstream or
112119
# multipath-tcp.org kernel.
113120
AC_ARG_WITH([kernel],
@@ -273,6 +280,11 @@ AC_CHECK_FUNC([l_netlink_message_new_sized],
273280
[ELL has l_netlink_message_new_sized()])])
274281
LIBS=$mptcpd_save_libs
275282

283+
# ---------------------------------------------------------------
284+
# Checks for header files.
285+
# ---------------------------------------------------------------
286+
AC_CHECK_HEADERS([error.h])
287+
276288
# ---------------------------------------------------------------
277289
# Enable additional C compiler warnings. We do this after all
278290
# Autoconf tests have been run since not all autoconf macros are

include/mptcpd/private/sockaddr.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <byteswap.h>
1616

1717
#include <netinet/in.h> // For in_addr_t.
18+
#include <linux/swab.h> // For __constant_swab*.
1819

1920
#include <mptcpd/export.h>
2021

@@ -26,8 +27,8 @@
2627
*/
2728
///@{
2829
#if __BYTE_ORDER == __LITTLE_ENDIAN
29-
# define MPTCPD_CONSTANT_HTONS(hs) __bswap_constant_16(hs)
30-
# define MPTCPD_CONSTANT_HTONL(hl) __bswap_constant_32(hl)
30+
# define MPTCPD_CONSTANT_HTONS(hs) __swab16(hs)
31+
# define MPTCPD_CONSTANT_HTONL(hl) __swab32(hl)
3132
#else
3233
// No need to swap bytes on big endian platforms.
3334
// host byte order == network byte order

scripts/check-permissions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exit_status=0
1919

2020
for p in $@; do
2121
# Access rights in human readable form (e.g. "drwxrwxr-x")
22-
perms=`stat --dereference --format=%A $p`
22+
perms=`stat -L -c %A $p`
2323

2424
# The write mode for "others".
2525
other_write=`echo $perms | sed -e 's/.*\(.\).$/\1/'`

src/configuration.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@
5050
// This should never occur!
5151
# error Problem configuring default log message destination.
5252
#endif
53-
/// Name of the default logging function determined at compile-time.
54-
#define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER)
53+
// Optimisation for C standard library not supporting the concat macros.
54+
#ifdef MPTCPD_LOGGER_STDERR
55+
# define MPTCPD_SET_LOG_FUNCTION l_log_set_stderr
56+
#else
57+
/// Name of the logging function determined at compile-time.
58+
# define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER)
59+
#endif
5560

5661
/**
5762
* @brief Get the function that sets the log message destination.

src/mptcpize.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <argp.h>
1919
#include <dlfcn.h>
2020
#include <errno.h>
21-
#include <error.h>
2221
#include <fcntl.h>
2322
#include <stdio.h>
2423
#include <stdlib.h>
@@ -29,6 +28,10 @@
2928
# include <mptcpd/private/config.h>
3029
#endif
3130

31+
#ifdef HAVE_ERROR_H
32+
# include <error.h>
33+
#endif
34+
3235
#define SYSTEMD_ENV_VAR "Environment="
3336
#define SYSTEMD_UNIT_VAR "FragmentPath="
3437
#define SYSTEMD_SERVICE_TAG "[Service]"
@@ -55,6 +58,20 @@ static char doc[] =
5558
"\tdisable <unit> Update the systemd <unit>, removing\n"
5659
"\t the above launcher.\n";
5760

61+
#ifndef HAVE_ERROR_H
62+
# define ERROR_HELPER(status, errnum, format, ...) do { \
63+
if (errnum) { \
64+
errno = errnum; \
65+
perror(format); \
66+
} else { \
67+
fprintf(stderr, format "%s", __VA_ARGS__); \
68+
} \
69+
if (status) \
70+
exit(status); \
71+
} while(0)
72+
# define error(...) ERROR_HELPER(__VA_ARGS__, "\n")
73+
#endif
74+
5875
static struct argp const argp = { 0, 0, args_doc, doc, 0, 0, 0 };
5976

6077
static void help(void)

0 commit comments

Comments
 (0)