On Monday, September 25, 2006 at 1:58 PM, Nigel Horne wrote:
> > if (!CreateProcess(szProgram,
> > szCommandLine,
> > NULL,
> > NULL,
> > TRUE,
> > CREATE_NEW_PROCESS_GROUP |
> > NORMAL_PRIORITY_CLASS,
> > NULL,
> > szWorkingDirectory,
> > NULL,
> > &pinfo))
> > status = GetLastError();
> > free(szCommandLine);
> > if (status == ERROR_SUCCESS)
> > {
> > CloseHandle(pinfo.hProcess);
> > CloseHandle(pinfo.hThread);
> > }
> >
> > On success, the returned pinfo structure contains the dwProcessId
which
> > is later used at shutdown time to pass to
GenerateConsoleCtrlEvent().
>
> Except, as I said, I get error -6 :-(
OK.
Meanwhile, you seem to have done something to address the problem since
the current PowerTools.MSI installs a ClamAV Service which actually
stops the freshclam.exe process.... This may be a bit brute force using
TerminateProcess, which may leave a mess if freshclam happens to be
processing an update when it is attempted to be stopped.
In any case, if you are still interested, I've done some research on
what I'm doing in my service application: First, my earlier suggestion
about calling GenerateConsoleCtrlEvent(CTRL_C_EVENT, dwProcessId) is not
exactly what my code is doing. My code actually calls
GenerateConsoleCtrlEvent with CTRL_BREAK_EVENT. I did some testing and
the same code doesn't pass a signal to the created process when called
with CTRL_C_EVENT. It doesn't get an error, but no signal is delivered
- I can't explain why. I suggested using CTRL_C_EVENT since the
documentation doesn't seem to indicate that any unexpected behavior
would happen. This suggestion was based on the fact that freshclam.exe
already had a signal handler for SIGINT. You should be able to use
CTRL_BREAK_EVENT if you define a windows signal handler for SIGBREAK in
freshclam.c:
#ifdef C_WINDOWS
signal(SIGINT, daemon_sighandler);
signal(SIGBREAK, daemon_sighandler);
terminate = 0;
#else
Second, the above CreateProcess() code was not the only relevant code
required before creating the process. I also call AllocConsole() in the
initialization code of my service, then the background service has a
"console" which the created processes can inherit, which therefore can
be pass these signals thru.
- Mark Pizzolato
_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-win32