]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Return process id of openvpn from interactive service to client
authorSelva Nair <selva.nair@gmail.com>
Fri, 24 Jun 2016 02:50:56 +0000 (22:50 -0400)
committerGert Doering <gert@greenie.muc.de>
Fri, 24 Jun 2016 06:24:07 +0000 (08:24 +0200)
- 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>
src/openvpnserv/interactive.c

index 2453f17664617dc294cd72ecfb3730148a6678a6..ffaa1710cf0ee130d4e64e8cb2020bc103eb31a7 100644 (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);