On Mon, Jun 13, 2016 at 4:41 PM, Gert Doering <g...@greenie.muc.de> wrote:
> Hi, > > On Mon, Jun 13, 2016 at 04:22:39PM -0400, Selva Nair wrote: > > As Windows clears semaphores when all open handles to it are gone, this > is > > a problem only when there is one or more other openvpn processes running. > > > > Any suggestions on how to fix this? > > Would "relinquish the semaphore when the initialization is finished, and > re-acuire it when running the netsh.exe commands for route deletion on > tunnel teardown" work? > > Aka "while openvpn is running in steady state, no handle exists", so the > semaphore should clear itself. > > Good idea. Just open and close the semaphore as and when needed instead of keeping the open handle throughout the life of the process. That should work, I think. > Not sure I understand the environment well enough to say whether this > might work or not... > My understanding is that when the process terminates all handles are closed but the semaphores lock count doesn't change. Until there are no open handles at which point the semaphore can be cleared. So it does seem your suggestion should work. I'll test it. Also we could just avoid opening the semaphore at all if interactive service is in use. By the way, the interactive service currently uses an un-named sempahore --- the thinking was that there is only one process, so a global name is not needed. But if both automatic and interactive services are in use, it may be better to use the same global semaphore everywhere. > Bonus question: write a unit test that anticipates this and catches it :-) > > All our units need to be perfect, so this just cannot happen! ;-) > corollary: No code can be perfect, ergo no unit test can ever be written ;) Selva