Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4fd157
drivers/*.c: switch to #include "nut_float.h" instead of direct <math…
jimklimov Jul 16, 2024
6fb5c24
configure.ac, m4/nut_check_bool.m4, include/nut_bool.h, tests/nutbool…
jimklimov Jul 16, 2024
b57689a
m4/nut_check_pkgconfig.m4: report PKG_CONFIG_PATH and `pkg-config --v…
jimklimov Jul 17, 2024
4ddc5ae
m4/nut_check_pkgconfig.m4: when cross-building with a non-cross pkg-c…
jimklimov Jul 17, 2024
6ea8d7a
docs/Makefile.am: adjust to possibility of repeated date+author title…
jimklimov Jul 17, 2024
d2eb31f
NEWS.adoc: when cross-building with a non-cross pkg-config program, n…
jimklimov Jul 17, 2024
59ef670
m4/nut_check_libusb.m4: differentiate native and cross mingw builds, …
jimklimov Jul 17, 2024
91ea627
configure.ac: try to run sem_init() detector to see if it is usable […
jimklimov Jul 17, 2024
2fe558a
configure.ac: add a sem_open() detector of named semaphore support [#…
jimklimov Jul 17, 2024
88e99ed
tools/nut-scanner/*: add ability to use named semaphores [#2522]
jimklimov Jul 17, 2024
2c3a09e
tools/nut-scanner/nut-scanner.c: bump RESERVE_FD_COUNT for NetSNMP us…
jimklimov Jul 17, 2024
ab8c221
Makefile.am: check-scripts-syntax: fix to ignore old /bin/bash and tr…
jimklimov Jul 17, 2024
f04499c
Merge remote-tracking branch 'origin/issue-1176' into issue-2522
jimklimov Jul 18, 2024
b844450
Merge remote-tracking branch 'origin/issue-2510' into issue-2522
jimklimov Jul 18, 2024
a7d899e
docs/config-prereqs.txt: update about NUT CI Jenkins agent on MacOS
jimklimov Jul 18, 2024
cfe4985
server/upsd.c: fix build on systems without IPV6_V6ONLY
jimklimov Jul 18, 2024
7f30060
Jenkinsfile-dynamatrix: do not build "pure autoconf default" scenario…
jimklimov Jul 18, 2024
cc576aa
tools/nut-scanner/nut-scanner.c: include nut_stdint.h always, not onl…
jimklimov Jul 18, 2024
1634be7
tools/nut-scanner/scan_*: typo fix from copy-pasted %i=>PRIuSIZE [#2522]
jimklimov Jul 18, 2024
38153e9
clients/upssched.c: indent preprocessor clauses
jimklimov Jul 18, 2024
3fcc871
tools/nut-scanner/nut-scan.h, configure.ac: sem_open() usage needs O_…
jimklimov Jul 18, 2024
830d1e6
configure.ac: refactor discovery of SEMLIBS (may be needed to AX_RUN_…
jimklimov Jul 18, 2024
bee9346
include/timehead.h, configure.ac, common/Makefile.am, common/timegm_f…
jimklimov Jul 18, 2024
7101211
Provide fallback strtof() for platforms where it is missing
jimklimov Jul 18, 2024
e3b197b
tools/nut-scanner/nut-scanner.c: update build for systems that lack a…
jimklimov Jul 18, 2024
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
5 changes: 5 additions & 0 deletions Jenkinsfile-dynamatrix
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ set | sort -n """
// so exclude systems which have e.g. gcc-4.2.1 which claims
// type range comparison warnings despite pragma fencing.
// gcc-4.8.x on CentOS 7 and Ubuntu 14.04 looks already okay.
+ [[~/OS_DISTRO=macos/]]
// MacOS (at least agents prepared with HomeBrew packages)
// requires a few pkg-config and CFLAGS pre-sets which are
// done in ci_build.sh and defeat the purpose of this stage.
// So it is easier and more honest to just skip it.
], body)
}, // getParStages
//'bodyParStages': {}
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ check-NIT check-NIT-devel:
###
check-scripts-syntax:
@echo 'NOTE: modern bash complains about scripts using backticks (warning not error), which we ignore in NUT codebase for portability reasons: `...` obsolete, use $$(...)'
@RUNBASH=bash; if [ -x /bin/bash ]; then RUNBASH=/bin/bash ; else if [ -x /usr/bin/env ] ; then RUNBASH="/usr/bin/env bash"; fi; fi ; \
@RUNBASH=bash; if [ -x /bin/bash ] && /bin/bash -c 'echo $${BASH_VERSION}' | grep -E '^[456789]\.' ; then RUNBASH=/bin/bash ; else if [ -x /usr/bin/env ] ; then RUNBASH="/usr/bin/env bash"; fi; fi ; \
for F in `git ls-files || find . -type f` ; do \
case "`file "$$F"`" in \
*"Bourne-Again shell script"*) ( set -x ; $$RUNBASH -n "$$F" ; ) ;; \
Expand Down
7 changes: 7 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ during a NUT build.
variable support was added to optionally disable this verification.
Also the NUT daemons should request to double-check against their
run-time process name (if it can be detected). [issue #2463]
* introduced `m4` macros to check during `configure` phase for the
platform, and a `nut_bool.h` header with `nut_bool_t` type to use
during build, to avoid the numerous definitions of Boolean types
and values (or macros) in the NUT codebase. [issue #1176, issue #31]

- various recipe, documentation and source files were revised to address
respective warnings issued by the new generations of analysis tools.
Expand Down Expand Up @@ -243,6 +247,9 @@ during a NUT build.
of more complex configurations (e.g. some line patterns that involve too
many double-quote characters) which are valid for NUT proper. [#657]

- Cross-builds using only a host implementation of `pkg-config` program
should now ignore host `*.pc` files and avoid confusion.

- NUT CI farm build recipes, documentation and some `m4`/`configure.ac`
sources updated to handle a much larger build scope on MacOS. Also
migrated the builders to Apple Silicon from x86 (deprecated by CircleCI).
Expand Down
53 changes: 27 additions & 26 deletions clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@

#include <sys/types.h>
#ifndef WIN32
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
# include <sys/wait.h>
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>
# include <unistd.h>
# include <fcntl.h>
# include <poll.h>
#else
#include "wincompat.h"
#include <winsock2.h>
#include <ws2tcpip.h>
# include "wincompat.h"
# include <winsock2.h>
# include <ws2tcpip.h>
#endif

#include "upssched.h"
Expand All @@ -75,7 +75,7 @@ static const char *upsname, *notify_type;

#ifdef WIN32
static OVERLAPPED connect_overlapped;
#define BUF_LEN 512
# define BUF_LEN 512
#endif

#define PARENT_STARTED -2
Expand Down Expand Up @@ -361,7 +361,7 @@ static TYPE_FD open_sock(void)

/* Wait for a connection */
ConnectNamedPipe(fd,&connect_overlapped);
#endif
#endif /* WIN32 */

return fd;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ static int send_to_one(conn_t *conn, const char *fmt, ...)

return 0; /* failed */
}
#endif
#endif /* WIN32 */

return 1; /* OK */
}
Expand All @@ -495,9 +495,9 @@ static TYPE_FD conn_add(TYPE_FD sockfd)
int ret;
conn_t *tmp, *last;
struct sockaddr_un saddr;
#if defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED)
# if defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED)
int salen;
#else
# else
socklen_t salen;
#endif

Expand Down Expand Up @@ -625,7 +625,7 @@ static TYPE_FD conn_add(TYPE_FD sockfd)
upsdebugx(3, "new connection on handle %p", acc);

pconf_init(&conn->ctx, NULL);
#endif
#endif /* WIN32 */

return acc;
}
Expand Down Expand Up @@ -753,7 +753,8 @@ static int sock_read(conn_t *conn)
/* Restart async read */
memset(conn->buf,0,sizeof(conn->buf));
ReadFile(conn->fd,conn->buf,1,NULL,&(conn->read_overlapped));
#endif
#endif /* WIN32 */

ret = pconf_char(&conn->ctx, ch);

if (ret == 0) /* nothing to parse yet */
Expand Down Expand Up @@ -815,7 +816,7 @@ static void start_daemon(TYPE_FD lockfd)
/* child */

/* make fds 0-2 (typically) point somewhere defined */
#ifdef HAVE_DUP2
# ifdef HAVE_DUP2
/* system can close (if needed) and (re-)open a specific FD number */
if (1) { /* scoping */
TYPE_FD devnull = open("/dev/null", O_RDWR);
Expand All @@ -836,8 +837,8 @@ static void start_daemon(TYPE_FD lockfd)

close(devnull);
}
#else
# ifdef HAVE_DUP
# else /* not HAVE_DUP2 */
# ifdef HAVE_DUP
/* opportunistically duplicate to the "lowest-available" FD number */
close(STDIN_FILENO);
if (open("/dev/null", O_RDWR) != STDIN_FILENO)
Expand All @@ -854,7 +855,7 @@ static void start_daemon(TYPE_FD lockfd)
if (dup(STDIN_FILENO) != STDERR_FILENO)
fatal_with_errno(EXIT_FAILURE, "dup /dev/null as STDERR");
}
# else
# else /* not HAVE_DUP */
close(STDIN_FILENO);
if (open("/dev/null", O_RDWR) != STDIN_FILENO)
fatal_with_errno(EXIT_FAILURE, "re-open /dev/null as STDIN");
Expand All @@ -870,8 +871,8 @@ static void start_daemon(TYPE_FD lockfd)
if (open("/dev/null", O_RDWR) != STDERR_FILENO)
fatal_with_errno(EXIT_FAILURE, "re-open /dev/null as STDERR");
}
# endif
#endif
# endif /* not HAVE_DUP */
# endif /* not HAVE_DUP2 */

pipefd = open_sock();

Expand Down Expand Up @@ -1048,7 +1049,7 @@ static void start_daemon(TYPE_FD lockfd)

checktimers();
}
#endif
#endif /* WIN32 */
}

/* --- 'client' functions --- */
Expand Down Expand Up @@ -1100,7 +1101,7 @@ static TYPE_FD try_connect(void)
if (VALID_FD(pipefd))
return pipefd;

#endif
#endif /* WIN32 */

return ERROR_FD;
}
Expand Down Expand Up @@ -1289,7 +1290,7 @@ static void sendcmd(const char *cmd, const char *arg1, const char *arg2)
CloseHandle(pipefd);
continue;
}
#endif
#endif /* WIN32 */

if (!strncmp(buf, "OK", 2))
return; /* success */
Expand Down
12 changes: 12 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ endif !BUILDING_IN_TREE
$(top_builddir)/include/nut_version.h:
+@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F)

# FIXME: If we maintain some of those helper libs as subsets of the others
# (strictly), maybe build the lowest common denominator only and link the
# bigger scopes with it (rinse and repeat)?
libcommon_la_SOURCES = state.c str.c upsconf.c
libcommonclient_la_SOURCES = state.c str.c

Expand Down Expand Up @@ -95,6 +98,15 @@ else !HAVE_STRSEP
libcommonclient_la_SOURCES += strsep.c
endif !HAVE_STRSEP

if WANT_TIMEGM_FALLBACK
# fall back to simple implem
libcommon_la_SOURCES += timegm_fallback.c
libcommonstr_la_SOURCES += timegm_fallback.c
libcommonclient_la_SOURCES += timegm_fallback.c
else !WANT_TIMEGM_FALLBACK
EXTRA_DIST += timegm_fallback.c
endif !WANT_TIMEGM_FALLBACK

if HAVE_WINDOWS
libnutwincompat_la_SOURCES = wincompat.c $(top_srcdir)/include/wincompat.h
libnutwincompat_la_LDFLAGS =
Expand Down
27 changes: 27 additions & 0 deletions common/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,30 @@ int str_ends_with(const char *s, const char *suff) {

return (slen >= sufflen) && (!memcmp(s + slen - sufflen, suff, sufflen));
}

#ifndef HAVE_STRTOF
# include <errno.h>
# include <stdio.h>
float strtof(const char *nptr, char **endptr)
{
double d;
int i;

if (!nptr || !*nptr) {
errno = EINVAL;
return 0;
}

i = sscanf(nptr, "%f", &d);
if (i < 1) {
errno = EINVAL;
return 0;
}

if (endptr) {
*endptr = (char*)nptr + i;
}

return (float)d;
}
#endif
49 changes: 49 additions & 0 deletions common/timegm_fallback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Fallback timegm() for systems that lack one.
* Algorithm: http://howardhinnant.github.io/date_algorithms.html
* https://stackoverflow.com/a/58037981/4715872
*/

#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif

static int days_from_epoch_1970(int y, int m, int d)
{
y -= m <= 2;
int era = y / 400;
int yoe = y - era * 400; // [0, 399]
int doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1; // [0, 365]
int doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; // [0, 146096]
return era * 146097 + doe - 719468;
}

/* It does not modify broken-down time */
time_t timegm_fallback(struct tm const* t)
{
int year = t->tm_year + 1900;
int month = t->tm_mon; // 0-11
int days_since_epoch_1970;

if (month > 11)
{
year += month / 12;
month %= 12;
}
else if (month < 0)
{
int years_diff = (11 - month) / 12;
year -= years_diff;
month += 12 * years_diff;
}
days_since_epoch_1970 = days_from_epoch_1970(year, month + 1, t->tm_mday);

return 60 * (60 * (24L * days_since_epoch_1970 + t->tm_hour) + t->tm_min) + t->tm_sec;
}

Loading