BSD and glibc have the signature for request as unsigned long.
musl and Solaris have a signed int.
As such, we need to detect this at compile time and adjust the
signature of our internal ioctl functions to match.
To keep the onwire format the same, memcpy the request to the
unsigned long request and back again, thus preserving the signedness.
fi
done
fi
- : ${PRIVSEP_USER:= _dhcpcd}
+ : ${PRIVSEP_USER:=_dhcpcd}
echo "CPPFLAGS+= -DPRIVSEP" >>$CONFIG_MK
echo "#ifndef PRIVSEP_USER" >>$CONFIG_H
rm -f _clock_gettime.c _clock_gettime
$abort && exit 1
+printf "Testing ioctl request type ... "
+cat <<EOF >_ioctl.c
+#include <sys/ioctl.h>
+int main(void) {
+ unsigned long req = 0;
+ return ioctl(3, req, &req);
+}
+EOF
+if $XCC _ioctl.c -o _ioctl 2>&3; then
+ IOCTL_REQ="unsigned long"
+else
+ IOCTL_REQ="int"
+fi
+echo "$IOCTL_REQ"
+# Our default is unsigned long
+# We can still define it, but it makes the code path slightly bigger
+if [ "$IOCTL_REQ" != "unsigned long" ]; then
+ echo "#define IOCTL_REQUEST_TYPE $IOCTL_REQ" >>$CONFIG_H
+fi
+rm -f _ioctl.c _ioctl
+
printf "Testing for inet_ntoa ... "
cat <<EOF >_inet_ntoa.c
#include <netinet/in.h>
}
int
-if_ioctl(struct dhcpcd_ctx *ctx, unsigned long req, void *data, size_t len)
+if_ioctl(struct dhcpcd_ctx *ctx, ioctl_request_t req, void *data, size_t len)
{
#ifdef PRIVSEP
#endif
#include "config.h"
+
+/* POSIX defines ioctl request as an int, which Solaris and musl use.
+ * Everyone else use an unsigned long, which happens to be the bigger one
+ * so we use that in our on wire API. */
+#ifdef IOCTL_REQUEST_TYPE
+typedef IOCTL_REQUEST_TYPE ioctl_request_t;
+#else
+typedef unsigned long ioctl_request_t;
+#endif
+
#include "dhcpcd.h"
#include "ipv4.h"
#include "ipv6.h"
int if_getsubnet(struct dhcpcd_ctx *, const char *, int, void *, size_t);
#endif
-int if_ioctl(struct dhcpcd_ctx *, unsigned long, void *, size_t);
+int if_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
int if_getflags(struct interface *ifp);
int if_setflag(struct interface *ifp, short flag);
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING))
#include <assert.h>
#include <pwd.h>
#include <errno.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
+#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "privsep.h"
#include "script.h"
+__CTASSERT(sizeof(ioctl_request_t) <= sizeof(unsigned long));
+
struct psr_error
{
ssize_t psr_result;
s = socket(PF_INET, SOCK_DGRAM, 0);
if (s != -1)
+#ifdef IOCTL_REQUEST_TYPE
+ {
+ ioctl_request_t reqt;
+
+ memcpy(&reqt, &req, sizeof(reqt));
+ err = ioctl(s, reqt, data, len);
+ }
+#else
err = ioctl(s, req, data, len);
+#endif
else
err = -1;
if (s != -1)
}
ssize_t
-ps_root_ioctl(struct dhcpcd_ctx *ctx, unsigned long req, void *data, size_t len)
+ps_root_ioctl(struct dhcpcd_ctx *ctx, ioctl_request_t req, void *data,
+ size_t len)
{
+#ifdef IOCTL_REQUEST_TYPE
+ unsigned long ulreq = 0;
+
+ memcpy(&ulreq, &req, sizeof(req));
+ if (ps_sendcmd(ctx, ctx->ps_root_fd, PS_IOCTL, ulreq, data, len) == -1)
+ return -1;
+#else
if (ps_sendcmd(ctx, ctx->ps_root_fd, PS_IOCTL, req, data, len) == -1)
return -1;
+#endif
return ps_root_readerror(ctx);
}
#ifndef PRIVSEP_ROOT_H
#define PRIVSEP_ROOT_H
+#include "if.h"
+
pid_t ps_root_start(struct dhcpcd_ctx *ctx);
int ps_root_stop(struct dhcpcd_ctx *ctx);
ssize_t ps_root_readerror(struct dhcpcd_ctx *);
-ssize_t ps_root_ioctl(struct dhcpcd_ctx *, unsigned long, void *, size_t);
+ssize_t ps_root_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
ssize_t ps_root_os(struct ps_msghdr *, struct msghdr *);
#if defined(BSD) || defined(__sun)
ssize_t ps_root_route(struct dhcpcd_ctx *, void *, size_t);