Skip to content

Commit

Permalink
compat: stub out _rs_forkhandler for compat/arc4random.c
Browse files Browse the repository at this point in the history
We need to keep the fd open at fork, but we retained the code to
handle a fork.

The original update to chacha avoided this by guarding the call
but left the code alive which produced an unused function warning
on the GitHub Ubuntu runner.
This update fixes that.
  • Loading branch information
rsmarples committed Apr 2, 2024
1 parent 0ab1dfa commit 9f8bb1f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compat/arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ static int _dhcpcd_rand_fd = -1; /* /dev/urandom fd */

static int _dhcpcd_getentropy(void *, size_t);
static inline int _rs_allocate(struct _rs **, struct _rsx **);

/* dhcpcd needs to hold onto the fd at fork due to privsep */
#if 0
static inline void _rs_forkdetect(void);
#else
#define _rs_forkdetect()
#define _rs_forkhandler()
#endif

/* Inline "arc4random.h" */
#include <sys/types.h>
Expand All @@ -89,7 +96,6 @@ static inline void _rs_rekey(u_char *dat, size_t datlen);
/* dhcpcd isn't multithreaded */
#define _ARC4_LOCK()
#define _ARC4_UNLOCK()
#define _ARC4_ATFORK(f)

static int
_dhcpcd_getentropy(void *buf, size_t length)
Expand Down Expand Up @@ -126,6 +132,7 @@ _getentropy_fail(void)
raise(SIGKILL);
}

#if 0
static volatile sig_atomic_t _rs_forked;

static inline void
Expand All @@ -148,6 +155,7 @@ _rs_forkdetect(void)
memset(rs, 0, sizeof(*rs));
}
}
#endif

static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
Expand All @@ -163,7 +171,7 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
return (-1);
}

_ARC4_ATFORK(_rs_forkhandler);
_rs_forkhandler();
return (0);
}

Expand Down

0 comments on commit 9f8bb1f

Please sign in to comment.