Skip to content

2249 nut master branch builds broken after recent prs andor infra changes #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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