Skip to content

Commit

Permalink
Merge pull request #2251 from aquette/2249-nut-master-branch-builds-b…
Browse files Browse the repository at this point in the history
…roken-after-recent-prs-andor-infra-changes

2249 nut master branch builds broken after recent prs andor infra changes
  • Loading branch information
jimklimov authored Dec 25, 2023
2 parents 3eb96fe + 6577bb7 commit b22c133
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tools/nut-scanner/nut-scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ nutscan_device_t * nutscan_scan_xml_http_range(const char *start_ip, const char

nutscan_device_t * nutscan_scan_nut(const char * startIP, const char * stopIP, const char * port, useconds_t usec_timeout);

nutscan_device_t * nutscan_scan_nut_simulation();
nutscan_device_t * nutscan_scan_nut_simulation(void);

nutscan_device_t * nutscan_scan_avahi(useconds_t usec_timeout);

Expand Down
56 changes: 21 additions & 35 deletions tools/nut-scanner/scan_nut_simulation.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Arnaud Quette
* Copyright (C) 2023-2024 Arnaud Quette
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -25,9 +25,6 @@
#include "nut-scan.h"
#include "nut_stdint.h"
#include <dirent.h>
#if !HAVE_DECL_REALPATH
# include <sys/stat.h>
#endif

#define SCAN_NUT_SIMULATION_DRIVERNAME "dummy-ups"

Expand All @@ -38,50 +35,40 @@ static nutscan_device_t * dev_ret = NULL;
static pthread_mutex_t dev_mutex;
#endif

/* return 1 when filter is ok (.dev or .seq) */
static int filter_ext(const struct dirent *dir)
{
if(!dir)
return 0;

if(dir->d_type == DT_REG) { /* only deal with regular file */
const char *ext = strrchr(dir->d_name,'.');
if((!ext) || (ext == dir->d_name))
return 0;
else {
if ((strcmp(ext, ".dev") == 0) || (strcmp(ext, ".seq") == 0)) {
return 1;
}
}
}
return 0;
}

nutscan_device_t * nutscan_scan_nut_simulation()
nutscan_device_t * nutscan_scan_nut_simulation(void)
{
DIR *dp;
struct dirent *dirp;
nutscan_device_t * dev = NULL;
struct dirent **namelist;
int n;

#if HAVE_PTHREAD
pthread_mutex_init(&dev_mutex, NULL);
#endif /* HAVE_PTHREAD */

upsdebugx(1,"Scanning: %s", CONFPATH);

n = scandir(CONFPATH, &namelist, filter_ext, alphasort);
if (n < 0) {
fatal_with_errno(EXIT_FAILURE, "Failed to scandir");
if ((dp = opendir(CONFPATH)) == NULL) {
fatal_with_errno(EXIT_FAILURE, "Failed to open %s", CONFPATH);
return NULL;
}
else {
while (n--) {
upsdebugx(1,"Found simulation file: %s", namelist[n]->d_name);

while ((dirp = readdir(dp)) != NULL)
{
const char *ext;

upsdebugx(5, "Comparing file %s with simulation file extensions", dirp->d_name);
ext = strrchr(dirp->d_name, '.');
if((!ext) || (ext == dirp->d_name))
continue;

/* Filter on '.dev' and '.seq' extensions' */
if ((strcmp(ext, ".dev") == 0) || (strcmp(ext, ".seq") == 0)) {
upsdebugx(1,"Found simulation file: %s", dirp->d_name);

dev = nutscan_new_device();
dev->type = TYPE_NUT_SIMULATION;
dev->driver = strdup(SCAN_NUT_SIMULATION_DRIVERNAME);
dev->port = strdup(namelist[n]->d_name);
dev->port = strdup(dirp->d_name);

#ifdef HAVE_PTHREAD
pthread_mutex_lock(&dev_mutex);
Expand All @@ -90,10 +77,9 @@ nutscan_device_t * nutscan_scan_nut_simulation()
#ifdef HAVE_PTHREAD
pthread_mutex_unlock(&dev_mutex);
#endif
free(namelist[n]);
}
free(namelist);
}
closedir(dp);

#if HAVE_PTHREAD
pthread_mutex_destroy(&dev_mutex);
Expand Down

0 comments on commit b22c133

Please sign in to comment.