Skip to content

Commit 6aac70a

Browse files
jeffhostetlergitster
authored andcommitted
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%[email protected]/T/#m08be8f1942ea8a2c36cfee0e51cdf06489fdeafc Reported-by: Randall S. Becker <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36a7eb6 commit 6aac70a

File tree

6 files changed

+48
-14
lines changed

6 files changed

+48
-14
lines changed

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,13 +1679,31 @@ ifdef NO_UNIX_SOCKETS
16791679
else
16801680
LIB_OBJS += unix-socket.o
16811681
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
16841682
endif
16851683

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+
#
16861695
ifdef USE_WIN32_IPC
1696+
BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
16871697
LIB_OBJS += compat/simple-ipc/ipc-shared.o
16881698
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
16891707
endif
16901708

16911709
ifdef NO_ICONV

compat/simple-ipc/ipc-shared.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
#include "pkt-line.h"
55
#include "thread-utils.h"
66

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
814

915
int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
1016
ipc_server_application_cb *application_cb,
@@ -24,5 +30,3 @@ int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
2430

2531
return ret;
2632
}
27-
28-
#endif /* SUPPORTS_SIMPLE_IPC */

compat/simple-ipc/ipc-unix-socket.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#include "unix-socket.h"
77
#include "unix-stream-server.h"
88

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
1115
#endif
1216

1317
enum ipc_active_state ipc_get_active_state(const char *path)

compat/simple-ipc/ipc-win32.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include "pkt-line.h"
55
#include "thread-utils.h"
66

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
913
#endif
1014

1115
static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)

contrib/buildsystems/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,15 @@ endif()
248248

249249
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
250250
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)
251253
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()
253260
endif()
254261

255262
set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
@@ -966,6 +973,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
966973
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
967974
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
968975
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")
969977
if(WIN32)
970978
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
971979
endif()

simple-ipc.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
* See Documentation/technical/api-simple-ipc.txt
66
*/
77

8-
#if defined(GIT_WINDOWS_NATIVE) || !defined(NO_UNIX_SOCKETS)
9-
#define SUPPORTS_SIMPLE_IPC
10-
#endif
11-
128
#ifdef SUPPORTS_SIMPLE_IPC
139
#include "pkt-line.h"
1410

0 commit comments

Comments
 (0)