Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c10010
Add support for Darwin / macOS
rsmarples Apr 6, 2026
e920e7f
Add reallocarray
rsmarples Apr 6, 2026
441de7a
Csat away a compile warning.
rsmarples Apr 6, 2026
eb8dc1e
Solve initgroups compile warning on all OS.
rsmarples Apr 6, 2026
837d25f
Fixup xsetfd
rsmarples Apr 6, 2026
c9c891b
Remove debug
rsmarples Apr 6, 2026
bf8283a
lua: correct message type
rsmarples Apr 6, 2026
f6cd3bc
remove old svc_run
rsmarples Apr 6, 2026
d04a15a
Remove dup define
rsmarples Apr 6, 2026
dd14a87
lua: improve hostname lookup
rsmarples Apr 6, 2026
3bdae24
lua: fix payload len guard
rsmarples Apr 6, 2026
d2034e5
lua: more fixes
rsmarples Apr 6, 2026
44b1998
use blocking sockets
rsmarples Apr 6, 2026
e1c159c
Fix returning service data
rsmarples Apr 7, 2026
19d1d3e
Abort eloop if service watcher fails.
rsmarples Apr 7, 2026
5da02fe
Add macos to github actions
rsmarples Apr 7, 2026
7e6dad8
Fix macos arm64
rsmarples Apr 7, 2026
c450118
Just build on latest OS
rsmarples Apr 7, 2026
8a67a9a
Fix diagnostic message
rsmarples Apr 7, 2026
65a2602
Use latest checkout
rsmarples Apr 7, 2026
bdf0823
Brew and pkgconf are already installed.
rsmarples Apr 7, 2026
6a590c6
Latest checkout
rsmarples Apr 7, 2026
ea815b0
Don't exit on hangup as we already have
rsmarples Apr 7, 2026
f7ee065
eloop: rationalise not setting cloexec on macos
rsmarples Apr 7, 2026
f18a138
lua: ensure we have space to copyout hostname.
rsmarples Apr 7, 2026
b346ca9
Fix xsetfd, close eloop fd with epoll and correct a diagnositic message.
rsmarples Apr 7, 2026
d10a94f
Fix on bsd
rsmarples Apr 7, 2026
0853b1f
Fix again, lol
rsmarples Apr 7, 2026
2824fd2
reallocarray: fix errno and avoid div by zero.
rsmarples Apr 7, 2026
be6a688
Build on macos-15 and macos-26
rsmarples Apr 7, 2026
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
28 changes: 26 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
ubuntu:
strategy:
matrix:
os: [ ubuntu-latest, ubuntu-22.04 ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Install Lua
run: |
Expand All @@ -30,7 +30,29 @@ jobs:
- name: Build
run: make

macos:
strategy:
matrix:
os: [ macos-15, macos-26 ]
runs-on: ${{ matrix.os }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

steps:
- uses: actions/checkout@v6

- name: Install Lua
run: |
brew install lua

- name: Configure
run: ./configure

- name: Build
run: make
Comment on lines +42 to +50
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Lua plugin may silently fail to build — pkg-config configuration needed.

The ./configure script detects Lua via pkg-config (see configure:695-720). On macOS, Homebrew-installed Lua's .pc files may not be indexed by pkg-config without additional setup. If detection fails, the build will succeed but skip the Lua plugin entirely, defeating the test purpose.

Consider adding the Homebrew pkg-config path:

Proposed fix
     - name: Install Lua
       run: |
         brew install lua
+
+    - name: Configure
+      run: |
+        export PKG_CONFIG_PATH="$(brew --prefix lua)/lib/pkgconfig:$PKG_CONFIG_PATH"
+        ./configure
 
-    - name: Configure
-      run: ./configure
-
     - name: Build
       run: make

Alternatively, you could add a post-configure check that verifies LUA_PLUGIN was detected:

grep -q 'LUA_PLUGIN' config.mk || { echo "Lua plugin not detected"; exit 1; }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 42 - 50, The workflow's Lua build
can silently skip the plugin because Homebrew's pkg-config path isn't exported
before running ./configure; update the CI steps around "Install Lua" and
"Configure" to export the Homebrew pkg-config directory into PKG_CONFIG_PATH
(the Homebrew lib/pkgconfig location) so pkg-config can find Lua .pc files
before invoking ./configure, and add a post-configure verification that checks
config.mk for LUA_PLUGIN (e.g., fail the job if LUA_PLUGIN is not present) to
ensure the Lua plugin was detected; target the existing steps invoking brew
install lua, ./configure and make and the config.mk/LUA_PLUGIN symbols when
making these changes.

Comment on lines +33 to +50
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Lua plugin may silently fail to build on macOS — pkg-config path still not configured.

The ./configure script detects Lua via pkg-config (see configure:695-720). On macOS, Homebrew-installed packages are not in pkg-config's default search path. Without setting PKG_CONFIG_PATH, the Lua detection will fail silently and the plugin will be skipped, defeating the test purpose.

Proposed fix to export Homebrew's pkg-config path
     - name: Install Lua
       run: |
         brew install lua

     - name: Configure
-      run: ./configure
+      run: |
+        export PKG_CONFIG_PATH="$(brew --prefix lua)/lib/pkgconfig:$PKG_CONFIG_PATH"
+        ./configure

     - name: Build
       run: make

Optionally, add a post-configure verification step:

    - name: Verify Lua plugin detected
      run: grep -q 'LUA_PLUGIN' config.mk || { echo "Lua plugin not detected"; exit 1; }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build.yml around lines 33 - 50, The macOS build step must
export Homebrew's pkg-config path before running ./configure so pkg-config can
find Lua; update the workflow so the "Configure" step (or immediately before it,
e.g., after "Install Lua") sets PKG_CONFIG_PATH to include `$(brew
--prefix)/opt/lua/lib/pkgconfig` (and/or `$(brew --prefix)/lib/pkgconfig`) so
configure detects the Lua plugin, then run ./configure; also add a
post-configure step named "Verify Lua plugin detected" that greps for
'LUA_PLUGIN' in config.mk and fails the job if not found to ensure the plugin
was detected.


# The BSDs are currently broken on github

openbsd:
if: false
runs-on: ubuntu-latest
steps:
- name: Bootstrap OpenBSD-latest
Expand All @@ -50,6 +72,7 @@ jobs:
make

freebsd:
if: false
runs-on: ubuntu-latest
steps:
- name: Bootstrap FreeBSD-latest
Expand All @@ -69,6 +92,7 @@ jobs:
make

netbsd:
if: false
runs-on: ubuntu-latest
steps:
- name: Bootstrap NetBSD-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ config.mk
config.h
config.log

*.dSYM/**
*.o
*.So
*.soo
*.so

*.tar.xz
Expand Down
62 changes: 62 additions & 0 deletions compat/reallocarray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */

/*-
* Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

/*
* To be clear, this is NetBSD's more refined reallocarr(3) function
* made to look like OpenBSD's more useable reallocarray(3) interface.
*/
#include "reallocarray.h"

#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2))
void *
reallocarray(void *ptr, size_t n, size_t size)
{
if (n == 0 || size == 0)
return realloc(ptr, 0);

/*
* Try to avoid division here.
*
* It isn't possible to overflow during multiplication if neither
* operand uses any of the most significant half of the bits.
*/
if ((n | size) >= SQRT_SIZE_MAX && n > SIZE_MAX / size) {
errno = ENOMEM;
return NULL;
}
return realloc(ptr, n * size);
}
39 changes: 39 additions & 0 deletions compat/reallocarray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */

/*-
* Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#ifndef REALLOCARRAY_H
#define REALLOCARRAY_H

#include <stddef.h>

void *reallocarray(void *, size_t, size_t);

#endif
2 changes: 0 additions & 2 deletions config-null.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# This space left intentionally blank

DHCPCD_SRCS+= dhcpcd-embedded.c
54 changes: 39 additions & 15 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,16 @@ EOF
else
echo "no"
fi
rm -rf _test.c _test
rm -rf _test.* _test
fi
else
echo "CPPFLAGS+= -DNDEBUG" >>$CONFIG_MK
fi

case "$OS" in
darwin*)
echo "LDFLAGS_SO+= -Wl,-undefined,dynamic_lookup" >>$CONFIG_MK
;;
freebsd*|kfreebsd*)
# FreeBSD hide some newer POSIX APIs behind _GNU_SOURCE ...
echo "CPPFLAGS+= -D_GNU_SOURCE" >>$CONFIG_MK
Expand Down Expand Up @@ -381,7 +384,7 @@ _CC=false
if $XCC _test.c -o _test >/dev/null 2>&3; then
[ -x _test ] && _CC=true
fi
rm -f _test.c _test
rm -rf _test.* _test
if ! $_CC; then
echo $XCC
echo "$CC does not create executables" >&2
Expand All @@ -394,8 +397,7 @@ $CC --version | $SED -e '1!d'
if [ -z "$DHCPSD_USER" ]; then
printf "Detecting a suitable user for dhcpsd ... "
for x in _dhcpsd dhcpsd _dhcpd dhcpd; do
home=$(getent passwd $x 2>/dev/null | cut -d: -f6)
if [ -d "$home" ]; then
if id "$x" >/dev/null 2>&1; then
DHCPSD_USER="$x"
echo "$DHCPSD_USER"
break
Expand Down Expand Up @@ -430,7 +432,7 @@ if $XCC _capsicum.c -o _capsicum -lcasper -lcap_net 2>&3; then
else
echo "no"
fi
rm -f _capsicum.c _capsicum
rm -rf _capsicum.* _capsicum
fi

if [ -z "$SANDBOX" ]; then
Expand All @@ -448,7 +450,7 @@ EOF
else
echo "no"
fi
rm -f _pledge.c _pledge
rm -rf _pledge.* _pledge
fi

abort=false
Expand All @@ -474,7 +476,7 @@ else
echo "libc support for getifaddrs is required - aborting" >&2
abort=true
fi
rm -f _getifaddrs.c _getifaddrs
rm -rf _getifaddrs.* _getifaddrs
$abort && exit 1

printf "Testing for clock_gettime ... "
Expand All @@ -495,7 +497,7 @@ else
echo "libc support for clock_getttime is required - aborting" >&2
abort=true
fi
rm -f _clock_gettime.c _clock_gettime
rm -rf _clock_gettime.* _clock_gettime
$abort && exit 1

if [ -z "$ARC4RANDOM" ]; then
Expand All @@ -512,7 +514,7 @@ EOF
ARC4RANDOM=no
fi
echo "$ARC4RANDOM"
rm -f _arc4random.c _arc4random
rm -rf _arc4random.* _arc4random
fi
if [ "$ARC4RANDOM" = no ]; then
echo "COMPAT_SRCS+= compat/arc4random.c" >>$CONFIG_MK
Expand All @@ -536,7 +538,7 @@ EOF
fi
echo "$CLOSEFROM"
fi
rm -f _closefrom.c _closefrom
rm -rf _closefrom.* _closefrom
if [ "$CLOSEFROM" = no ]; then
echo "COMPAT_SRCS+= compat/closefrom.c" >>$CONFIG_MK
echo "#include \"compat/closefrom.h\"" >>$CONFIG_H
Expand All @@ -561,7 +563,7 @@ echo "$IOCTL_REQ"
if [ "$IOCTL_REQ" != "unsigned long" ]; then
echo "#define IOCTL_REQUEST_TYPE $IOCTL_REQ" >>$CONFIG_H
fi
rm -f _ioctl.c _ioctl
rm -rf _ioctl.* _ioctl

printf "Testing for inet_ntoa ... "
cat <<EOF >_inet_ntoa.c
Expand All @@ -586,9 +588,31 @@ else
echo "libc support for inet_ntoa is required - aborting" >&2
abort=true
fi
rm -f _inet_ntoa.c _inet_ntoa
rm -rf _inet_ntoa.* _inet_ntoa
$abort && exit 1

if [ -z "$SETPROCTITLE" ]; then
printf "Testing for setproctitle ... "
cat << EOF >_setproctitle.c
#include <stdlib.h>
#include <unistd.h>
int main(void) {
setproctitle("foo");
return 0;
}
EOF
if $XCC _setproctitle.c -o _setproctitle 2>&3; then
SETPROCTITLE=yes
else
SETPROCTITLE=no
fi
echo "$SETPROCTITLE"
rm -rf _setproctitle.* _setproctitle
fi
if [ "$SETPROCTITLE" != no ]; then
echo "#define HAVE_SETPROCTITLE" >>$CONFIG_H
fi

if [ -z "$STRLCPY" ]; then
printf "Testing for strlcpy ... "
cat <<EOF >_strlcpy.c
Expand All @@ -605,7 +629,7 @@ EOF
STRLCPY=no
fi
echo "$STRLCPY"
rm -f _strlcpy.c _strlcpy
rm -rf _strlcpy.* _strlcpy
fi
if [ "$STRLCPY" = no ]; then
echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK
Expand All @@ -629,7 +653,7 @@ EOF
RBTREE=no
fi
echo "$RBTREE"
rm -f _rbtree.c _rbtree
rm -rf _rbtree.* _rbtree
fi
if [ "$RBTREE" = no ]; then
echo "VENDOR_SRCS+= vendor/rbtree.c" >>$CONFIG_MK
Expand Down Expand Up @@ -659,7 +683,7 @@ EOF
REALLOCARRAY=no
fi
echo "$REALLOCARRAY"
rm -f _reallocarray.c _reallocarray
rm -rf _reallocarray.* _reallocarray
fi
if [ "$REALLOCARRAY" = no ]; then
echo "COMPAT_SRCS+= compat/reallocarray.c" >>$CONFIG_MK
Expand Down
Loading