Skip to content

Commit

Permalink
tools/nut-scanner/scan_*.c: reconcile coding style some more [network…
Browse files Browse the repository at this point in the history
…upstools#2511]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 11, 2024
1 parent e66990f commit cce2567
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tools/nut-scanner/nutscan-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions tools/nut-scanner/scan_avahi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tools/nut-scanner/scan_eaton_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions tools/nut-scanner/scan_ipmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ int nutscan_unload_ipmi_library(void);

#ifdef WITH_IPMI

#include "upsclient.h"
#include <freeipmi/freeipmi.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
32 changes: 18 additions & 14 deletions tools/nut-scanner/scan_nut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ltdl.h>

#define SCAN_NUT_DRIVERNAME "dummy-ups"
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
12 changes: 7 additions & 5 deletions tools/nut-scanner/scan_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int nutscan_unload_snmp_library(void);
# undef _WIN32_WINNT
#endif

#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <ltdl.h>

/* workaround for buggy Net-SNMP config
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tools/nut-scanner/scan_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions tools/nut-scanner/scan_xml_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit cce2567

Please sign in to comment.