[Nut-upsdev] nut-scanner pthread issue
Michal Hlavinka
mhlavink at redhat.com
Mon Sep 10 09:12:04 UTC 2012
> 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.
Right, on Linux, pthread_t is a pointer.
> I did not find something saying that an implementation of pthread
forbid thre thread ID to be 0 (correct me if I am wrong).
I did not find any documentation neither
> setting the appropriate nutscan_avail_* variable to 0 might be a
better way.
yes, it'll fix the problem too
> ________________________________________
> 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)
>
More information about the Nut-upsdev
mailing list