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)
diff -up nut-2.6.5/tools/nut-scanner/nut-scanner.c.pthreadfix nut-2.6.5/tools/nut-scanner/nut-scanner.c
--- nut-2.6.5/tools/nut-scanner/nut-scanner.c.pthreadfix 2012-09-06 13:25:03.856936357 +0200
+++ nut-2.6.5/tools/nut-scanner/nut-scanner.c 2012-09-06 13:25:03.881936493 +0200
@@ -434,22 +434,22 @@ display_help:
}
#ifdef HAVE_PTHREAD
- if( allow_usb && nutscan_avail_usb ) {
+ if( allow_usb && nutscan_avail_usb && thread[TYPE_USB]) {
pthread_join(thread[TYPE_USB],NULL);
}
- if( allow_snmp && nutscan_avail_snmp ) {
+ if( allow_snmp && nutscan_avail_snmp && thread[TYPE_SNMP]) {
pthread_join(thread[TYPE_SNMP],NULL);
}
- if( allow_xml && nutscan_avail_xml_http ) {
+ if( allow_xml && nutscan_avail_xml_http && thread[TYPE_XML]) {
pthread_join(thread[TYPE_XML],NULL);
}
- if( allow_oldnut && nutscan_avail_nut ) {
+ if( allow_oldnut && nutscan_avail_nut && thread[TYPE_NUT]) {
pthread_join(thread[TYPE_NUT],NULL);
}
- if( allow_avahi && nutscan_avail_avahi ) {
+ if( allow_avahi && nutscan_avail_avahi && thread[TYPE_AVAHI]) {
pthread_join(thread[TYPE_AVAHI],NULL);
}
- if( allow_ipmi && nutscan_avail_ipmi ) {
+ if( allow_ipmi && nutscan_avail_ipmi && thread[TYPE_IPMI]) {
pthread_join(thread[TYPE_IPMI],NULL);
}
#endif /* HAVE_PTHREAD */
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsdev