Win32: Event signals
Hi James and everyone else,
I'm working on a patch to add events for the other unix signals. I want this because I want the GUI to have the same possibility to send openvpn signals like you have in unix or when running from the console.
While working on this I think I either found a bug or I've missunderstood something.
What is the purpose of beeing able to set the exit_event initial state with the --service option?
Currently I've always done as the service_wrapper. I've created a non-signaled event and then started openvpn with --service exit_event_nameXX 1.
I think this is wrong, as I (and the service wrapper) had created the event in non-signaled state, so shouldn't I tell openvpn that the initial state is non-signaled?
But, as the event is already created as non-signaled state when OpenVPN tries to create the exit_event, it will remain in the non-signaled state, even though openvpn tries to create it signaled, so things works as expected.
What doesn't work as expected is if I create the event in signaled state, then OpenVPN wont start regardless if I pass 1 or 0 as initial_state via --service, because
if (WaitForSingleObject (event, 0) != WAIT_TIMEOUT)
msg (M_FATAL, "ERROR: EventMSN ('%s') is signaled", event_name);always fails if the event is in signaled state.
So, if it is impossible to start with a signaled event, why would you want to tell openvpn to create the event in signaled state?
I found this while rebugging my real problem, which is how to add the new signals. I wanted to avoid adding new options to openvpn if not necessary, so I though that I would create events simply named as the specified exit_event_name and just append _SIGUSR1, _SIGUSR2 and _SIGHUP.
The problem arised when I tried to create these events in the same initial state as specified via --service, which is 1 from both the service_wrapper and my GUI.
As I havn't added support for these events in the GUI, and we have to remain compatibility with the service wrapper, openvpn would fail to start as no such events exist, and openvpn then creates the new events in signal state, which means that the above code will fail, as the event is signaled.
So how do we fix this?
For the new signals I could just ignore the initial_state parameter of --service and always create them in non-signaled state.
or, we could fix the code by making it check that the event really is in the state given by --service instead of always checking if it's non-signaled. The drawback of this is that it will break compatiblity with the current version of the service_wrapper and OpenVPN GUI, but maybe it's the only right way to go...
Hope I havn't missunderstood everything and just waisted your time...
--
_____________________________________________________________
Mathias Sundman (^) ASCII Ribbon Campaign OpenVPN GUI for Windows X NO HTML/RTF in e-mail http://www.nilings.se/openvpn / \ NO Word docs in e-mail
Quoted 32 lines · Mathias Sundman
Hi James and everyone else,
I'm working on a patch to add events for the other unix signals. I want this because I want the GUI to have the same possibility to send openvpn signals like you have in unix or when running from the console.
While working on this I think I either found a bug or I've missunderstood something.
What is the purpose of beeing able to set the
exit_eventinitial state with the --service option?Currently I've always done as the
service_wrapper. I've created a non-signaled event and then started openvpn with --serviceexit_event_nameXX1.I think this is wrong, as I (and the service wrapper) had created the event in non-signaled state, so shouldn't I tell openvpn that the initial state is non-signaled?
But, as the event is already created as non-signaled state when OpenVPN tries to create the
exit_event, it will remain in the non-signaled state, even though openvpn tries to create it signaled, so things works as expected.What doesn't work as expected is if I create the event in signaled state, then OpenVPN wont start regardless if I pass 1 or 0 as
initial_statevia --service, becauseif (WaitForSingleObject (event, 0) != WAIT_TIMEOUT) msg (M_FATAL, "ERROR: EventMSN ('%s') is signaled", event_name);always fails if the event is in signaled state.
So, if it is impossible to start with a signaled event, why would you want to tell openvpn to create the event in signaled state?
I found this while rebugging my real problem, which is how to add the new signals. I wanted to avoid adding new options to openvpn if not necessary, so I though that I would create events simply named as the specified
exit_event_nameand just append_SIGUSR1,_SIGUSR2and_SIGHUP.The problem arised when I tried to create these events in the same initial state as specified via --service, which is 1 from both the
service_wrapperand my GUI.As I havn't added support for these events in the GUI, and we have to remain compatibility with the service wrapper, openvpn would fail to start as no such events exist, and openvpn then creates the new events in signal state, which means that the above code will fail, as the event is signaled.
Quoted 6 lines
So how do we fix this?
For the new signals I could just ignore the
initial_stateparameter of --service and always create them in non-signaled state.or, we could fix the code by making it check that the event really is in the state given by --service instead of always checking if it's non-signaled. The drawback of this is that it will break compatiblity with the current version of the
service_wrapperand OpenVPN GUI, but maybe it's the only right way to go...
(sorry for the "EventMSN" above. I added MSN just to make sure the message I saw was prited by that line...)
I tried to fix it by changing the code in win32_signal_open() to verify the event has the status given by --service by replacing
if (WaitForSingleObject (ws->in.read, 0) != WAIT_TIMEOUT)
msg (M_FATAL, "ERROR: Exit Event ('%s') is signaled", exit_event_name);
with
if (WaitForSingleObject (ws->in.read, 0) !=
(exit_event_initial_state ? WAIT_OBJECT_0 : WAIT_TIMEOUT))
msg (M_FATAL, "ERROR: Exit Event ('%s') is signaled",
exit_event_name);
but then we ran into problems in win32_service_interrupt() where again we only check if the event has become signaled, instead of checking if it has changed status since it was created.
Can we simply drop the initial_state parameter of the --service option, and always expect the event to initially be created in non-signaled state?
I can't see the use for it, and as it has never worked to accually start openvpn with a signaled event, we couln't possibly break any existing software, could we?
Signature · 4 lines
_________________________________________________________ Mathias Sundman (^) ASCII Ribbon Campaign NILINGS AB X NO HTML/RTF in e-mail Tel: +46-(0)8-666 32 28 / \ NO Word docs in e-mail
Quoted 9 lines · Mathias Sundman
Quoted 9 lines
I'm working on a patch to add events for the other unix signals. I want this because I want the GUI to have the same possibility to send openvpn signals like you have in unix or when running from the console.
While working on this I think I either found a bug or I've missunderstood something.
What is the purpose of beeing able to set the
exit_eventinitial state with the --service option?Currently I've always done as the
service_wrapper. I've created a non-signaled event and then started openvpn with --serviceexit_event_nameXX1.I think this is wrong, as I (and the service wrapper) had created the event in non-signaled state, so shouldn't I tell openvpn that the initial state is non-signaled?
After even more thinking about this, I realize that I probably did misunderstood the --service option after all.
If the intention of starting openvpn with --service xxx 1, is that openvpn should exit immediataly if no non-signaled event already exists, then there's no bug in the current code.
But, why would one want that?
and, back to my origial problem, how should I add these new signals? I don't want to break compatibility with existing versions of OpenVPN GUI or the service wrapper, which both calls openvpn with --service xxx 1.
If I create them accordingly to --service option, it will cause openvpn to exit immediatly as these events don't exist when using an old version of OpenVPN GUI or the service_wrapper.
Should I just create them in non-signaled state regardless of the --service option?
or, do I need to add a new option for each signal?
/Mathias
Quoted 11 lines · Mathias Sundman
Hi James and everyone else,
I'm working on a patch to add events for the other unix signals. I want this because I want the GUI to have the same possibility to send openvpn signals like you have in unix or when running from the console.
While working on this I think I either found a bug or I've missunderstood something.
What is the purpose of beeing able to set the
exit_eventinitial state with the --service option?
You almost always want to set initial state to 0.
The only reason to set it to 1 is to force OpenVPN to exit with an error if the event object does not already exist.
This works because the initial state is only used by the process which creates the event for the first time.
So it is a good way to make the startup of an openvpn process be conditional on the exit event having been pre-created by a controlling service.
James