Return process id of openvpn from interactive service to client
PATCH 1/1 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 pid formatted as 0x%08x on line 1, "Process Id" on line 2 and a blank line 3.
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.
--- src/openvpnserv/interactive.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
src/openvpnserv/interactive.c +14 -0
@@ -230,6 +230,18 @@ WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE evenreturn AsyncPipeOp (write, pipe, data, size, count, events); } +static VOID +ReturnProcessId (HANDLE pipe,DWORD pid,DWORD count,LPHANDLE events) +{ +const WCHAR msg[] =L"\nProcess ID\n" ; +WCHAR buf[10 +_countof (msg)];/* 10 characters for the pid in 0x%08x format */ + +/* A 3-line string like an error message but with pid in place of error number */ +_snwprintf (buf,_countof (buf),L"0x%08x%s" , 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 +1305,8 @@ RunOpenvpn (LPVOID p) goto out; } +ReturnProcessId (pipe, proc_info.dwProcessId,1 , &exit_event); +CloseHandleEx (&stdout_write);CloseHandleEx (&stdin_read);CloseHandleEx (&svc_pipe);
Signature · 1 line
1.7.10.4
Hi,
Quoted 9 lines · Selva Nair
- 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 pid formatted as 0x%08x on line 1, "Process Id" on line 2 and a blank line 3.
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.
How does the GUI currently handle return messages? As in, does this need GUI changes, or is the GUI prepared to handle anything that comes along?
src/openvpnserv/interactive.c WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even · line 244
Quoted 13 lines
src/openvpnserv/interactive.c +12
-0+static VOID +ReturnProcessId (HANDLE pipe,DWORD pid,DWORD count,LPHANDLE events) +{ +const WCHAR msg[] =L"\nProcess ID\n" ; +WCHAR buf[10 +_countof (msg)];/* 10 characters for the pid in 0x%08x format */ + +/* A 3-line string like an error message but with pid in place of error number */ +_snwprintf (buf,_countof (buf),L"0x%08x%s" , pid, msg); + buf[_countof (buf) -1 ] ='\0' ; + +WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events); +}
Where does the extra blank line come from? If I'm not all confused (this is before my first cup of tea) this will write
%08x\nProcess ID\n
into the buffer, and not \n\n...
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Quoted 6 lines · Gert Doering
Quoted 5 lines · Selva Nair
- 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 pid formatted as 0x%08x on line 1, "Process Id" on line 2 and a blank line 3.
Quoted 9 lines
Quoted 4 lines
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.
How does the GUI currently handle return messages? As in, does this need GUI changes, or is the GUI prepared to handle anything that comes along?
Currently the GUI interpretes two custom error codes (0x2000000 and 0x20000001) and ignores the rest. So it will just a log a message and ignore this one. Unless the PID happens to match one of those two numbers. Though I've never seen PIDs that large.
An alternative is to set error = 0 and pass PID as the second line:
"0x00000000\nPID\Process ID"
where PID may be formatted as 0x%08x. May be that is better?
Quoted 19 lines
src/openvpnserv/interactive.c WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even
Quoted 6 lines
src/openvpnserv/interactive.c +5
-0+static VOID +ReturnProcessId (HANDLE pipe,DWORD pid,DWORD count,LPHANDLE events) +{ +const WCHAR msg[] =L"\nProcess ID\n" ; +WCHAR buf[10 +_countof (msg)];/* 10 characters for the pid in 0x%08x format */
Review
Quoted 2 lines
(quoted diff) +2
-0+ + /* A 3-line string like an error message but with pid in place oferror number */
src/openvpnserv/interactive.c WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even · line 244
Quoted 5 lines
src/openvpnserv/interactive.c +5
-0+_snwprintf (buf,_countof (buf),L"0x%08x%s" , pid, msg); + buf[_countof (buf) -1 ] ='\0' ; + +WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events); +}Where does the extra blank line come from? If I'm not all confused (this is before my first cup of tea) this will write
Quoted 3 lines
%08x\nProcess ID\n
into the buffer, and not \n\n...
May be its my terminology of what is a "line", not your tea. The currently used format is NUMBER\nLINE2\nLINE3 so there is no \n at the end of line
3. In the present case that would be "%08x\nProcess ID\n"
Thanks for looking into this.
Selva
Hi,
Quoted 9 lines · Selva Nair
Quoted 3 lines
How does the GUI currently handle return messages? As in, does this need GUI changes, or is the GUI prepared to handle anything that comes along?
Currently the GUI interpretes two custom error codes (
0x2000000and0x20000001) and ignores the rest. So it will just a log a message and ignore this one. Unless the PID happens to match one of those two numbers. Though I've never seen PIDs that large.
Quoted 5 lines
An alternative is to set error = 0 and pass PID as the second line:
"0x00000000\nPID\Process ID"
where PID may be formatted as 0x%08x. May be that is better?
I think this is better - define a convention for "informational messages" (which this could be) and then use it at both ends :-)
Quoted 18 lines
Quoted 18 lines
src/openvpnserv/interactive.c WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even
Quoted 5 lines
src/openvpnserv/interactive.c +5
-0+static VOID +ReturnProcessId (HANDLE pipe,DWORD pid,DWORD count,LPHANDLE events) +{ +const WCHAR msg[] =L"\nProcess ID\n" ; +WCHAR buf[10 +_countof (msg)];/* 10 characters for the pid in 0x%08x format */
Review
Quoted 2 lines
(quoted diff) +2
-0+ + /* A 3-line string like an error message but with pid in place oferror number */
src/openvpnserv/interactive.c WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE even · line 244
Quoted 5 lines
src/openvpnserv/interactive.c +5
-0+_snwprintf (buf,_countof (buf),L"0x%08x%s" , pid, msg); + buf[_countof (buf) -1 ] ='\0' ; + +WritePipeAsync (pipe, buf,wcslen (buf) *2 , count, events); +}Where does the extra blank line come from? If I'm not all confused (this is before my first cup of tea) this will write
Quoted 8 lines
Quoted 3 lines
%08x\nProcess ID\n
into the buffer, and not \n\n...
May be its my terminology of what is a "line", not your tea. The currently used format is NUMBER\nLINE2\nLINE3 so there is no \n at the end of line
3. In the present case that would be "%08x\nProcess ID\n"
Indeed, terminology. For me, a line ends with a "\n" - but it certainly does not *have* to. If service and gui agree on "thee parts, separated by two \n, no trailing \n", this is good enough (and in which case the code does what is expected).
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...PATCH 1/1 Return process id of openvpn from interactive service to client
In reply to Selva Nair- 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.
--- src/openvpnserv/interactive.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
src/openvpnserv/interactive.c +17 -0
@@ -230,6 +230,21 @@ WritePipeAsync (HANDLE pipe, LPVOID data, DWORD size, DWORD count, LPHANDLE evenreturn 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);
Signature · 1 line
1.7.10.4
ACK.
Only compile-tested and "stared at code".
Your patch has been applied to the master branch.
commit e4c9bbe6c367132c8570fe747d85a6075ff04245
Author: Selva Nair Date: Thu Jun 23 22:50:56 2016 -0400
Return process id of openvpn from interactive service to client
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11984
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering