Skip to content

Commit 6580b64

Browse files
committed
install: Fix compilation issues with FreeBSD.
Make Asterisk compile successfully with FreeBSD. Since there is still an issue with the GitHub CI not detecting the uuid package, the FreeBSD build remains disabled in the CI, but should work if installing on a regular FreeBSD system. Issues remain with actually running it; the enclosed changes fix compilation issues only.
1 parent 309fc67 commit 6580b64

File tree

6 files changed

+51
-21
lines changed

6 files changed

+51
-21
lines changed

apps/app_callback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static void cancel_thread(struct callback_monitor_item *cb, int join)
441441
{
442442
pthread_t thread = cb->thread;
443443

444-
ast_debug(3, "Instructing thread %lu to exit\n", thread);
444+
ast_debug(3, "Instructing callback thread %lu to exit\n", (long) thread);
445445

446446
ast_mutex_lock(&cb->lock);
447447
cb->cancel = 1;
@@ -453,7 +453,7 @@ static void cancel_thread(struct callback_monitor_item *cb, int join)
453453
/*! \todo join can cause a segfault on module unload/refresh, but why??? */
454454
pthread_join(thread, NULL); /* Thread will now free cb and clean up. */
455455
}
456-
ast_debug(3, "Thread %lu has exited\n", thread);
456+
ast_debug(3, "Thread %ld has exited\n", (long) thread);
457457
}
458458

459459
static int cancel_exec(struct ast_channel *chan, const char *data)

apps/app_ccsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ static void *call_back_queue(void *data)
14131413
/* Something happened: perhaps it's our turn to do a callback? Or maybe we were aborted. */
14141414
}
14151415
if (call->aborted) { /* CBQ was cancelled. */
1416-
ast_debug(1, "CBQ thread %lu is ending early\n", call->cbqthread);
1416+
ast_debug(1, "CBQ thread %ld is ending early\n", (long) call->cbqthread);
14171417
break;
14181418
} else if (res) {
14191419
char cbq_dest[AST_MAX_CONTEXT]; /* Technically not enough for exten@context, but in practice, should be... */
@@ -1534,7 +1534,7 @@ static void *call_back_queue(void *data)
15341534

15351535
if (!call->aborted) {
15361536
/* Hey, we weren't aborted, which means nobody is going to clean up our mess for us. */
1537-
ast_debug(2, "Thread %lu is ending of its own volition\n", call->cbqthread);
1537+
ast_debug(2, "Thread %ld is ending of its own volition\n", (long) call->cbqthread);
15381538
pthread_detach(call->cbqthread);
15391539
call_free(call, 1);
15401540
}

apps/app_mail.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "asterisk.h"
3333

3434
#include <sys/stat.h>
35+
#include <libgen.h> /* for FreeBSD */
3536

3637
#include "asterisk/logger.h"
3738
#include "asterisk/channel.h"
@@ -125,7 +126,7 @@ static void make_email_file(FILE *p, const char *subject, char *body, const char
125126
struct ast_tm tm;
126127
char date[256];
127128
char host[MAXHOSTNAMELEN] = "";
128-
char who[256];
129+
char who[257];
129130
char bound[256];
130131
struct ast_str *str2 = ast_str_create(16);
131132
char filename[256];

phreaknet.sh

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ fi
303303
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
304304
PAC_MAN="pkg"
305305
AST_SOURCE_PARENT_DIR="/usr/local/src"
306+
AST_CONFIG_DIR="/usr/local/etc/asterisk"
306307
AST_MAKE="gmake"
307308
XMLSTARLET="/usr/local/bin/xml"
308309
elif [ "$OS_DIST_INFO" = "Sangoma Linux" ]; then # the FreePBX distro...
@@ -892,8 +893,8 @@ make_keys_readable() {
892893
# tlscertfile used by http.conf and sip.conf
893894
# Simpler methods of looping on each line of output only work in bash and not POSIX sh
894895
echo -n "" > /tmp/astkeylist.txt
895-
grep -h -R "tlscertfile" /etc/asterisk | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
896-
grep -h -R "priv_key_file" /etc/asterisk | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
896+
grep -h -R "tlscertfile" $AST_CONFIG_DIR | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
897+
grep -h -R "priv_key_file" $AST_CONFIG_DIR | grep -v '<' | cut -d'=' -f 2 | sed 's/^[ \t]*//' | sed '/^;/d' | grep -e ".pem" -e ".key" | cut -d' ' -f 1 >> /tmp/astkeylist.txt
897898

898899
while read filename
899900
do
@@ -952,7 +953,7 @@ install_prereq() {
952953
elif [ "$PAC_MAN" = "pkg" ]; then
953954
PREREQ_PACKAGES="$PREREQ_PACKAGES git gmake"
954955
if [ "$1" = "1" ]; then
955-
PREREQ_PACKAGES="$PREREQ_PACKAGES curl subversion e2fsprogs-libuuid sqlite3 xmlstarlet"
956+
PREREQ_PACKAGES="$PREREQ_PACKAGES curl subversion e2fsprogs-libuuid sqlite3 xmlstarlet libsysinfo"
956957
if [ "$ENHANCED_INSTALL" = "1" ]; then
957958
PREREQ_PACKAGES="$PREREQ_PACKAGES ntp tcpdump mpg123 bind-tools" # bind-tools for dig
958959
fi
@@ -1070,7 +1071,7 @@ install_freepbx_checks() {
10701071
fi
10711072
if [ -f $AST_CONFIG_DIR/extensions.conf ]; then
10721073
if [ "$FORCE_INSTALL" != "1" ]; then
1073-
echoerr "An existing /etc/asterisk/extensions.conf has been detected on the file system. Installing FreePBX will overwrite ALL OF YOUR CONFIGURATION!!!"
1074+
echoerr "An existing $AST_CONFIG_DIR/extensions.conf has been detected on the file system. Installing FreePBX will overwrite ALL OF YOUR CONFIGURATION!!!"
10741075
printf "%s\n" "If this is intended, rerun the command with the -f or --force flag. Be sure to backup your configuration first if desired."
10751076
exit 2
10761077
fi
@@ -1124,9 +1125,9 @@ uninstall_freepbx() {
11241125
# rm -rf /var/lib/asterisk/bin/* # there could be other stuff in here
11251126
rm -rf /var/www/html/admin/*
11261127
rm /etc/amportal.conf
1127-
rm /etc/asterisk/amportal.conf
1128+
rm $AST_CONFIG_DIR/amportal.conf
11281129
rm /etc/freepbx.conf
1129-
rm /etc/asterisk/freepbx.conf
1130+
rm $AST_CONFIG_DIR/freepbx.conf
11301131
}
11311132

11321133
run_testsuite_test() {
@@ -1461,9 +1462,15 @@ github_pr() {
14611462
# $2 = 1 to force
14621463
asterisk_pr() {
14631464
wget -q "https://patch-diff.githubusercontent.com/raw/asterisk/asterisk/pull/$1.diff" -O /tmp/$1.pr.diff --no-cache
1465+
if [ $? -ne 0 ]; then
1466+
echoerr "Failed to download https://patch-diff.githubusercontent.com/raw/asterisk/asterisk/pull/$1.diff"
1467+
fi
14641468
if [ "$2" = "1" ]; then
14651469
git apply -v "/tmp/$1.pr.diff"
1466-
patch -p1 -F 3 -f --verbose < "/tmp/$1.pr.diff"
1470+
if [ $? -ne 0 ]; then
1471+
echoerr "Failed to apply patch using git apply, retrying directly using patch..."
1472+
patch -p1 -F 3 -f --verbose < "/tmp/$1.pr.diff"
1473+
fi
14671474
else
14681475
git apply "/tmp/$1.pr.diff"
14691476
fi
@@ -1822,8 +1829,8 @@ install_dahdi() {
18221829
else
18231830
echoerr "No assigned spans"
18241831
fi
1825-
if [ -f /etc/asterisk/dahdi-channels.conf ]; then
1826-
cat /etc/asterisk/dahdi-channels.conf
1832+
if [ -f $AST_CONFIG_DIR/dahdi-channels.conf ]; then
1833+
cat $AST_CONFIG_DIR/dahdi-channels.conf
18271834
else
18281835
echoerr "No DAHDI channels"
18291836
fi
@@ -2027,6 +2034,9 @@ asterisk_pr_if() {
20272034
asterisk_pr_if_single $2 $1
20282035
asterisk_pr_if_single $3 $1
20292036
asterisk_pr_if_single $4 $1
2037+
if [ "$5" != "" ]; then # At some times of the year, there will be 4 branches actively supported
2038+
asterisk_pr_if_single $5 $1
2039+
fi
20302040
}
20312041

20322042
asterisk_pr_unconditional() {
@@ -2123,7 +2133,11 @@ phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
21232133
#cd ..
21242134
fi
21252135
custom_module "apps/app_fsk.c" "https://raw.githubusercontent.com/alessandrocarminati/app-fsk/master/app_fsk_18.c"
2126-
sed -i 's/<defaultenabled>no<\/defaultenabled>//g' apps/app_fsk.c # temporary bug fix
2136+
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
2137+
sed -i '' '/defaultenabled/d' apps/app_fsk.c
2138+
else
2139+
sed -i 's/<defaultenabled>no<\/defaultenabled>//g' apps/app_fsk.c # temporary bug fix
2140+
fi
21272141

21282142
## Add patches to existing modules
21292143
phreak_tree_patch "apps/app_stack.c" "returnif.patch" # Add ReturnIf application
@@ -2146,13 +2160,15 @@ phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
21462160
phreak_tree_patch "res/res_srtp.c" "srtp.diff" # Temper SRTCP unprotect warnings. Only beneficial for older ATAs that require older TLS protocols.
21472161
fi
21482162

2149-
## todo: there should be logic to download an rc if it exists, but switch to current if it no longer does.
2150-
2151-
printf "Determining patches applicable to %s -> %d (~%s)\n" "$AST_ALT_VER" "$AST_MM_VER" "$AST_MAJOR_VER"
2163+
printf "Applying patches applicable to %s -> %d (~%s)\n" "$AST_ALT_VER" "$AST_MM_VER" "$AST_MAJOR_VER"
21522164

21532165
## merged into master, not yet in a release version (use asterisk_pr_if, e.g. asterisk_pr_if 399 210100 200600 182100)
2166+
#git_custom_patch "https://github.com/InterLinked1/asterisk/commit/d389a0b14569ab60daac73391e66d57fbbabdadb.diff" # astfd compiler fix
2167+
asterisk_pr_if 901 220100 210600 182600 # astfd compiler fix
2168+
asterisk_pr_if 903 220100 210600 182600 # voicemail pager email fix
21542169

21552170
## Unmerged patches: remove once merged
2171+
asterisk_pr_unconditional 917 # FreeBSD compilation fixes
21562172
git_patch "config_c_fix_template_inheritance_overrides.patch" # config.c: fix template inheritance/overrides
21572173
git_patch "config_c_fix_template_writing.patch" # config.c: fix template inheritance/overrides
21582174

@@ -2712,8 +2728,6 @@ get_source() {
27122728
svn --non-interactive --trust-server-cert export https://svn.digium.com/svn/thirdparty/mp3/trunk addons/mp3
27132729
./contrib/scripts/get_mp3_source.sh
27142730

2715-
git_custom_patch "https://github.com/InterLinked1/asterisk/commit/d389a0b14569ab60daac73391e66d57fbbabdadb.diff" # astfd compiler fix
2716-
27172731
if [ "$EXTRA_FEATURES" = "1" ]; then
27182732
# Add PhreakNet patches
27192733
printf "%s\n" "Beginning custom patches..."
@@ -3191,7 +3205,17 @@ elif [ "$cmd" = "install" ]; then
31913205
niceval="-15" # -15 to speed up compilation by increasing CPU priority.
31923206
fi
31933207
if [ "$OS_DIST_INFO" = "FreeBSD" ]; then
3194-
nice $AST_MAKE ASTLDFLAGS=-lcrypt main
3208+
# For some reason, %%LIBSYSINFO%% is in the linking flags on FreeBSD, remove that from being added. libsysinfo is needed though.
3209+
# Same with HAVE_CRYPT_R, that's not available but gets detected, so undetect it
3210+
# Note that these sed expressions are designed for BSD sed, and do not work with GNU sed
3211+
sed -i '' '/LIBSYSINFO/d' main/Makefile
3212+
sed -i '' '/HAVE_CRYPT_R/d' include/asterisk/autoconfig.h
3213+
sed -i "" -e 's|WRAP_LIBC_MALLOC|ASTMM_LIBC ASTMM_REDIRECT|g' addons/mp3/interface.c # for format_mp3
3214+
sed -i "" -e 's|\\s|s|g' build_tools/make_xml_documentation # fix sed command in this script to remove the backslash for BSD sed
3215+
nice $AST_MAKE "ASTLDFLAGS=-lcrypt -lsysinfo" main
3216+
if [ $? -eq 0 ]; then
3217+
nice $AST_MAKE -j$(nproc) # compile Asterisk. This is the longest step, if you are installing for the first time. Also, don't let it take over the server.
3218+
fi
31953219
else
31963220
nice $AST_MAKE -j$(nproc) main # compile 'main' subdirectory first
31973221
if [ $? -eq 0 ]; then
@@ -3200,6 +3224,7 @@ elif [ "$cmd" = "install" ]; then
32003224
fi
32013225

32023226
if [ $? -ne 0 ]; then
3227+
$AST_MAKE NOISY_BUILD=1 # show actual compilation command that failed
32033228
if [ ! -f channels/chan_dahdi.o ]; then
32043229
echoerr "Compilation of chan_dahdi failed?"
32053230
ls -la /usr/include/dahdi

res/res_alarmsystem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
#include "asterisk.h"
3939

40+
#include <signal.h> /* use pthread_kill */
41+
4042
#include "asterisk/file.h"
4143
#include "asterisk/pbx.h"
4244
#include "asterisk/channel.h"

res/res_irc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include "asterisk.h"
3737

38+
#include <signal.h> /* use pthread_kill */
39+
3840
#include "asterisk/lock.h"
3941
#include "asterisk/channel.h"
4042
#include "asterisk/pbx.h"

0 commit comments

Comments
 (0)