summaryrefslogtreecommitdiffstats
path: root/src/privsep-root.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-01-08 20:13:20 +0000
committerRoy Marples <roy@marples.name>2020-01-08 20:13:20 +0000
commit84bb0708e0d5996f010b733fdb68d17bf441e255 (patch)
tree4c0f27df4110076994676980475f569ae6dc155d /src/privsep-root.c
parentc55279517dc3df6743100c5e525d464010f563c6 (diff)
downloaddhcpcd-84bb0708e0d5996f010b733fdb68d17bf441e255.tar.xz
ioctl: The POSIX signature differs from BSD and glibc
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.
Diffstat (limited to 'src/privsep-root.c')
-rw-r--r--src/privsep-root.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/privsep-root.c b/src/privsep-root.c
index dd60a4ff..47363624 100644
--- a/src/privsep-root.c
+++ b/src/privsep-root.c
@@ -46,6 +46,8 @@
#include "privsep.h"
#include "script.h"
+__CTASSERT(sizeof(ioctl_request_t) <= sizeof(unsigned long));
+
struct psr_error
{
ssize_t psr_result;
@@ -130,7 +132,16 @@ ps_root_doioctl(unsigned long req, void *data, size_t len)
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)
@@ -410,9 +421,18 @@ ps_root_script(const struct interface *ifp, const void *data, size_t len)
}
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);
}