From: Selva Nair Date: Fri, 24 Jun 2016 02:50:56 +0000 (-0400) Subject: Return process id of openvpn from interactive service to client X-Git-Tag: v2.4_alpha1~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4c9bbe6c367132c8570fe747d85a6075ff04245;p=thirdparty%2Fopenvpn.git Return process id of openvpn from interactive service to client - The process id is returned as a message formatted in the same manner as error messages from the service to the client: i.e., a three-line message with error number formatted as 0x%08x on line 1, followed by the PID in format 0x%08x on line 2 and a description that reads as "Process ID" on line 3. Error number is set to zero to indicate this is an informational message. This provides a way for service clients to check the status of openvpn and terminate it without needing management interface or exit event. Useful when the interactive service is used from a launch script, or to force-terminate openvpn from the GUI if/when needed. v2 changes: format of the message changed as described above. Signed-off-by: Selva Nair Acked-by: Gert Doering Message-Id: <1466736656-27501-1-git-send-email-selva.nair@gmail.com> URL: http://article.gmane.org/gmane.network.openvpn.devel/11984 Signed-off-by: Gert Doering --- diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 2453f1766..ffaa1710c 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -230,6 +230,21 @@ WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even return AsyncPipeOp (write, pipe, data, size, count, events); } +static VOID +ReturnProcessId (HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) +{ + const WCHAR msg[] = L"Process ID"; + WCHAR buf[22 + _countof(msg)]; /* 10 chars each for error and PID and 2 for line breaks */ + + /* + * Same format as error messages (3 line string) with error = 0 in + * 0x%08x format, PID on line 2 and a description "Process ID" on line 3 + */ + _snwprintf (buf, _countof(buf), L"0x%08x\n0x%08x\n%s", 0, pid, msg); + buf[_countof(buf) - 1] = '\0'; + + WritePipeAsync (pipe, buf, wcslen (buf) * 2, count, events); +} static VOID ReturnError (HANDLE pipe, DWORD error, LPCWSTR func, DWORD count, LPHANDLE events) @@ -1293,6 +1308,8 @@ RunOpenvpn (LPVOID p) goto out; } + ReturnProcessId (pipe, proc_info.dwProcessId, 1, &exit_event); + CloseHandleEx (&stdout_write); CloseHandleEx (&stdin_read); CloseHandleEx (&svc_pipe);