simple-ipc/ipc-win32: add trace2 debugging

Create "ipc-debug" category events to log unexpected errors when creating Simple-IPC connections. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Sep 20, 2021 at 15:36 UTC 9bd51d4975a542adaa765af784595d7309e0dd84
1 file changed +24 -1
compat/simple-ipc/ipc-win32.c
+24 -1
@@ -49,6 +49,9 @@ static enum ipc_active_state get_active_state(wchar_t *pipe_path)
49 if (GetLastError() == ERROR_FILE_NOT_FOUND)
50 return IPC_STATE__PATH_NOT_FOUND;
51
52 + trace2_data_intmax("ipc-debug", NULL, "getstate/waitpipe/gle",
53 + (intmax_t)GetLastError());
54 +
55 return IPC_STATE__OTHER_ERROR;
56 }
57
@@ -109,9 +112,15 @@ static enum ipc_active_state connect_to_server(
112 t_start_ms = (DWORD)(getnanotime() / 1000000);
113
114 if (!WaitNamedPipeW(wpath, timeout_ms)) {
112 - if (GetLastError() == ERROR_SEM_TIMEOUT)
115 + DWORD gleWait = GetLastError();
116 +
117 + if (gleWait == ERROR_SEM_TIMEOUT)
118 return IPC_STATE__NOT_LISTENING;
119
120 + trace2_data_intmax("ipc-debug", NULL,
121 + "connect/waitpipe/gle",
122 + (intmax_t)gleWait);
123 +
124 return IPC_STATE__OTHER_ERROR;
125 }
126
@@ -133,17 +142,31 @@ static enum ipc_active_state connect_to_server(
142 break; /* try again */
143
144 default:
145 + trace2_data_intmax("ipc-debug", NULL,
146 + "connect/createfile/gle",
147 + (intmax_t)gle);
148 +
149 return IPC_STATE__OTHER_ERROR;
150 }
151 }
152
153 if (!SetNamedPipeHandleState(hPipe, &mode, NULL, NULL)) {
154 + gle = GetLastError();
155 + trace2_data_intmax("ipc-debug", NULL,
156 + "connect/setpipestate/gle",
157 + (intmax_t)gle);
158 +
159 CloseHandle(hPipe);
160 return IPC_STATE__OTHER_ERROR;
161 }
162
163 *pfd = _open_osfhandle((intptr_t)hPipe, O_RDWR|O_BINARY);
164 if (*pfd < 0) {
165 + gle = GetLastError();
166 + trace2_data_intmax("ipc-debug", NULL,
167 + "connect/openosfhandle/gle",
168 + (intmax_t)gle);
169 +
170 CloseHandle(hPipe);
171 return IPC_STATE__OTHER_ERROR;
172 }