simple-ipc: correct ifdefs when NO_PTHREADS is defined

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>

Jeff Hostetler committed May 20, 2021 at 18:28 UTC 6aac70a870fc40482eca943ff0b64003497d69c1
6 files changed +48 -14
Makefile
+20 -2
@@ -1679,13 +1679,31 @@ ifdef NO_UNIX_SOCKETS
1679 else
1680 LIB_OBJS += unix-socket.o
1681 LIB_OBJS += unix-stream-server.o
1682 - LIB_OBJS += compat/simple-ipc/ipc-shared.o
1683 - LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
1682 endif
1683
1684 +# Simple IPC requires threads and platform-specific IPC support.
1685 +# Only platforms that have both should include these source files
1686 +# in the build.
1687 +#
1688 +# On Windows-based systems, Simple IPC requires threads and Windows
1689 +# Named Pipes. These are always available, so Simple IPC support
1690 +# is optional.
1691 +#
1692 +# On Unix-based systems, Simple IPC requires pthreads and Unix
1693 +# domain sockets. So support is only enabled when both are present.
1694 +#
1695 ifdef USE_WIN32_IPC
1696 + BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
1697 LIB_OBJS += compat/simple-ipc/ipc-shared.o
1698 LIB_OBJS += compat/simple-ipc/ipc-win32.o
1699 +else
1700 +ifndef NO_PTHREADS
1701 +ifndef NO_UNIX_SOCKETS
1702 + BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
1703 + LIB_OBJS += compat/simple-ipc/ipc-shared.o
1704 + LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
1705 +endif
1706 +endif
1707 endif
1708
1709 ifdef NO_ICONV
compat/simple-ipc/ipc-shared.c
+7 -3
@@ -4,7 +4,13 @@
4 #include "pkt-line.h"
5 #include "thread-utils.h"
6
7 -#ifdef SUPPORTS_SIMPLE_IPC
7 +#ifndef SUPPORTS_SIMPLE_IPC
8 +/*
9 + * This source file should only be compiled when Simple IPC is supported.
10 + * See the top-level Makefile.
11 + */
12 +#error SUPPORTS_SIMPLE_IPC not defined
13 +#endif
14
15 int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
16 ipc_server_application_cb *application_cb,
@@ -24,5 +30,3 @@ int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
30
31 return ret;
32 }
27 -
28 -#endif /* SUPPORTS_SIMPLE_IPC */
compat/simple-ipc/ipc-unix-socket.c
+6 -2
@@ -6,8 +6,12 @@
6 #include "unix-socket.h"
7 #include "unix-stream-server.h"
8
9 -#ifdef NO_UNIX_SOCKETS
10 -#error compat/simple-ipc/ipc-unix-socket.c requires Unix sockets
9 +#ifndef SUPPORTS_SIMPLE_IPC
10 +/*
11 + * This source file should only be compiled when Simple IPC is supported.
12 + * See the top-level Makefile.
13 + */
14 +#error SUPPORTS_SIMPLE_IPC not defined
15 #endif
16
17 enum ipc_active_state ipc_get_active_state(const char *path)
compat/simple-ipc/ipc-win32.c
+6 -2
@@ -4,8 +4,12 @@
4 #include "pkt-line.h"
5 #include "thread-utils.h"
6
7 -#ifndef GIT_WINDOWS_NATIVE
8 -#error This file can only be compiled on Windows
7 +#ifndef SUPPORTS_SIMPLE_IPC
8 +/*
9 + * This source file should only be compiled when Simple IPC is supported.
10 + * See the top-level Makefile.
11 + */
12 +#error SUPPORTS_SIMPLE_IPC not defined
13 #endif
14
15 static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
contrib/buildsystems/CMakeLists.txt
+9 -1
@@ -248,8 +248,15 @@ endif()
248
249 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
250 list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-win32.c)
251 + add_compile_definitions(SUPPORTS_SIMPLE_IPC)
252 + set(SUPPORTS_SIMPLE_IPC 1)
253 else()
252 - list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
254 + # Simple IPC requires both Unix sockets and pthreads on Unix-based systems.
255 + if(NOT NO_UNIX_SOCKETS AND NOT NO_PTHREADS)
256 + list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
257 + add_compile_definitions(SUPPORTS_SIMPLE_IPC)
258 + set(SUPPORTS_SIMPLE_IPC 1)
259 + endif()
260 endif()
261
262 set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
@@ -966,6 +973,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
973 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
974 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
975 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
976 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
977 if(WIN32)
978 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
979 endif()
simple-ipc.h
-4
@@ -5,10 +5,6 @@
5 * See Documentation/technical/api-simple-ipc.txt
6 */
7
8 -#if defined(GIT_WINDOWS_NATIVE) || !defined(NO_UNIX_SOCKETS)
9 -#define SUPPORTS_SIMPLE_IPC
10 -#endif
11 -
8 #ifdef SUPPORTS_SIMPLE_IPC
9 #include "pkt-line.h"
10