Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl compat #314

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ AC_CHECK_FUNC([l_netlink_message_new_sized],
[ELL has l_netlink_message_new_sized()])])
LIBS=$mptcpd_save_libs

# ---------------------------------------------------------------
# Checks for header files.
# ---------------------------------------------------------------
AC_CHECK_HEADERS([error.h])

# ---------------------------------------------------------------
# Enable additional C compiler warnings. We do this after all
# Autoconf tests have been run since not all autoconf macros are
Expand Down
10 changes: 10 additions & 0 deletions include/mptcpd/private/sockaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
*/
///@{
#if __BYTE_ORDER == __LITTLE_ENDIAN
/* These 2 helpers come from GNU C Library, under LGPL */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a macro, I guess it is fine to copy it.

If not, we only use it in one place, with one address in lib, and multiple ones in the tests.

Maybe that's enough to hardcode the address in lib. The tests need further modifications to support musl I think.

# ifndef __bswap_constant_16
# define __bswap_constant_16(x) \
((__uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
# endif
# ifndef __bswap_constant_32
# define __bswap_constant_32(x) \
((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) \
| (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
# endif
# define MPTCPD_CONSTANT_HTONS(hs) __bswap_constant_16(hs)
# define MPTCPD_CONSTANT_HTONL(hl) __bswap_constant_32(hl)
#else
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exit_status=0

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

# The write mode for "others".
other_write=`echo $perms | sed -e 's/.*\(.\).$/\1/'`
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@
// This should never occur!
# error Problem configuring default log message destination.
#endif
#if MPTCPD_LOGGER == stderr
#define MPTCPD_SET_LOG_FUNCTION l_log_set_stderr
#else
/// Name of the default logging function determined at compile-time.
#define MPTCPD_SET_LOG_FUNCTION MPTCPD_CONCAT(l_log_set_, MPTCPD_LOGGER)
#endif

/**
* @brief Get the function that sets the log message destination.
Expand Down
19 changes: 18 additions & 1 deletion src/mptcpize.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <argp.h>
#include <dlfcn.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -29,6 +28,10 @@
# include <mptcpd/private/config.h>
#endif

#ifdef HAVE_ERROR_H
# include <error.h>
#endif

#define SYSTEMD_ENV_VAR "Environment="
#define SYSTEMD_UNIT_VAR "FragmentPath="
#define SYSTEMD_SERVICE_TAG "[Service]"
Expand All @@ -53,6 +56,20 @@ static char doc[] =
"\tdisable <unit> Update the systemd <unit>, removing\n"
"\t the above launcher.\n";

#ifndef HAVE_ERROR_H
# define ERROR_HELPER(status, errnum, format, ...) do { \
if (errnum) { \
errno = errnum; \
perror(format); \
} else { \
fprintf(stderr, format "%s", __VA_ARGS__); \
} \
if (status) \
exit(status); \
} while(0)
# define error(...) ERROR_HELPER(__VA_ARGS__, "\n")
#endif

static struct argp const argp = { 0, 0, args_doc, doc, 0, 0, 0 };

static void help(void)
Expand Down