Bugs item #2924128, was opened at 2009-12-31 22:25
Message generated for change (Comment added) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2924128&group_id=78018
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: rolyapples (rolyapples)
Assigned to: Mark Hammond (mhammond)
Summary: Crash in dispatchServiceCtrl() for service with power event
Initial Comment:
If you create a service that accepts power events (by overriding GetAcceptedControls), the service will crash in dispatchServiceCtrl() when any power event other than PBT_POWERSETTINGCHANGE occurs.
The problem is that the code assumes eventData for a SERVICE_CONTROL_POWEREVENT is always a pointer to a POWERBROADCAST_SETTING structure, however that is only the case when dwEventType is PBT_POWERSETTINGCHANGE. For other event types (e.g. PBT_APMSUSPEND), the eventData is null.
To reproduce:
1. From your python install directory run "python Lib\site-packages\win32\Demos\service\serviceEvents.py install"
2. Run "python Lib\site-packages\win32\Demos\service\serviceEvents.py start"
3. Put your machine to sleep
4. Wake your machine
5. Check the windows application event log - see that there's an error for the service & that the service is no longer running
Changing this in dispatchServiceCtrl() in PythonService.cpp:
case SERVICE_CONTROL_POWEREVENT: {
POWERBROADCAST_SETTING *pbs = (POWERBROADCAST_SETTING *)eventData;
sub = Py_BuildValue("NN",
PyWinObject_FromIID(pbs->PowerSetting),
PyString_FromStringAndSize((char *)pbs->Data, pbs->DataLength));
break;
To the following is working for me:
case SERVICE_CONTROL_POWEREVENT: {
if (dwEventType == PBT_POWERSETTINGCHANGE) {
POWERBROADCAST_SETTING *pbs = (POWERBROADCAST_SETTING *)eventData;
sub = Py_BuildValue("NN",
PyWinObject_FromIID(pbs->PowerSetting),
PyString_FromStringAndSize((char *)pbs->Data, pbs->DataLength));
}
else {
sub = Py_None;
Py_INCREF(sub);
}
break;
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2010-08-30 14:26
Message:
thanks
Checking in PythonService.cpp;
new revision: 1.28; previous revision: 1.27
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-01-02 13:10
Message:
looks good, thanks!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2924128&group_id=78018
|