]> git.kaiwu.me - haproxy.git/commitdiff
BUILD: fd: unshare is not available on NetBSD
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 7 Sep 2026 13:39:53 +0000 (15:39 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 7 Sep 2026 13:45:40 +0000 (15:45 +0200)
Define HA_HAVE_UNSHARE which tests CLONE_FILES with an exception on
NetBSD which has the CLONE_FILES define for clone() but doesn't provide
unshare().

  src/thread.c: In function ‘start_extra_tgroup_threads’:
  src/thread.c:244:21: error: implicit declaration of function ‘unshare’ [-Werror=implicit-function-declaration]
    244 |                 if (unshare(CLONE_FILES) != 0) {
        |                     ^~~~~~~

No backport needed.

include/haproxy/compat.h
src/cfgparse-global.c
src/haload_init.c
src/thread.c

index 3f0f0b39307b5979c860989f77f027c59e784b16..1f486835d7653acc86e70b9409a329a273199ac6 100644 (file)
@@ -355,6 +355,11 @@ typedef struct { } empty_t;
 #define IPPROTO_MPTCP 262
 #endif
 
+#if defined(CLONE_FILES) && !defined(__NetBSD__)
+/* NetBSD defines CLONE_FILES but don't have unshare */
+#define HA_HAVE_UNSHARE
+#endif
+
 #endif /* _HAPROXY_COMPAT_H */
 
 /*
index e16eadab8b7776e028ef7e14155717e15a632f85..af1acb40f1de8d0ef4aeb7075f37b722c13698e7 100644 (file)
@@ -1521,7 +1521,7 @@ static int cfg_parse_global_tune_opts(char **args, int section_type,
                return 0;
        }
        else if (strcmp(args[0], "tune.fd.tables") == 0) {
-#ifdef CLONE_FILES
+#ifdef HA_HAVE_UNSHARE
                if (strcmp(args[1], "per-thread-group") == 0)
                        global.tune.options |= GTUNE_NO_TG_FD_SHARING;
                else if (strcmp(args[1], "shared") == 0)
index 74dac49bbcb2076d09755e6f2e4a237f4b681315..27709ce42fba63a5ac83ce0285ef5c57903dfcea 100644 (file)
@@ -438,7 +438,7 @@ void haproxy_init_args(int argc, char **argv)
        hbuf_appendf(&gbuf, "global\n");
        hbuf_appendf(&gbuf, "\ttune.memory.hot-size 3145728\n");
        hbuf_appendf(&gbuf, "\tssl-server-verify none\n");
-#ifdef CLONE_FILES
+#ifdef HA_HAVE_UNSHARE
        /* required for "tune.fd.tables" below */
        hbuf_appendf(&gbuf, "\texpose-experimental-directives\n");
        hbuf_appendf(&gbuf, "\ttune.fd.tables per-thread-group\n");
index 24f7aa751d477529560998af29b670f061c3ad74..6006e8cb2faea5cfb90930fdfda0789d42389bbd 100644 (file)
@@ -242,7 +242,7 @@ void *start_extra_tgroup_threads(void *arg)
        struct tgroup_info *tgi = (struct tgroup_info *)arg;
        int i;
 
-#ifdef CLONE_FILES
+#ifdef HA_HAVE_UNSHARE
        if (global.tune.options & GTUNE_NO_TG_FD_SHARING)
                if (unshare(CLONE_FILES) != 0) {
                        ha_alert("unshare(CLONE_FILES) failed while trying to use one FD table per thread group (%s)\n", strerror(errno));