]> git.ipfire.org Git - thirdparty/git.git/commitdiff
simple-ipc: correct ifdefs when NO_PTHREADS is defined
authorJeff Hostetler <jeffhost@microsoft.com>
Thu, 20 May 2021 18:28:10 +0000 (18:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 May 2021 22:55:00 +0000 (07:55 +0900)
Simple IPC always requires threads (in addition to various
platform-specific IPC support).  Fix the ifdefs in the Makefile
to define SUPPORTS_SIMPLE_IPC when appropriate.

Previously, the Unix version of the code would only verify that
Unix domain sockets were available.

This problem was reported here:
https://lore.kernel.org/git/YKN5lXs4AoK%2FJFTO@coredump.intra.peff.net/T/#m08be8f1942ea8a2c36cfee0e51cdf06489fdeafc

Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
compat/simple-ipc/ipc-shared.c
compat/simple-ipc/ipc-unix-socket.c
compat/simple-ipc/ipc-win32.c
contrib/buildsystems/CMakeLists.txt
simple-ipc.h

index dfc37b0480e481141050817771ed27dc41418450..8ca59f49439a7a0da132b2253af52f7128f55a0b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1679,13 +1679,31 @@ ifdef NO_UNIX_SOCKETS
 else
        LIB_OBJS += unix-socket.o
        LIB_OBJS += unix-stream-server.o
-       LIB_OBJS += compat/simple-ipc/ipc-shared.o
-       LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
 endif
 
+# Simple IPC requires threads and platform-specific IPC support.
+# Only platforms that have both should include these source files
+# in the build.
+#
+# On Windows-based systems, Simple IPC requires threads and Windows
+# Named Pipes.  These are always available, so Simple IPC support
+# is optional.
+#
+# On Unix-based systems, Simple IPC requires pthreads and Unix
+# domain sockets.  So support is only enabled when both are present.
+#
 ifdef USE_WIN32_IPC
+       BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
        LIB_OBJS += compat/simple-ipc/ipc-shared.o
        LIB_OBJS += compat/simple-ipc/ipc-win32.o
+else
+ifndef NO_PTHREADS
+ifndef NO_UNIX_SOCKETS
+       BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
+       LIB_OBJS += compat/simple-ipc/ipc-shared.o
+       LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
+endif
+endif
 endif
 
 ifdef NO_ICONV
index 1edec8159532eb4b7b5ec312ebb6c0da59d37da5..1b9d359ab68185036c40a40bb2a44b8e5fbfb913 100644 (file)
@@ -4,7 +4,13 @@
 #include "pkt-line.h"
 #include "thread-utils.h"
 
-#ifdef SUPPORTS_SIMPLE_IPC
+#ifndef SUPPORTS_SIMPLE_IPC
+/*
+ * This source file should only be compiled when Simple IPC is supported.
+ * See the top-level Makefile.
+ */
+#error SUPPORTS_SIMPLE_IPC not defined
+#endif
 
 int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
                   ipc_server_application_cb *application_cb,
@@ -24,5 +30,3 @@ int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
 
        return ret;
 }
-
-#endif /* SUPPORTS_SIMPLE_IPC */
index 38689b278df30e1366afb378a5cd9f1c7062da7f..1927e6ef4bca8eb7f7a6827078e4c56cd5d40a0f 100644 (file)
@@ -6,8 +6,12 @@
 #include "unix-socket.h"
 #include "unix-stream-server.h"
 
-#ifdef NO_UNIX_SOCKETS
-#error compat/simple-ipc/ipc-unix-socket.c requires Unix sockets
+#ifndef SUPPORTS_SIMPLE_IPC
+/*
+ * This source file should only be compiled when Simple IPC is supported.
+ * See the top-level Makefile.
+ */
+#error SUPPORTS_SIMPLE_IPC not defined
 #endif
 
 enum ipc_active_state ipc_get_active_state(const char *path)
index 8f89c02037e36c9edba263a83882d147e463bbff..8dc7bda087da5f6f5996e7f79e2e0631d09ace4e 100644 (file)
@@ -4,8 +4,12 @@
 #include "pkt-line.h"
 #include "thread-utils.h"
 
-#ifndef GIT_WINDOWS_NATIVE
-#error This file can only be compiled on Windows
+#ifndef SUPPORTS_SIMPLE_IPC
+/*
+ * This source file should only be compiled when Simple IPC is supported.
+ * See the top-level Makefile.
+ */
+#error SUPPORTS_SIMPLE_IPC not defined
 #endif
 
 static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
index 629a1817459b8ccdffc122dd33f8f87528623b5f..67d97d2443d7715e58b861dd550277b9188cfcfd 100644 (file)
@@ -248,8 +248,15 @@ endif()
 
 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
        list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-win32.c)
+       add_compile_definitions(SUPPORTS_SIMPLE_IPC)
+       set(SUPPORTS_SIMPLE_IPC 1)
 else()
-       list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
+       # Simple IPC requires both Unix sockets and pthreads on Unix-based systems.
+       if(NOT NO_UNIX_SOCKETS AND NOT NO_PTHREADS)
+               list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
+               add_compile_definitions(SUPPORTS_SIMPLE_IPC)
+               set(SUPPORTS_SIMPLE_IPC 1)
+       endif()
 endif()
 
 set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
@@ -966,6 +973,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
 if(WIN32)
        file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
 endif()
index dc3606e30bd61955fbce1dda9882f71a995279d2..2c48a5ee004732e7c33739befcf6efe4db2d4e27 100644 (file)
@@ -5,10 +5,6 @@
  * See Documentation/technical/api-simple-ipc.txt
  */
 
-#if defined(GIT_WINDOWS_NATIVE) || !defined(NO_UNIX_SOCKETS)
-#define SUPPORTS_SIMPLE_IPC
-#endif
-
 #ifdef SUPPORTS_SIMPLE_IPC
 #include "pkt-line.h"