0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-20 12:02:28 +02:00

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 <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
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 <gert@greenie.muc.de>
This commit is contained in:
Selva Nair 2016-06-23 22:50:56 -04:00 committed by Gert Doering
parent d023fb661c
commit e4c9bbe6c3

View File

@ -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);