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....@lists.alioth.debian.org 
[nut-upsdev-bounces+fredericbohe=eaton....@lists.alioth.debian.org] on behalf 
of Michal Hlavinka [[email protected]]
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)
Index: nut-scanner.c
===================================================================
--- nut-scanner.c	(revision 3719)
+++ nut-scanner.c	(working copy)
@@ -371,6 +371,7 @@
 	if( allow_snmp && nutscan_avail_snmp ) {
 		if( start_ip == NULL ) {
 			printq(quiet,"No start IP, skipping SNMP\n");
+			nutscan_avail_snmp = 0;
 		}
 		else {
 			printq(quiet,"Scanning SNMP bus.\n");
@@ -398,6 +399,7 @@
 	if( allow_oldnut && nutscan_avail_nut) {
 		if( start_ip == NULL ) {
 			printq(quiet,"No start IP, skipping NUT bus (old connect method)\n");
+			nutscan_avail_nut = 0;
 		}
 		else {
 			printq(quiet,"Scanning NUT bus (old connect method).\n");
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsdev

Reply via email to