Page MenuHomeFreeBSD

D60401.id188793.diff
No OneTemporary

D60401.id188793.diff

diff --git a/lib/libcasper/libcasper/libcasper.c b/lib/libcasper/libcasper/libcasper.c
--- a/lib/libcasper/libcasper/libcasper.c
+++ b/lib/libcasper/libcasper/libcasper.c
@@ -95,7 +95,7 @@
return (NULL);
}
- pid = pdfork(&pfd, PD_NOWAITPID);
+ pid = casper_pdfork(&pfd);
if (pid == 0) {
/* Child. */
close(sock[0]);
diff --git a/lib/libcasper/libcasper/libcasper_impl.h b/lib/libcasper/libcasper/libcasper_impl.h
--- a/lib/libcasper/libcasper/libcasper_impl.h
+++ b/lib/libcasper/libcasper/libcasper_impl.h
@@ -33,6 +33,10 @@
#ifndef _LIBCASPER_IMPL_H_
#define _LIBCASPER_IMPL_H_
+#include <sys/param.h>
+#include <sys/procdesc.h>
+
+#include <errno.h>
#include <stdbool.h>
#include "libcasper.h"
@@ -44,6 +48,25 @@
bool fd_is_valid(int fd);
void fd_fix_environment(int *fdp);
+static inline pid_t
+casper_pdfork(int *fdp)
+{
+ pid_t pid;
+
+ pid = pdfork(fdp, PD_NOWAITPID);
+#if __FreeBSD_version < 1700000
+ /*
+ * Kernels predating PD_NOWAITPID (introduced in 15.2) reject the
+ * flag with EINVAL before creating a child, so retrying without
+ * it is safe. The child must then be reaped with waitpid(2), as
+ * before. This fallback is compiled out starting with 17.0.
+ */
+ if (pid == -1 && errno == EINVAL)
+ pid = pdfork(fdp, 0);
+#endif
+ return (pid);
+}
+
/* Private service functions. */
struct service *service_alloc(const char *name,
service_limit_func_t *limitfunc,
diff --git a/lib/libcasper/libcasper/zygote.c b/lib/libcasper/libcasper/zygote.c
--- a/lib/libcasper/libcasper/zygote.c
+++ b/lib/libcasper/libcasper/zygote.c
@@ -149,7 +149,7 @@
error = errno;
goto send;
}
- pid = pdfork(&procfd, PD_NOWAITPID);
+ pid = casper_pdfork(&procfd);
switch (pid) {
case -1:
/* Failure. */

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 11, 9:13 AM (3 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40434539
Default Alt Text
D60401.id188793.diff (1 KB)

Event Timeline