Skip to content

Commit 5201d13

Browse files
committed
build: Fix compilation issues on ARM platforms.
* Use int instead of char in places where we implicitly wanted to use a signed char, since char may be unsigned on some platforms. * Don't hardcode assumed x86_64 architecture when looking for modules or include files. * thread.c: Add workaround for thread unregistration.
1 parent a749781 commit 5201d13

File tree

14 files changed

+51
-32
lines changed

14 files changed

+51
-32
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BBSTOPDIR:=$(subst $(space),\$(space),$(CURDIR))
1212

1313
export BBSTOPDIR # Top level dir, used in subdirs' Makefiles
1414

15-
GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g')
15+
GCCVERSION := $(shell gcc --version | grep ^gcc | sed 's/^.* //g')
1616
GCCVERSIONGTEQ8 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 8)
1717
ALPINE_LINUX := $(shell ls /etc/alpine-release 2>/dev/null | wc -l)
1818

bbs/editor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int bbs_line_editor(struct bbs_node *node, const char *restrict instr, char *res
4242
}
4343

4444
for (;;) {
45-
char c;
45+
int c;
4646
bbs_node_buffer(node);
4747
/* Read until we get 2 newlines */
4848
for (;;) {

bbs/menu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int menu_set_title(struct bbs_node *node, const char *name)
484484
static int bbs_menu_run(struct bbs_node *node, const char *menuname, const char *menuitemname, int stack, const char *optreq, char *restrict scratchbuf)
485485
{
486486
int res;
487-
char opt = 0;
487+
int opt = 0;
488488
struct bbs_menu *menu;
489489
struct bbs_menu_item *menuitem;
490490
char options[64]; /* No menu will ever have more than this many options... */
@@ -692,7 +692,7 @@ static int bbs_menu_run(struct bbs_node *node, const char *menuname, const char
692692
}
693693

694694
/* We don't need to call MENUITEM_NOT_APPLICABLE here to check if it applies, it wouldn't be in the options buffer if it wasn't */
695-
menuitem = find_menuitem(menu, opt);
695+
menuitem = find_menuitem(menu, (char) opt);
696696
/* It was in the menu and the menu hasn't changed, it better exist. */
697697
if (!menuitem) {
698698
bbs_warning("Could not find option '%c' in menu '%s'\n", opt, menu->name);

bbs/node.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,8 +1993,7 @@ static int init_term_properties_automatic(struct bbs_node *node)
19931993

19941994
static int ask_yn(struct bbs_node *node, const char *question)
19951995
{
1996-
int i;
1997-
char c;
1996+
int i, c;
19981997
/* Since we're not sure if this terminal supports ANSI,
19991998
* don't use any ANSI escape sequences, just keep it nice and simple. */
20001999
for (i = 0; i < 3; i++) {

bbs/socket.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,9 +1937,9 @@ int bbs_expect_line(int fd, int ms, struct readline_data *rldata, const char *st
19371937
return 0;
19381938
}
19391939

1940-
static char bbs_tread(int fd, int ms)
1940+
static int bbs_tread(int fd, int ms)
19411941
{
1942-
signed char res;
1942+
int res;
19431943

19441944
if (fd < 0) {
19451945
bbs_error("Invalid file descriptor: %d\n", fd);
@@ -1948,11 +1948,11 @@ static char bbs_tread(int fd, int ms)
19481948
}
19491949

19501950
bbs_assert(ms > 0); /* There would be no reason to use bbs_node_tpoll over bbs_node_poll unless ms > 0. */
1951-
res = (char) bbs_poll(fd, ms);
1951+
res = (int) bbs_poll(fd, ms);
19521952

19531953
if (res > 0) {
19541954
char buf[1];
1955-
res = (char) read(fd, buf, sizeof(buf));
1955+
res = (int) read(fd, buf, sizeof(buf));
19561956
if (res <= 0) {
19571957
return res;
19581958
}
@@ -1961,16 +1961,16 @@ static char bbs_tread(int fd, int ms)
19611961
return res;
19621962
}
19631963

1964-
char bbs_node_tread(struct bbs_node *node, int ms)
1964+
int bbs_node_tread(struct bbs_node *node, int ms)
19651965
{
1966-
signed char res;
1966+
int res;
19671967

19681968
bbs_assert(ms > 0); /* There would be no reason to use bbs_node_tpoll over bbs_node_poll unless ms > 0. */
1969-
res = (char) bbs_node_tpoll(node, ms);
1969+
res = bbs_node_tpoll(node, ms);
19701970

19711971
if (res > 0) {
19721972
char buf[1];
1973-
res = (signed char) bbs_node_read(node, buf, sizeof(buf));
1973+
res = (int) bbs_node_read(node, buf, sizeof(buf));
19741974
if (res <= 0) {
19751975
return res;
19761976
}
@@ -1989,7 +1989,7 @@ static int __bbs_node_read_escseq(struct bbs_node *node, int fd)
19891989
/* We can't just declare a variable pointing to the right function to use, since their arguments are of different types (node vs int). Use a macro instead. */
19901990
#define bbs_proper_tread(node, fd, ms) node ? bbs_node_tread(node, ms) : bbs_tread(fd, ms)
19911991

1992-
char c1, c2, c3;
1992+
int c1, c2, c3;
19931993
/* We already read ESC (27). Try to read further characters. */
19941994
c1 = bbs_proper_tread(node, fd, 10); /* 10ms ought to be more than enough. We should really get everything at once. */
19951995
if (c1 <= 0) {

bbs/thread.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ static int __thread_unregister(pthread_t id, const char *file, int line, const c
112112
int remove = 0;
113113
int lwp = -1;
114114

115+
#if defined(__linux__) && defined(__GLIBC__)
116+
/* For some reason, when detached threads exit on ARM (as opposed to x86),
117+
* the thread id is 1, rather than an actual thread.
118+
* However, since it's being run in the context of the exiting thread,
119+
* we can use pthread_self() to get the actual thread and then everything else works as expected. */
120+
if (id == 1) {
121+
id = pthread_self();
122+
}
123+
#endif
124+
115125
RWLIST_WRLOCK(&thread_list);
116126
RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
117127
#ifdef __FreeBSD__
@@ -205,7 +215,11 @@ void bbs_thread_cleanup(void)
205215
* especially if it's a thread that has been in the waitjoin state for some time (more than a couple seconds).
206216
* Be nice and free the memory anyways. */
207217
print_time_elapsed(x->waitingjoin ? x->end : x->start, now, elapsed, sizeof(elapsed));
218+
#ifdef __linux__
219+
bbs_warning("Thread still registered at shutdown: %d [%lu] (%s %s) %s\n", x->lwp, (unsigned long) x->id, thread_state_name(x), elapsed, x->name);
220+
#else
208221
bbs_warning("Thread still registered at shutdown: %d (%s %s) %s\n", x->lwp, thread_state_name(x), elapsed, x->name);
222+
#endif
209223
free_if(x->name);
210224
free(x);
211225
}

doors/door_usermgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static int pwchange_exec(struct bbs_node *node, const char *args)
248248

249249
static int termmgmt_exec(struct bbs_node *node, const char *args)
250250
{
251-
char c;
251+
int c;
252252

253253
UNUSED(args);
254254

external/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ RM = rm -f
1212
INSTALL = install
1313
NCURSES_FLAGS=$(shell pkg-config --cflags ncurses)
1414

15+
ARCH = $(shell uname -m)
16+
CFLAGS += -DBBS_LINUX_ARCH=$(ARCH)
17+
1518
all: $(EXES)
1619

1720
$(EXES_NOFLEMGR): %: %.o

external/modman.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ static int load_header_file_locations(void)
335335
len -= bytes;
336336
}
337337
pclose(pfp);
338-
#define SYS_INCLUDE_DIR "/usr/include/x86_64-linux-gnu"
338+
#define STR(s) #s
339+
#define XSTR(s) STR(s)
340+
#define SYS_INCLUDE_DIR "/usr/include/" XSTR(BBS_LINUX_ARCH) "-linux-gnu"
339341
if (!strstr(buf, SYS_INCLUDE_DIR) && !access(SYS_INCLUDE_DIR, R_OK)) {
340342
/* This directory is not explicitly returned by the gcc output, but all the <sys/...> header files live here: */
341343
modman_log(7, " System include path: %s\n", SYS_INCLUDE_DIR);
@@ -824,7 +826,7 @@ static void show_help(void)
824826

825827
int main(int argc, char *argv[])
826828
{
827-
char c;
829+
int c;
828830
static const char *getopt_settings = "?dhtv";
829831

830832
while ((c = getopt(argc, argv, getopt_settings)) != -1) {

include/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ int bbs_expect_line(int fd, int ms, struct readline_data *rldata, const char *st
523523
* \note This is useful for reading a single character (in non-canonical mode) with no delay
524524
* \retval 0 if fd closed, -1 on failure, non-negative character read otherwise
525525
*/
526-
char bbs_node_tread(struct bbs_node *node, int ms);
526+
int bbs_node_tread(struct bbs_node *node, int ms);
527527

528528
/*! * \brief Same as bbs_node_read_escseq, but directly on a file descriptor, rather than a node */
529529
int bbs_read_escseq(int fd);

0 commit comments

Comments
 (0)