Skip to content

Commit

Permalink
build: Improve compatibility with Alpine Linux and musl.
Browse files Browse the repository at this point in the history
* Include Alpine Linux packages in install_prereq.sh
* Fix compilation errors on Alpine Linux / musl systems.
* Not all targets can build successfully with these changes,
  but this fixes the majority of issues that existed.
  • Loading branch information
InterLinked1 committed Feb 16, 2025
1 parent 227e434 commit 17efeea
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 21 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ jobs:
- name: Run basic tests
run: |
tests/test -ttest_menus -ddddddddd -DDDDDDDDDD -x
alpine-linux:
runs-on: ubuntu-24.04
name: Alpine Linux
container: alpine:latest
steps:
- uses: actions/checkout@v4
- name: Build LBBS
run: |
./scripts/install_prereq.sh
make modcheck
make modconfig
make -j$(nproc)
make install
make samples
make tests
fedora-42:
runs-on: ubuntu-24.04
name: Fedora 42
Expand Down
8 changes: 7 additions & 1 deletion bbs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ MAIN_SRC := $(wildcard *.c)
MAIN_OBJ = $(MAIN_SRC:.c=.o)
DEPENDS := $(patsubst %.c,%.d,$(MAIN_SRC))

ALPINE_LINUX := $(shell ls /etc/alpine-release | wc -l)

# the include directory is in the parent
INC = -I..

Expand Down Expand Up @@ -30,12 +32,16 @@ ifneq ($(LSFRAME_CHECK),1)
LIBS += -lsframe
endif

ifeq ($(UNAME_S),Linux)
ifeq ($(ALPINE_LINUX),1)
LIBS += -lcap
else ifeq ($(UNAME_S),Linux)
LIBS += -lbsd -lcap
endif

ifeq ($(UNAME_S),FreeBSD)
LIBS += -lexecinfo -lintl
else ifeq ($(ALPINE_LINUX),1)
LIBS += -lexecinfo
endif

all: $(EXE)
Expand Down
2 changes: 1 addition & 1 deletion bbs/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int __attribute__ ((format (gnu_printf, 5, 6))) __bbs_asprintf(const char *file,

size_t bbs_malloc_trim(void)
{
#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
int res;
size_t diff;
void *before, *after;
Expand Down
4 changes: 4 additions & 0 deletions bbs/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <unistd.h> /* use close */
#include <sys/time.h> /* use gettimeofday */

#if defined(linux) && !defined(__GLIBC__)
#include <libgen.h> /* use non-GNU basename */
#endif

#ifdef __FreeBSD__
#include <libgen.h> /* use basename */
#endif
Expand Down
2 changes: 1 addition & 1 deletion bbs/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int bbs_pty_allocate(struct bbs_node *node)
if (bbs_pthread_create(&node->ptythread, NULL, pty_master, node)) {
return -1;
}
#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
bbs_debug(8, "PTY thread %lu allocated for node %u\n", node->ptythread, node->id);
#endif

Expand Down
1 change: 1 addition & 0 deletions bbs/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/time.h> /* struct timeval for musl */
#include <netinet/in.h> /* use sockaddr_in */
#include <net/if.h> /* use ifreq */
#include <sys/un.h> /* use struct sockaddr_un */
Expand Down
2 changes: 1 addition & 1 deletion bbs/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#undef strlcat

#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
#include <bsd/string.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion bbs/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ static int set_limit(int resource, int value)
return 0;
}

limit = (unsigned long) value;
limit = (rlim_t) value;
memset(&r, 0, sizeof(r));

if (getrlimit(resource, &r)) {
Expand Down
2 changes: 2 additions & 0 deletions bbs/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ int __bbs_pthread_join(pthread_t thread, void **retval, const char *file, const
/* Now, proceed as normal and do a ~blocking pthread_join */
/* Seems that after using pthread_timedjoin_np, you can't do a blocking pthread_join anymore? So loop */
while (res && res == ETIMEDOUT) {
#if defined(__linux__) && defined(__GLIBC__)
bbs_debug(9, "Thread %lu not yet joined after %lus\n", thread, ts.tv_sec);
#endif
bbs_safe_sleep(250);
ts.tv_sec = 1; /* XXX Even this doesn't seem to make it work right */
res = pthread_timedjoin_np(thread, retval ? retval : &tmp, &ts);
Expand Down
5 changes: 5 additions & 0 deletions bbs/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <unistd.h>
#include <dirent.h>
#include <ftw.h>
#include <sys/time.h> /* struct timeval for musl */
#include <time.h> /* use time */
#include <sys/time.h> /* use gettimeofday */
#include <libgen.h> /* use dirname, basename (FreeBSD) */
Expand Down Expand Up @@ -968,7 +969,11 @@ ssize_t bbs_splice(int fd_in, int fd_out, size_t len)
{
/* Use splice(2) if available, otherwise fall back to sendfile(2) */
#ifdef __linux__
#ifdef __GLIBC__
off64_t off_in = 0;
#else
off_t off_in = 0;
#endif /* __GLIBC__ */
/* off_in must be NULL if fd_in is a pipe */
ssize_t res, written = 0;
for (;;) {
Expand Down
2 changes: 2 additions & 0 deletions include/bbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
#define sprintf(fmt, ...) Do_not_use_sprintf__use_snprintf
#define vsprintf(s, fmt, arg) Do_not_use_vsprintf__use_vsnprintf
/* Force usage of poll instead of the deprecated and unsafe select */
#ifdef __GLIBC__
#define select(nfds, readfds, writefds, exceptfds, timeout) Do_not_use_select__use_poll
#endif
/* Force usage of thread-safe functions */
#define localtime(a) Do_not_use_localtime__use_localtime_r
#define gmtime(a) Do_not_use_gmtime__use_gmtime_r
Expand Down
2 changes: 1 addition & 1 deletion io/io_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static int cli_compression(struct bbs_cli_args *a)
char send_pct[13], recv_pct[13];
snprintf(send_pct, sizeof(send_pct), "%d%%", (int) (100.0 * (double) z->sentbytes_comp / (double) z->sentbytes));
snprintf(recv_pct, sizeof(recv_pct), "%d%%", (int) (100.0 * (double) z->recvbytes_comp / (double) z->recvbytes));
#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
bbs_dprintf(a->fdout, "%3d %3d %8d %8d %5d %11lu %11lu %11lu %11lu %6s %6s %lu\n",
z->rpfd[0], z->wpfd[1], z->orig_rfd, z->orig_wfd, z->level, z->sentbytes, z->sentbytes_comp, z->recvbytes, z->recvbytes_comp, send_pct, recv_pct, z->thread);
#else
Expand Down
1 change: 1 addition & 0 deletions io/io_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <pthread.h>
#include <signal.h>
#include <ctype.h>
#include <sys/time.h> /* struct timeval for musl */

#include "include/module.h"
#include "include/node.h"
Expand Down
9 changes: 8 additions & 1 deletion modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ GMIME_FLAGS := $(filter-out -I/usr/include/libassuan2%,$(GMIME_FLAGS))
GMIME_LIBS=$(shell pkg-config --libs glib-2.0 gmime-3.0)
MYSQL_LIBS := $(shell mysql_config --libs)

ALPINE_LINUX := $(shell ls /etc/alpine-release | wc -l)
MOD_WEBMAIL_LIBS := -ljansson -lssl -lcrypto
ifneq ($(ALPINE_LINUX),1)
MOD_WEBMAIL_LIBS += -ldb-5.3
endif
MOD_WEBMAIL_LIBS += -lz

ETPANCFLAGS=-I/usr/local/include

all: $(MOD_SO)
Expand Down Expand Up @@ -120,7 +127,7 @@ mod_smtp_filter_spf.so : mod_smtp_filter_spf.o

mod_webmail.so : mod_webmail.o
@echo " [LD] $^ -> $@"
$(CC) -shared -fPIC -o $(basename $^).so $^ -ljansson -lssl -lcrypto -ldb-5.3 -lz -L/usr/local/lib -Wl,-rpath=/usr/local/lib/ -letpan
$(CC) -shared -fPIC -o $(basename $^).so $^ $(MOD_WEBMAIL_LIBS) -L/usr/local/lib -Wl,-rpath=/usr/local/lib/ -letpan

# Don't automatically remove intermediate .o files, to prevent unnecessary recompilations
.SECONDARY: $(patsubst %.c,%.o,$(MOD_SRC))
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_irc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ static int cli_irc_irc_clients(struct bbs_cli_args *a)
bbs_dprintf(a->fdout, "%-20s %6s %3s %9s %-15s %s\n", "Name", "Status", "Log", "Callbacks", "Thread", "BotMsgScript");
RWLIST_RDLOCK(&irc_clients);
RWLIST_TRAVERSE(&irc_clients, c, entry) {
#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
bbs_dprintf(a->fdout, "%-20s %6s %3s %9s %15lu %s\n", c->name, irc_client_connected(c->client) ? "Online" : "Offline", BBS_YN(c->log), BBS_YN(c->callbacks), c->thread, S_IF(c->msgscript));
#else
bbs_dprintf(a->fdout, "%-20s %6s %3s %9s %15s %s\n", c->name, irc_client_connected(c->client) ? "Online" : "Offline", BBS_YN(c->log), BBS_YN(c->callbacks), "", S_IF(c->msgscript));
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_irc_relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <signal.h>
#include <unistd.h>

#ifdef __linux__
#if defined(__linux__) && defined(__GLIBC__)
#include <bsd/string.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions modules/mod_mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <signal.h>
#include <dirent.h>
#include <libgen.h> /* use dirname */
#include <sys/time.h> /* struct timeval for musl */

#include "include/linkedlists.h"
#include "include/module.h"
Expand Down
9 changes: 9 additions & 0 deletions modules/mod_mailscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <regex.h>
#include <float.h>

#if defined(linux) && !defined(__GLIBC__)
#include <libgen.h> /* use non-GNU basename */
#endif

#include "include/module.h"
#include "include/system.h"
#include "include/stringlist.h"
Expand Down Expand Up @@ -383,6 +387,11 @@ static int exec_cmd(struct smtp_msg_process *mproc, char *s)
}

/* Calculate the path of the temp file we are going to create */
#if defined(linux) && !defined(__GLIBC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
res = bbs_transfer_home_config_file(mproc->userid, basename(mproc->datafile), tmpfile, sizeof(tmpfile));
if (res == -1) {
return 1; /* Couldn't calculate path */
Expand Down
21 changes: 15 additions & 6 deletions modules/mod_smtp_delivery_external.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,20 @@ static struct stringlist *get_static_routes(const char *domain)
*/
static int lookup_mx_all(const char *domain, struct stringlist *results)
{
char *hostname, *tmp;
unsigned char answer[PACKETSZ] = "";
char dispbuf[PACKETSZ] = "";
char domainbuf[256];
int res, i;
ns_msg msg;
ns_rr rr;
struct mx_records mxs; /* No need to bother locking this list, nobody else knows about it */
int priority;
int res;
struct mx_record *mx;
int added = 0;
ns_msg msg;
#if !defined(linux) || defined(__GLIBC__)
char dispbuf[PACKETSZ] = "";
char *hostname, *tmp;
int i;
ns_rr rr;
int priority;
#endif

if (strlen_zero(domain)) {
bbs_error("Missing domain\n");
Expand Down Expand Up @@ -214,6 +217,11 @@ static int lookup_mx_all(const char *domain, struct stringlist *results)

RWLIST_HEAD_INIT(&mxs);

#if defined(linux) && !defined(__GLIBC__)
/* ns_sprintrr isn't available with musl */
bbs_error("MX record lookups unavailable on this platform, use static mail routing on this system instead\n");
return -1;
#else
/* Add each record to our sorted list */
for (i = 0; i < res; i++) {
ns_parserr(&msg, ns_s_an, i, &rr);
Expand Down Expand Up @@ -273,6 +281,7 @@ static int lookup_mx_all(const char *domain, struct stringlist *results)
RWLIST_INSERT_SORTED(&mxs, mx, entry, priority);
added++;
}
#endif /* defined(linux) && !defined(__GLIBC__) */

if (!added) {
bbs_warning("No MX records available for %s\n", domain);
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_spamassassin.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "include/bbs.h"

#include <wait.h>
#include <sys/wait.h>

#include "include/module.h"
#include "include/utils.h"
Expand Down
2 changes: 1 addition & 1 deletion nets/net_imap/imap_server_flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string.h>
#include <ctype.h>

#ifdef __linux__
#if defined(linux) && defined(__GLIBC__)
#include <bsd/string.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions nets/net_smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <signal.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h> /* struct timeval for musl */

#include <dirent.h> /* for msg_to_filename */

Expand Down
2 changes: 2 additions & 0 deletions nets/net_telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include <netinet/in.h> /* use sockaddr_in */

/* Expose the telcmds and telopts string arrays */
#if !defined(linux) || defined(__GLIBC__)
#define TELCMDS
#endif
#define TELOPTS
#include "arpa/telnet.h"

Expand Down
Loading

0 comments on commit 17efeea

Please sign in to comment.