[Nut-upsdev] nut-scanner pthread issue
FredericBohe at Eaton.com
FredericBohe at Eaton.com
Thu Sep 6 14:30:11 UTC 2012
Hi Michal,
There is indeed a bug, thanks for reporting it.
I am not sure your patch is the right way to fix. I guess it's crashing because pthread_t is some kind of pointer on your system. But after a quick search I did not find something saying that an implementation of pthread forbid thre thread ID to be 0 (correct me if I am wrong). It might even break the portability of the code. So I guess, setting the appropriate nutscan_avail_* variable to 0 might be a better way.
Let me know what you think of the attached patch.
Regards,
Fred
--
Eaton Opensource Team - http://opensource.eaton.com
-----------------------------
-----------------------------
________________________________________
From: nut-upsdev-bounces+fredericbohe=eaton.com at lists.alioth.debian.org [nut-upsdev-bounces+fredericbohe=eaton.com at lists.alioth.debian.org] on behalf of Michal Hlavinka [mhlavink at redhat.com]
Sent: Thursday, September 06, 2012 3:24 PM
To: NUT Developers
Subject: [Nut-upsdev] nut-scanner pthread issue
Hi,
the terminating part of nut-scanner can crash in pthread code, because
some threads won't exist. For example snmp part:
==============================
if( allow_snmp && nutscan_avail_snmp ) {
if( start_ip == NULL ) {
printq(quiet,"No start IP, skipping SNMP\n");
}
else {
printq(quiet,"Scanning SNMP bus.\n");
#ifdef HAVE_PTHREAD
if( pthread_create(&thread[TYPE_SNMP],NULL,run_snmp,&snmp_sec)) {
nutscan_avail_snmp = 0;
}
#else
dev[TYPE_SNMP] = nutscan_scan_snmp(start_ip,end_ip,timeout,&snmp_sec);
#endif /* HAVE_PTHREAD */
}
}
==============================
if start_ip==NULL, pthread is not created, but later...
if( allow_snmp && nutscan_avail_snmp && thread[TYPE_SNMP]) {
pthread_join(thread[TYPE_SNMP],NULL);
}
it calls pthread_join with threan[TYPE_SNMP]==0,
pthread_join(0, ?) behaviour is undefined, on my system undefined=crashes.
I used attached patch to get rid of it.
Cheers,
Michal
/me is back from vacation and going to another one tmrw, so I won't be
reachable for some time (again)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pthread.patch
Type: text/x-diff
Size: 651 bytes
Desc: pthread.patch
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20120906/3776aa5e/attachment.patch>
More information about the Nut-upsdev
mailing list