I wrote a Module upon INIT of the module
it starts a posix thread (w/ pthread_create),  to Monitor some resource.
The thread-method is called (I know because I see
that logs to the snmpd.log) but once it "sleeps"
it then wakes and literally disappears. I never get
the "done sleeping for" or "MonitorMain: done sleep", or
"MonitorMain: exiting" messages.

Thanks for any insight/info.

-Joel

Here is the pertinent code:

in init:
pthread_t pvmMonitorThread=0;
     int rc=0;
     rc = pthread_create(&pvmMonitorThread, NULL, MonitorMain, (void 
*)NULL);
     if (rc){
         my_snmp_log(LOG_ERR,"ERROR; return code from pthread_create() 
is %d\n", rc);
     }

     int pvm_runMonitor=1; //set to zero by parent thread, when ready to 
exit.

     void *MonitorMain()
     {  
        int last=-1;
        my_snmp_log(LOG_INFO,"MonitorMain running\n");
        while(pvm_runMonitor)
        {
                ret=check_pvm_server();
                if(last!=ret)
                {
                    if(ret==PVM_STATUS_DOWN)
                    {
                        //couldn't connect set status to DOWN
                        g_pvmStatus=PVM_STATUS_DOWN;
                    }
                    if(ret==PVM_STATUS_UP)
                    {
                        g_pvmStatus=PVM_STATUS_UP;
                    }                   
                }
                snmp_log(LOG_INFO,"MonitorMain: result is %d from check_server, 
sleep 
%d\n",ret,seconds);

                //sleep won't work for pthreads (use nanosleep instead)
                // sleep(seconds);
                pvmSleep(seconds);
                snmp_log(LOG_INFO,"MonitorMain: done sleep %d\n",ret);
                last=ret;
        }
         snmp_log(LOG_INFO,"MonitorMain: exiting");
        pthread_exit(NULL);
}

void pvmSleep(int seconds)
{
        struct timespec sleepTime;
        struct timespec remainingSleepTime;
        sleepTime.tv_sec=seconds;
        sleepTime.tv_nsec=0;
        while(1){
              snmp_log(LOG_INFO,"sleeping for %d sec\n",seconds);
              nanosleep(&sleepTime,&remainingSleepTime);
              snmp_log(LOG_INFO,"done sleeping for %d sec\n",seconds);
              if(remainingSleepTime.tv_sec==0 &&
                   remainingSleepTime.tv_nsec==0)
              {
                        break;
              }
              sleepTime.tv_sec=remainingSleepTime.tv_sec;
              sleepTime.tv_nsec=remainingSleepTime.tv_nsec;
        }
}


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to