From: Razvan Cojocaru <[email protected]> Log failures to create or disconnect the first pipe instance with their own messages, instead of falling through to the generic one. This makes a pipe name already in use distinguishable, and logs the error before CloseHandleEx() can clobber it.
Change-Id: Id795de7dfe1324fb00660b6f8a9043732aa3e84c Signed-off-by: Razvan Cojocaru <[email protected]> Acked-by: Heiko Hund <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2356 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2356 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Heiko Hund <[email protected]> diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 1cb191a..a381fa1 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -4066,35 +4066,34 @@ swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service", service_instance); + HANDLE pipe = INVALID_HANDLE_VALUE; + static HANDLE blocker = INVALID_HANDLE_VALUE; if (blocker == INVALID_HANDLE_VALUE) { blocker = CreateNamedPipe(pipe_name, flags | FILE_FLAG_FIRST_PIPE_INSTANCE, mode, PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, &sa); - if (blocker != INVALID_HANDLE_VALUE && !DisconnectNamedPipe(blocker)) + if (blocker == INVALID_HANDLE_VALUE) { - DWORD error = GetLastError(); + MsgToEventLog(M_SYSERR, L"Could not create first instance of named pipe"); + goto out; + } + if (!DisconnectNamedPipe(blocker)) + { + MsgToEventLog(M_SYSERR, L"Could not disconnect first instance of named pipe"); CloseHandleEx(&blocker); - SetLastError(error); + goto out; } } - /* Without the first instance, fail and try again with the next call */ - HANDLE pipe = INVALID_HANDLE_VALUE; - if (blocker != INVALID_HANDLE_VALUE) - { - pipe = CreateNamedPipe(pipe_name, flags, mode, PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, - &sa); - } - - LocalFree(sd); - + pipe = CreateNamedPipe(pipe_name, flags, mode, PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, &sa); if (pipe == INVALID_HANDLE_VALUE) { MsgToEventLog(M_SYSERR, L"Could not create named pipe"); - return INVALID_HANDLE_VALUE; } +out: + LocalFree(sd); return pipe; } _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
