diff --git a/tools/nut-scanner/nutscan-init.c b/tools/nut-scanner/nutscan-init.c index bf458ec394..a0246f52fc 100644 --- a/tools/nut-scanner/nutscan-init.c +++ b/tools/nut-scanner/nutscan-init.c @@ -598,7 +598,7 @@ void nutscan_init(void) nutscan_avail_nut_simulation = 1; } -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally to scan_* modules */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); diff --git a/tools/nut-scanner/scan_avahi.c b/tools/nut-scanner/scan_avahi.c index 812c0f9ac1..18ea2db55f 100644 --- a/tools/nut-scanner/scan_avahi.c +++ b/tools/nut-scanner/scan_avahi.c @@ -95,7 +95,7 @@ static int (*nut_avahi_service_browser_free)(AvahiServiceBrowser *); static char * (*nut_avahi_address_snprint)(char *ret_s, size_t length, const AvahiAddress *a); static const AvahiPoll* (*nut_avahi_simple_poll_get)(AvahiSimplePoll *s); -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); @@ -104,7 +104,7 @@ int nutscan_unload_avahi_library(void) return nutscan_unload_library(&nutscan_avail_avahi, &dl_handle, &dl_saved_libname); } -/* return 0 on error; visible externally */ +/* Return 0 on error; visible externally */ int nutscan_load_avahi_library(const char *libname_path); int nutscan_load_avahi_library(const char *libname_path) { @@ -132,7 +132,10 @@ int nutscan_load_avahi_library(const char *libname_path) dl_error = lt_dlerror(); goto err; } - lt_dlerror(); /* Clear any existing error */ + + /* Clear any existing error */ + lt_dlerror(); + *(void **) (&nut_avahi_service_browser_get_client) = lt_dlsym(dl_handle, "avahi_service_browser_get_client"); if ((dl_error = lt_dlerror()) != NULL) { goto err; diff --git a/tools/nut-scanner/scan_eaton_serial.c b/tools/nut-scanner/scan_eaton_serial.c index aee6af5c73..93f95875bf 100644 --- a/tools/nut-scanner/scan_eaton_serial.c +++ b/tools/nut-scanner/scan_eaton_serial.c @@ -589,9 +589,10 @@ nutscan_device_t * nutscan_scan_eaton_serial(const char* ports_range) # ifdef HAVE_SEMAPHORE /* Wait for all current scans to complete */ if (thread_array != NULL) { - upsdebugx (2, "%s: Running too many scanning threads, " + upsdebugx (2, "%s: Running too many scanning threads (%" + PRIuSIZE "), " "waiting until older ones would finish", - __func__); + __func__, thread_count); for (i = 0; i < thread_count ; i++) { int ret; if (!thread_array[i].active) { diff --git a/tools/nut-scanner/scan_ipmi.c b/tools/nut-scanner/scan_ipmi.c index 44f4fd3325..76a1a73982 100644 --- a/tools/nut-scanner/scan_ipmi.c +++ b/tools/nut-scanner/scan_ipmi.c @@ -33,7 +33,6 @@ int nutscan_unload_ipmi_library(void); #ifdef WITH_IPMI -#include "upsclient.h" #include #include #include @@ -138,7 +137,7 @@ typedef int bool_t; static nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t * sec); static void * nutscan_scan_ipmi_device_thready(void * arg_sec); -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); @@ -633,7 +632,6 @@ nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t memset (port_id, 0, sizeof(port_id)); } - } /* Final cleanup */ diff --git a/tools/nut-scanner/scan_nut.c b/tools/nut-scanner/scan_nut.c index 435cdab294..b1d1cce4dd 100644 --- a/tools/nut-scanner/scan_nut.c +++ b/tools/nut-scanner/scan_nut.c @@ -30,6 +30,10 @@ #include "upsclient.h" #include "nut-scan.h" #include "nut_stdint.h" + +/* externally visible to nutscan-init */ +int nutscan_unload_upsclient_library(void); + #include #define SCAN_NUT_DRIVERNAME "dummy-ups" @@ -69,27 +73,26 @@ struct scan_nut_arg { useconds_t timeout; }; -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); -int nutscan_unload_upsclient_library(void); int nutscan_unload_upsclient_library(void) { return nutscan_unload_library(&nutscan_avail_nut, &dl_handle, &dl_saved_libname); } -/* return 0 on error; visible externally */ +/* Return 0 on error; visible externally */ int nutscan_load_upsclient_library(const char *libname_path); int nutscan_load_upsclient_library(const char *libname_path) { if (dl_handle != NULL) { - /* if previous init failed */ - if (dl_handle == (void *)1) { - return 0; - } - /* init has already been done */ - return 1; + /* if previous init failed */ + if (dl_handle == (void *)1) { + return 0; + } + /* init has already been done */ + return 1; } if (libname_path == NULL) { @@ -98,17 +101,18 @@ int nutscan_load_upsclient_library(const char *libname_path) } if (lt_dlinit() != 0) { - fprintf(stderr, "Error initializing lt_init\n"); - return 0; + fprintf(stderr, "Error initializing lt_init\n"); + return 0; } dl_handle = lt_dlopen(libname_path); if (!dl_handle) { - dl_error = lt_dlerror(); - goto err; + dl_error = lt_dlerror(); + goto err; } - lt_dlerror(); /* Clear any existing error */ + /* Clear any existing error */ + lt_dlerror(); *(void **) (&nut_upscli_splitaddr) = lt_dlsym(dl_handle, "upscli_splitaddr"); diff --git a/tools/nut-scanner/scan_snmp.c b/tools/nut-scanner/scan_snmp.c index b35c645846..6f96a95ac3 100644 --- a/tools/nut-scanner/scan_snmp.c +++ b/tools/nut-scanner/scan_snmp.c @@ -40,8 +40,8 @@ int nutscan_unload_snmp_library(void); # undef _WIN32_WINNT #endif -#include #include +#include #include /* workaround for buggy Net-SNMP config @@ -182,7 +182,7 @@ static oid *nut_usmHMAC256SHA384AuthProtocol; static oid *nut_usmHMAC384SHA512AuthProtocol; #endif -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ #ifndef WITH_SNMP_STATIC @@ -198,7 +198,7 @@ int nutscan_unload_snmp_library(void) #endif } -/* return 0 on error; visible externally */ +/* Return 0 on error; visible externally */ int nutscan_load_snmp_library(const char *libname_path); int nutscan_load_snmp_library(const char *libname_path) { @@ -312,7 +312,9 @@ int nutscan_load_snmp_library(const char *libname_path) goto err; } - lt_dlerror(); /* Clear any existing error */ + /* Clear any existing error */ + lt_dlerror(); + *(void **) (&nut_init_snmp) = lt_dlsym(dl_handle, "init_snmp"); if ((dl_error = lt_dlerror()) != NULL) { goto err; @@ -1331,7 +1333,7 @@ nutscan_device_t * nutscan_scan_ip_range_snmp(nutscan_ip_range_list_t * irl, # endif /* HAVE_PTHREAD_TRYJOIN */ } #else /* if not HAVE_PTHREAD */ - try_SysOID_thready((void *)tmp_sec); + try_SysOID_thready(tmp_sec); #endif /* if HAVE_PTHREAD */ /* Prepare the next iteration; note that diff --git a/tools/nut-scanner/scan_usb.c b/tools/nut-scanner/scan_usb.c index 0b756991ca..553a6d1198 100644 --- a/tools/nut-scanner/scan_usb.c +++ b/tools/nut-scanner/scan_usb.c @@ -81,7 +81,7 @@ static int (*nut_usb_get_string_simple)(libusb_device_handle *dev, int index, static char * (*nut_usb_strerror)(void); #endif /* WITH_LIBUSB_1_0 */ -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); @@ -90,7 +90,7 @@ int nutscan_unload_usb_library(void) return nutscan_unload_library(&nutscan_avail_usb, &dl_handle, &dl_saved_libname); } -/* return 0 on error; visible externally */ +/* Return 0 on error; visible externally */ int nutscan_load_usb_library(const char *libname_path); int nutscan_load_usb_library(const char *libname_path) { @@ -118,7 +118,9 @@ int nutscan_load_usb_library(const char *libname_path) dl_error = lt_dlerror(); goto err; } - lt_dlerror(); /* Clear any existing error */ + + /* Clear any existing error */ + lt_dlerror(); *(void **) (&nut_usb_init) = lt_dlsym(dl_handle, USB_INIT_SYMBOL); if ((dl_error = lt_dlerror()) != NULL) { diff --git a/tools/nut-scanner/scan_xml_http.c b/tools/nut-scanner/scan_xml_http.c index ff8ca5a414..a858c85662 100644 --- a/tools/nut-scanner/scan_xml_http.c +++ b/tools/nut-scanner/scan_xml_http.c @@ -89,7 +89,7 @@ typedef enum ebool { FALSE = 0, TRUE } bool_t; typedef int bool_t; #endif -/* return 0 on success, -1 on error e.g. "was not loaded"; +/* Return 0 on success, -1 on error e.g. "was not loaded"; * other values may be possible if lt_dlclose() errors set them; * visible externally */ int nutscan_unload_library(int *avail, lt_dlhandle *pdl_handle, char **libpath); @@ -98,7 +98,7 @@ int nutscan_unload_neon_library(void) return nutscan_unload_library(&nutscan_avail_xml_http, &dl_handle, &dl_saved_libname); } -/* return 0 on error; visible externally */ +/* Return 0 on error; visible externally */ int nutscan_load_neon_library(const char *libname_path); int nutscan_load_neon_library(const char *libname_path) { @@ -127,7 +127,9 @@ int nutscan_load_neon_library(const char *libname_path) goto err; } - lt_dlerror(); /* Clear any existing error */ + /* Clear any existing error */ + lt_dlerror(); + *(void **) (&nut_ne_xml_push_handler) = lt_dlsym(dl_handle, "ne_xml_push_handler"); if ((dl_error = lt_dlerror()) != NULL) { @@ -171,6 +173,7 @@ int nutscan_load_neon_library(const char *libname_path) } return 0; } +/* end of dynamic link library stuff */ /* A start-element callback for element with given namespace/name. */ static int startelm_cb(void *userdata, int parent, const char *nspace, const char *name, const char **atts) { @@ -479,8 +482,8 @@ nutscan_device_t * nutscan_scan_xml_http_range(const char * start_ip, const char nutscan_device_t * nutscan_scan_ip_range_xml_http(nutscan_ip_range_list_t * irl, useconds_t usec_timeout, nutscan_xml_t * sec) { bool_t pass = TRUE; /* Track that we may spawn a scanning thread */ - nutscan_xml_t * tmp_sec = NULL; nutscan_device_t * result = NULL; + nutscan_xml_t * tmp_sec = NULL; if (!nutscan_avail_xml_http) { return NULL; @@ -498,6 +501,7 @@ nutscan_device_t * nutscan_scan_ip_range_xml_http(nutscan_ip_range_list_t * irl, /* Iterate the one or a range of IPs to scan */ nutscan_ip_range_list_iter_t ip; char * ip_str = NULL; + #ifdef HAVE_PTHREAD # ifdef HAVE_SEMAPHORE sem_t * semaphore = nutscan_semaphore();