Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
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
60 changes: 60 additions & 0 deletions compat/reallocarray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* $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)
{

/*
* 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 = EOVERFLOW;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
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
78 changes: 65 additions & 13 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,44 @@ sa_pton(struct sockaddr *sa, const char *src)
return inet_pton(sa->sa_family, src, addr);
}

#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
static int
xsetfd(int fd, int flags)
{
int oflags;

#ifndef HAVE_SOCK_CLOEXEC
if (flags & SOCK_CLOEXEC) {
oflags = fcntl(fd, F_GETFD);
if (oflags == -1)
return -1;
if (!(oflags & FD_CLOEXEC) &&
fcntl(fd, F_SETFD, oflags | O_NONBLOCK) == -1)
return -1;
}
#endif

#ifndef HAVE_SOCK_NONBLOCK
if (flags & SOCK_NONBLOCK) {
oflags = fcntl(fd, F_GETFL);
if (oflags == -1)
return -1;
if (!(oflags & O_NONBLOCK) &&
fcntl(fd, F_SETFL, oflags | O_NONBLOCK) == -1)
return -1;
}
#endif

return 0;
}
#endif
Comment thread
rsmarples marked this conversation as resolved.

int
xsocket(int domain, int type, int protocol)
{
int s;
#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
int xflags, xtype = type;
int xtype = type;
#endif

#ifndef HAVE_SOCK_CLOEXEC
Expand All @@ -481,24 +513,44 @@ xsocket(int domain, int type, int protocol)
if ((s = socket(domain, type, protocol)) == -1)
return -1;

#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
if (xtype != type && xsetfd(s, xtype) == -1) {
close(s);
return -1;
}
#endif

return s;
}

int
xsocketpair(int domain, int type, int protocol, int fdset[2])
{
int s;
#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
int xtype = type;
#endif

#ifndef HAVE_SOCK_CLOEXEC
if ((xtype & SOCK_CLOEXEC) &&
((xflags = fcntl(s, F_GETFD)) == -1 ||
fcntl(s, F_SETFD, xflags | FD_CLOEXEC) == -1))
goto out;
if (xtype & SOCK_CLOEXEC)
type &= ~SOCK_CLOEXEC;
#endif
#ifndef HAVE_SOCK_NONBLOCK
if ((xtype & SOCK_NONBLOCK) &&
((xflags = fcntl(s, F_GETFL)) == -1 ||
fcntl(s, F_SETFL, xflags | O_NONBLOCK) == -1))
goto out;
if (xtype & SOCK_NONBLOCK)
type &= ~SOCK_NONBLOCK;
#endif

return s;
if ((s = socketpair(domain, type, protocol, fdset)) == -1)
return -1;

#if !defined(HAVE_SOCK_CLOEXEC) || !defined(HAVE_SOCK_NONBLOCK)
out:
close(s);
return -1;
if (xtype != type &&
(xsetfd(fdset[0], xtype) == -1 || xsetfd(fdset[1], xtype) == -1)) {
close(fdset[0]);
close(fdset[1]);
return -1;
}
#endif

return s;
}
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ hash_fnv1a(const void *key, size_t len)
#define SOCK_CXNB SOCK_CLOEXEC | SOCK_NONBLOCK
#endif
int xsocket(int, int, int);
int xsocketpair(int, int, int, int[2]);
#endif
Loading
Loading