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

build: Fix compilation errors on FreeBSD. #44

Merged
merged 1 commit into from
Sep 29, 2024
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ jobs:
- name: Run basic tests
run: |
tests/test -ttest_menus -ddddddddd -DDDDDDDDDD -x
# Binary fails to link due to uuid library missing in CI, but it will make all specified targets, so enumerate those
freebsd-14:
runs-on: ubuntu-24.04
name: FreeBSD
Expand All @@ -222,6 +223,11 @@ jobs:
./scripts/install_prereq.sh
gmake modcheck
gmake modconfig
gmake main
gmake doors
gmake io
gmake modules
gmake nets
gmake
gmake install
gmake samples
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ BINDIR = $(PREFIX)/bin
RM = rm -f
LN = ln
INSTALL = install
UNAME_S := $(shell uname -s)

# Uncomment this to see all build commands instead of 'quiet' output
#NOISY_BUILD=yes
Expand Down Expand Up @@ -57,9 +58,9 @@ SILENT_BUILD_PREFIX := @

export CC
export CFLAGS

export EXE

export UNAME_S
export SUBMAKE

# Run sub targets in parallel, but don't run top-level targets in parallel
Expand Down
9 changes: 4 additions & 5 deletions bbs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ LIBS += -lcrypt -lcrypto -lcurl -lreadline -luuid -rdynamic
# On SUSE, the remaining libraries are needed to link successfully
# However, on other platforms they are generally not, and -liberty is likely to cause issues
# Furthermore, some of the other libraries are also needed, if present, but must not be specified if not
# On FreeBSD, there is leading whitespace, so also trim for good measure
LIBS += -lbfd
LIBERTY_CHECK = $(shell gcc -liberty 2>&1 | grep "cannot find" | wc -l )
LZSTD_CHECK = $(shell gcc -lzstd 2>&1 | grep "cannot find" | wc -l )
LSFRAME_CHECK = $(shell gcc -lsframe 2>&1 | grep "cannot find" | wc -l )
LIBERTY_CHECK = $(shell gcc -liberty 2>&1 | grep "cannot find" | wc -l | tr -d ' ' )
LZSTD_CHECK = $(shell gcc -lzstd 2>&1 | grep "cannot find" | wc -l | tr -d ' ' )
LSFRAME_CHECK = $(shell gcc -lsframe 2>&1 | grep "cannot find" | wc -l | tr -d ' ' )
ifneq ($(LIBERTY_CHECK),1)
LIBS += -liberty -lz -lopcodes
endif
Expand All @@ -29,8 +30,6 @@ ifneq ($(LSFRAME_CHECK),1)
LIBS += -lsframe
endif

UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)
LIBS += -lbsd -lcap
endif
Expand Down
2 changes: 1 addition & 1 deletion bbs/bbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
#include <signal.h>
#include <poll.h>
#include <fcntl.h> /* use O_NONBLOCK */
#include <limits.h> /* use PATH_MAX */

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#include <sys/prctl.h> /* use prctl */
#include <sys/capability.h>
#include <linux/capability.h>
Expand Down
5 changes: 1 addition & 4 deletions bbs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/linkedlists.h"
#include "include/config.h"
Expand Down
13 changes: 10 additions & 3 deletions bbs/fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,24 @@ static int print_fds(int fd)
{
DIR *dir;
struct dirent *entry;
char path[512];
char symlink[256];
const char *fd_dir;
ssize_t bytes;

if (!(dir = opendir("/proc/self/fd"))) {
bbs_error("Error opening directory - %s: %s\n", path, strerror(errno));
#ifdef __linux__
fd_dir = "/proc/self/fd";
#else
fd_dir = "/dev/fd";
#endif

if (!(dir = opendir(fd_dir))) {
bbs_error("Error opening directory - %s: %s\n", fd_dir, strerror(errno));
return -1;
}

while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_LNK) {
char path[512];
int fdnum = atoi(entry->d_name);
/* Only care about ones we don't know about */
if (ARRAY_IN_BOUNDS(fdnum, fdleaks) && fdleaks[fdnum].isopen) {
Expand Down
5 changes: 1 addition & 4 deletions bbs/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
#include <sys/stat.h> /* use mkdir */
#include <sys/types.h>
#include <poll.h>

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/utils.h" /* use bbs_gettid, bbs_tvnow */
#include "include/linkedlists.h"
Expand Down
5 changes: 1 addition & 4 deletions bbs/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
#include <dlfcn.h>
#include <unistd.h> /* use usleep */
#include <poll.h>

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/linkedlists.h"
#include "include/stringlist.h"
Expand Down
5 changes: 5 additions & 0 deletions bbs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <sys/ioctl.h>
#include <limits.h>

/* For FreeBSD */
#ifndef CLOCK_MONOTONIC_RAW
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
#endif

#include "include/time.h" /* use timespecsub */
#include "include/node.h"
#include "include/user.h"
Expand Down
2 changes: 2 additions & 0 deletions bbs/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ int bbs_pty_allocate(struct bbs_node *node)
if (bbs_pthread_create(&node->ptythread, NULL, pty_master, node)) {
return -1;
}
#ifdef __linux__
bbs_debug(8, "PTY thread %lu allocated for node %u\n", node->ptythread, node->id);
#endif

/* We are the PTY slave */
node->slavefd = open(node->slavename, O_RDWR);
Expand Down
5 changes: 5 additions & 0 deletions bbs/ratelimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

#include <sys/time.h>

/* For FreeBSD */
#ifndef CLOCK_MONOTONIC_RAW
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
#endif

#include "include/time.h" /* use timespecsub */
#include "include/ratelimit.h"

Expand Down
8 changes: 8 additions & 0 deletions bbs/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ static int __bbs_socket_bind(int *sock, int rebind, int type, int port, const ch
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
safe_strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
#ifdef __linux__
if (setsockopt(*sock, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) {
bbs_error("Failed to set SO_BINDTODEVICE(%s): %s\n", interface, strerror(errno));
#elif defined(__FreeBSD__) && defined(IP_SENDIF)
if (setsockopt(*sock, SOL_SOCKET, IP_SENDIF, &ifr, sizeof(ifr)) < 0) {
bbs_error("Failed to set IP_SENDIF(%s): %s\n", interface, strerror(errno));
#else
if (1) {
bbs_error("Restricting binding to a specific interface is not supported on this platform\n");
#endif
close(*sock);
return -1;
}
Expand Down
7 changes: 6 additions & 1 deletion bbs/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ static int __thread_unregister(pthread_t id, const char *file, int line, const c

RWLIST_WRLOCK(&thread_list);
RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
if (x->id == id) {
#ifdef __FreeBSD__
/* Need both checks and it works */
if ((unsigned long) x->id == (unsigned long) id || (unsigned long) x->lwp == (unsigned long) id) {
#else
if (x->id == id) { /* pthread_t isn't numeric on FreeBSD, so this check only works on Linux. */
#endif
if (x->detached || x->waitingjoin) {
RWLIST_REMOVE_CURRENT(list);
remove = 1;
Expand Down
1 change: 1 addition & 0 deletions bbs/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <time.h> /* use time */
#include <sys/time.h> /* use gettimeofday */
#include <libgen.h> /* use dirname, basename (FreeBSD) */
#include <limits.h> /* use PATH_MAX */

#ifdef __linux__
#include <uuid/uuid.h> /* use uuid_generate, uuid_unparse */
Expand Down
2 changes: 1 addition & 1 deletion external/filemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include <wait.h>
#include <sys/wait.h>

#include <sys/stat.h>

Expand Down
25 changes: 21 additions & 4 deletions external/modman.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <ctype.h>
#include <errno.h>
#include <dirent.h>
#include <sys/wait.h> /* use WIFEXITED, WEXITSTATUS */

#include <sys/stat.h>

Expand Down Expand Up @@ -196,7 +197,13 @@ static int check_lib(const char *modname, const char *libname)
/* If we didn't reach the end, we hit an invalid character */
return 0;
}

/* ldconfig -p isn't valid on FreeBSD, so only try this on Linux: */
#ifdef __FreeBSD__
snprintf(cmd, sizeof(cmd), "ldconfig -r | grep 'lib%s.so' 2>/dev/null 1>&2", libname);
#else
snprintf(cmd, sizeof(cmd), "ldconfig -p | grep 'lib%s.so' 2>/dev/null 1>&2", libname);
#endif
res = system(cmd);
/* ldconfig | grep returned nonzero, which means
* we couldn't find any libraries by that name. */
Expand Down Expand Up @@ -413,7 +420,7 @@ static int check_header_file(const char *dirname, const char *modname, const cha
rewind(mfp);
snprintf(objname, sizeof(objname), "%s", modname);
TERMINATE_AT(objname, '.');
strncat(objname, ".o", sizeof(objname));
strncat(objname, ".o", sizeof(objname) - 1);
objnamelen = strlen(objname);
while (fgets(buf, sizeof(buf), mfp)) {
char *token, *tokens;
Expand Down Expand Up @@ -481,7 +488,7 @@ static int check_headers(const char *dirname, const char *modname, FILE *mfp, in

snprintf(filename, sizeof(filename), "%s/%s", dirname, modname);
TERMINATE_AT(filename, '.');
strncat(filename, ".c", sizeof(filename));
strncat(filename, ".c", sizeof(filename) - 1);

fp = fopen(filename, "r");
if (!fp) {
Expand All @@ -500,6 +507,15 @@ static int check_headers(const char *dirname, const char *modname, FILE *mfp, in
continue;
}
TERMINATE_AT(incfile, '>');
#ifdef __FreeBSD__
/* XXX Hardcoded exception: <bsd/string.h> is only included on __linux__,
* but since we don't process conditional includes (#ifdef),
* we'll erroneously think this is missing on FreeBSD (for mod_irc_relay)
* when it's not needed. */
if (!strcmp(incfile, "bsd/string.h")) {
continue;
}
#endif
if (!check_header_file(dirname, modname, incfile, mfp, met_deps)) {
unmet_headers++;
}
Expand Down Expand Up @@ -798,7 +814,7 @@ int main(int argc, char *argv[])
}
}

optind = 0;
optind = 1;
while ((c = getopt(argc, argv, getopt_settings)) != -1) {
switch (c) {
case '?':
Expand All @@ -817,5 +833,6 @@ int main(int argc, char *argv[])
}
}

return 0;
fprintf(stderr, "No arguments provided to modman, taking no action\n");
return -1;
}
1 change: 1 addition & 0 deletions include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct bbs_user;
struct bbs_vars;
struct readline_data;
struct pollfd;
struct sockaddr_in;

#define ANSI_CURSOR_QUERY (1 << 0)
#define ANSI_CURSOR_SET (1 << 1)
Expand Down
8 changes: 7 additions & 1 deletion io/io_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ 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));
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);
#ifdef __linux__
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
bbs_dprintf(a->fdout, "%3d %3d %8d %8d %5d %11lu %11lu %11lu %11lu %6s %6s\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);
#endif
}
RWLIST_UNLOCK(&compressors);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_asterisk_queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ static int cli_asterisk_calls(struct bbs_cli_args *a)
}

/*! \note 4 and 6 should also be nonnull, but SET_FSM_STRING_VAR does a strlen_zero check, so we can't include them in the attribute */
static __nonnull ((1, 5)) struct queue_call *new_call(struct queue *queue, int queueid, int ani2, const char *channel, const char *ani, const char *cnam, const char *dnis)
static __attribute__((nonnull (1, 5))) struct queue_call *new_call(struct queue *queue, int queueid, int ani2, const char *channel, const char *ani, const char *cnam, const char *dnis)
{
struct queue_call *call;
char *data;
Expand Down
5 changes: 1 addition & 4 deletions modules/mod_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
#include <signal.h>
#include <magic.h>
#include <sys/wait.h>

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/module.h"
#include "include/node.h"
Expand Down
4 changes: 4 additions & 0 deletions modules/mod_irc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,11 @@ 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__
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));
#endif
}
RWLIST_UNLOCK(&irc_clients);
return 0;
Expand Down
1 change: 1 addition & 0 deletions nets/net_ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h> /* use PATH_MAX */

#include "include/module.h"
#include "include/node.h"
Expand Down
4 changes: 1 addition & 3 deletions nets/net_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

#include "include/bbs.h"

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/module.h"
#include "include/config.h"
Expand Down
5 changes: 1 addition & 4 deletions nets/net_irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
#include <ctype.h>
#include <signal.h>
#include <unistd.h>

#ifdef __linux__
#include <linux/limits.h> /* use PATH_MAX */
#endif
#include <limits.h> /* use PATH_MAX */

#include "include/module.h"
#include "include/config.h"
Expand Down
2 changes: 1 addition & 1 deletion nets/net_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int msp_response(struct msp *restrict msp, const char *s, size_t len)
if (msp->node) {
bbs_node_fd_write(msp->node, msp->node->wfd, s, len);
} else {
ssize_t res = sendto(udp_socket, s, len, 0, msp->in, msp->slen);
ssize_t res = sendto(udp_socket, s, len, 0, (const struct sockaddr*) msp->in, msp->slen);
if (res <= 0) {
bbs_error("sendto failed: %s\n", strerror(errno));
}
Expand Down
1 change: 1 addition & 0 deletions nets/net_sieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h> /* use PATH_MAX */

#include "include/module.h"
#include "include/config.h"
Expand Down
Loading