From bd6e2339fe3a88fe84d833a2bfb58bc6545e33c5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 24 Jul 2024 14:48:03 +0200 Subject: [PATCH 01/11] configure.ac: avoid square brackets in m4 script [#1949] Signed-off-by: Jim Klimov --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index be40080330..1ea26f244a 100644 --- a/configure.ac +++ b/configure.ac @@ -16,7 +16,7 @@ dnl If the NUT codebase in this workspace is being developed and rebuilt dnl without reconfiguration, detailed version in the binaries will differ dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file). (command -v git >/dev/null 2>/dev/null) \ -&& NUT_SOURCE_GITREV="`(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' 2>/dev/null || git describe --tags --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' 2>/dev/null ) | sed -e 's/^v\([0-9]\)/\1/' -e 's,^.*/,,'`" \ +&& NUT_SOURCE_GITREV="`(git describe --tags --match 'v@<:@0-9@:>@*.@<:@0-9@:>@*.@<:@0-9@:>@' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' 2>/dev/null || git describe --tags --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' 2>/dev/null ) | sed -e 's/^v\(@<:@0-9@:>@\)/\1/' -e 's,^.*/,,'`" \ || NUT_SOURCE_GITREV="" dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads: From 713a8cdc8171122782867a8e6457b89d9770700d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Thu, 25 Jul 2024 17:44:55 +0200 Subject: [PATCH 02/11] ci_build.sh: check_gitignore(): introduce FILE_GLOB_EXCLUDE and handle FILE_GLOB allowing for multi-token values Signed-off-by: Jim Klimov --- ci_build.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ci_build.sh b/ci_build.sh index cf094e0e24..38afef363d 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -667,7 +667,9 @@ check_gitignore() { # Shell-glob filename pattern for points of interest to git status # and git diff; note that filenames starting with a dot should be # reported by `git status -- '*'` and not hidden. - [ -n "${FILE_GLOB-}" ] || FILE_GLOB='*' + [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" + # Always filter these names away; note: no extra quoting here: + FILE_GLOB_EXCLUDE=":!.ci*.log*" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) @@ -682,12 +684,11 @@ check_gitignore() { # One invocation should report to log if there was any discrepancy # to report in the first place (GITOUT may be empty without error): - GITOUT="`git status $GIT_ARGS -s -- "${FILE_GLOB}"`" \ + GITOUT="`git status $GIT_ARGS -s -- ${FILE_GLOB} ${FILE_GLOB_EXCLUDE}`" \ || { echo "WARNING: Could not query git repo while in `pwd`" >&2 ; GITOUT=""; } if [ -n "${GITOUT-}" ] ; then echo "$GITOUT" \ - | grep -E -v '^.. \.ci.*\.log.*' \ | grep -E "${FILE_REGEX}" else echo "Got no output and no errors querying git repo while in `pwd`: seems clean" >&2 @@ -695,12 +696,12 @@ check_gitignore() { echo "===" # Another invocation checks that there was nothing to complain about: - if [ -n "`git status $GIT_ARGS -s "${FILE_GLOB}" | grep -E -v '^.. \.ci.*\.log.*' | grep -E "^.. ${FILE_REGEX}"`" ] \ + if [ -n "`git status $GIT_ARGS -s ${FILE_GLOB} ${FILE_GLOB_EXCLUDE} | grep -E "^.. ${FILE_REGEX}"`" ] \ && [ "$CI_REQUIRE_GOOD_GITIGNORE" != false ] \ ; then echo "FATAL: There are changes in $FILE_DESCR files listed above - tracked sources should be updated in the PR (even if generated - not all builders can do so), and build products should be added to a .gitignore file, everything made should be cleaned and no tracked files should be removed! You can 'export CI_REQUIRE_GOOD_GITIGNORE=false' if appropriate." >&2 if [ "$GIT_DIFF_SHOW" = true ]; then - PAGER=cat git diff -- "${FILE_GLOB}" || true + PAGER=cat git diff -- ${FILE_GLOB} ${FILE_GLOB_EXCLUDE} || true fi echo "===" return 1 From d69f8dec2c6d72057fdc1b7476252dadd71acc94 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 01:54:22 +0200 Subject: [PATCH 03/11] ci_build.sh: check_gitignore(): define FILE_GLOB_EXCLUDE differently [#1949] Signed-off-by: Jim Klimov --- ci_build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci_build.sh b/ci_build.sh index 38afef363d..e2e9960e4d 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -668,8 +668,8 @@ check_gitignore() { # and git diff; note that filenames starting with a dot should be # reported by `git status -- '*'` and not hidden. [ -n "${FILE_GLOB-}" ] || FILE_GLOB="'*'" - # Always filter these names away; note: no extra quoting here: - FILE_GLOB_EXCLUDE=":!.ci*.log*" + # Always filter these names away: + FILE_GLOB_EXCLUDE="':!.ci*.log*'" [ -n "${GIT_ARGS-}" ] || GIT_ARGS='' # e.g. GIT_ARGS="--ignored" # Display contents of the diff? # (Helps copy-paste from CI logs to source to amend quickly) From 230113d3d24945daca69d531dea31ec273dd3004 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:25:58 +0000 Subject: [PATCH 04/11] autogen.sh: add line separators around big blocks of scripted messages Signed-off-by: Jim Klimov --- autogen.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autogen.sh b/autogen.sh index 91f98f1377..9d7d05e8c2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -178,6 +178,7 @@ fi [ "$AUTOTOOL_RES" = 0 ] && [ -s configure ] && [ -x configure ] \ || { cat << EOF +---------------------------------------------------------------------- FAILED: did not generate an executable configure script! # Note: on some systems "autoreconf", "automake" et al are dispatcher @@ -189,6 +190,7 @@ FAILED: did not generate an executable configure script! # check the configure.ac line it refers to and un-comment (or comment away) # the third argument for AM_SILENT_RULES check, or comment away the whole # "ifdef" block if your autotools still would not grok it. +---------------------------------------------------------------------- EOF exit 1 } >&2 @@ -217,15 +219,20 @@ else CONFIG_SHELL="`head -1 configure | sed 's,^#!,,'`" fi -# NOTE: Unquoted, may be multi-token +# NOTE: Unquoted CONFIG_SHELL, may be multi-token $CONFIG_SHELL -n configure 2>/dev/null >/dev/null \ -|| { echo "FAILED: configure script did not pass shell interpreter syntax checks with $CONFIG_SHELL" >&2 +|| { + echo "----------------------------------------------------------------------" >&2 + echo "FAILED: configure script did not pass shell interpreter syntax checks with $CONFIG_SHELL" >&2 echo "NOTE: If you are using an older OS release, try executing the script with" >&2 echo "a more functional shell implementation (dtksh, bash, dash...)" >&2 echo "You can re-run this script with a CONFIG_SHELL in environment" >&2 + echo "----------------------------------------------------------------------" >&2 exit 1 } +echo "----------------------------------------------------------------------" echo "SUCCESS: The generated configure script passed shell interpreter syntax checks" echo "Please proceed by running './configure --with-many-desired-options'" echo "For details check './configure --help' or docs/configure.txt in NUT sources" +echo "----------------------------------------------------------------------" From 10b5677d7db6180a9cb5f4166e0b0a5412930223 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 07:42:35 +0000 Subject: [PATCH 05/11] configure.ac: revise injection of "-O0" into debug-able C code builds on some platforms Signed-off-by: Jim Klimov --- configure.ac | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1ea26f244a..fab0529531 100644 --- a/configure.ac +++ b/configure.ac @@ -5292,7 +5292,16 @@ AS_CASE(["${CONFIG_CXXFLAGS}"], AS_CASE(["${nut_with_debuginfo_C}"], [yes], [ AS_IF([test x"${CLANGCC}" = x"yes" -o x"${GCC}" = x"yes"], [ - CFLAGS="${CFLAGS} -O0 -g3 -gdwarf-2" + dnl Where we can enable debug, minimize the optimizations. + dnl On some platforms LIBNETSNMP_CFLAGS or some such defines + dnl _FORTIFY_SOURCE=N which in turn "requires compiling with + dnl optimization", so we can not disable it in CFLAGS applied + dnl in the end of each and every build command line (highest + dnl priority). However, CPPFLAGS are before (making these + dnl lines an implementation-dependent hack)... + dnl AS_IF([set | grep -E 'FORTIFY_SOURCE'], [], [CFLAGS="${CFLAGS} -O0"]) + CPPFLAGS="${CPPFLAGS} -O0" + CFLAGS="${CFLAGS} -g3 -gdwarf-2" ],[nut_with_debuginfo_C="Unknown C compiler, not adding options"] )], dnl # [no]: By default we do not add debug info @@ -5305,7 +5314,9 @@ AS_CASE(["${nut_with_debuginfo_C}"], AS_CASE(["${nut_with_debuginfo_CXX}"], [yes], [ AS_IF([test "x$CLANGXX" = xyes -o "x$GXX" = xyes], [ - dnl Where we can enable debug, minimize the optimizations + dnl Where we can enable debug, minimize the optimizations. + dnl NOTE: Concerns for -O0 behavior commented above are about C code, + dnl not seen (yet) with C++. CXXFLAGS="${CXXFLAGS} -O0 -g3 -gdwarf-2" dnl Use same settings for CPPUNIT tests (they bump their own by default) CPPUNIT_NUT_CXXFLAGS="" From 0c87a5ea3a195b9a390dadd1947242279eec7267 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 08:11:10 +0000 Subject: [PATCH 06/11] common/common.c: compareprocname(): comment about libtool-wrapped developer builds [#2463] Signed-off-by: Jim Klimov --- common/common.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/common.c b/common/common.c index 729e7fbefb..5acecd0118 100644 --- a/common/common.c +++ b/common/common.c @@ -1018,6 +1018,12 @@ int compareprocname(pid_t pid, const char *procname, const char *progname) } #endif + /* TOTHINK: Developer builds wrapped with libtool may be prefixed + * by "lt-" in the filename. Should we re-enter (or wrap around) + * this search with a set of variants with/without the prefix on + * both sides?.. + */ + /* Nothing above has matched */ ret = 0; From ae06adc47c0e1170d18a4ee126f2153e080a7af7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 08:39:09 +0000 Subject: [PATCH 07/11] docs/config-prereqs.txt, docs/nut.dict: clarify envvar pre-sets for MacOS/Homebrew [#2522, #2555] Signed-off-by: Jim Klimov --- docs/config-prereqs.txt | 10 ++++++++++ docs/nut.dict | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/config-prereqs.txt b/docs/config-prereqs.txt index 8f6de45016..939f542cf6 100644 --- a/docs/config-prereqs.txt +++ b/docs/config-prereqs.txt @@ -1366,6 +1366,16 @@ setup, and https://brew.sh if you want to install it on your MacOS system depending on architecture -- see https://docs.brew.sh/Installation for more details; find via `brew config | grep HOMEBREW_PREFIX: | awk '{print $2}'`). +NOTE: The quickest pre-configuration for `ci_build.sh` integration with this +non-default build system would be to add this line into your shell profile: +---- +eval "$(brew shellenv)" +---- + +NOTE: Homebrew is not the only build/packaging system available for MacOS, +so NUT scripts do not make any assumptions nor try to find a build system +they were not told about (via `HOMEBREW_PREFIX` in this case). + Currently known dependencies for basic build include: ---- # Optional for a quick spin: diff --git a/docs/nut.dict b/docs/nut.dict index 8a0c0b2b5b..575264f3a8 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 3197 utf-8 +personal_ws-1.1 en 3198 utf-8 AAC AAS ABI @@ -2751,6 +2751,7 @@ sfr sgml sgs sha +shellenv shm shutdownArguments shutdowncmd From 3f264814daf6bd415a6ccefab79fc271d7eaec6c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 08:47:47 +0000 Subject: [PATCH 08/11] configure.ac: set PACKAGE_TARNAME and PACKAGE_URL verbatim via AC_INIT() [#1949] Signed-off-by: Jim Klimov --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index fab0529531..4d149b3518 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ dnl +------------------------------------------------------------------+ dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" dnl in include/nut_version.h (generated by make) -AC_INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues]) +AC_INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues],[nut],[https://networkupstools.org/]) dnl See docs/maintainer-guide.txt about releases - updating the version dnl above is a small part of the consistent ritual! From 4e34074575dae28cc5dc1f5e974d03e473e80f81 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 09:01:27 +0000 Subject: [PATCH 09/11] drivers/libshut.c: shut_control_msg(): restrict memcpy() amount Avoid warning: libshut.c:1296:25: error: 'memcpy' forming offset [11, 17] is out of the bounds [0, 11] of object 'shut_pkt' with type 'unsigned char[11]' [-Werror=array-bounds=] Signed-off-by: Jim Klimov --- drivers/libshut.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/libshut.c b/drivers/libshut.c index 8d8991613d..7a9f78bd34 100644 --- a/drivers/libshut.c +++ b/drivers/libshut.c @@ -1283,7 +1283,7 @@ static int shut_control_msg( __func__, data_size); return -1; } - if (data_size > 0x0F) { + if (data_size > 0x0F || data_size > sizeof(shut_pkt) - 2) { upsdebugx(1, "%s: WARNING: data_size %" PRI_NUT_USB_CTRL_CHARBUFSIZE " may be too large for SHUT packet?", __func__, data_size); @@ -1293,7 +1293,7 @@ static int shut_control_msg( } shut_pkt[1] = (unsigned char)(data_size<<4) + (unsigned char)data_size; if ( (requesttype == REQUEST_TYPE_SET_REPORT) && (remaining_size < 8) ) - memcpy(&shut_pkt[2], bytes, data_size); /* we need to send ctrl.data */ + memcpy(&shut_pkt[2], bytes, data_size > sizeof(shut_pkt) - 2 ? sizeof(shut_pkt) - 2 : data_size); /* we need to send ctrl.data */ else memcpy(&shut_pkt[2], &ctrl, 8); shut_pkt[(data_size+3) - 1] = shut_checksum(&shut_pkt[2], (unsigned char)data_size); From bf22026b6169d694aab0f241d2c13fa4c9e5267c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 26 Jul 2024 10:17:11 +0000 Subject: [PATCH 10/11] ci_build.sh: update suggestion about Homebrew envvar setting [#2522] Signed-off-by: Jim Klimov --- ci_build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci_build.sh b/ci_build.sh index e2e9960e4d..ca111198cc 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -1084,7 +1084,9 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp fi fi else - echo "WARNING: It seems you are building on MacOS, but HOMEBREW_PREFIX is not set or valid; it can help with auto-detection of some features!" + echo "WARNING: It seems you are building on MacOS, but HOMEBREW_PREFIX is not set or valid." + echo 'If you do use this build system, try running eval "$(brew shellenv)"' + echo "in your terminal or shell profile, it can help with auto-detection of some features!" fi ;; esac From 36763b5f502941467709403f63c801040b98e469 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 24 Jul 2024 11:01:31 +0200 Subject: [PATCH 11/11] m4/nut_check_aspell.m4: avoid "exec -- 2>&1" trick, not all shells like it Signed-off-by: Jim Klimov --- m4/nut_check_aspell.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/m4/nut_check_aspell.m4 b/m4/nut_check_aspell.m4 index dbccd27878..4515821add 100644 --- a/m4/nut_check_aspell.m4 +++ b/m4/nut_check_aspell.m4 @@ -114,7 +114,7 @@ if test -z "${nut_have_aspell_seen}"; then AS_IF([test -n "$ASPELL_FILTER_TEX_PATH" -a -d "$ASPELL_FILTER_TEX_PATH"], [ASPELL_NUT_TEXMODE_ARGS="--filter-path='${ASPELL_FILTER_TEX_PATH}' ${ASPELL_NUT_TEXMODE_ARGS}"]) ASPELL_NUT_COMMON_ARGS="-d en -a" dnl Using "eval" to handle quotes, in case of funny paths - out0="`LANG=C; LC_ALL=C; export LANG; export LC_ALL; exec -- 2>&1; set -x; echo test | eval ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS}`"; res0=$? + out0="`LANG=C; LC_ALL=C; export LANG; export LC_ALL; ( set -x; echo test | eval ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS} ) 2>&1`"; res0=$? AS_IF([test x"$res0" != x0], [ AC_MSG_NOTICE([FAILED CMD: ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS}]) AC_MSG_NOTICE([aspell result ($res0) and output: $out0]) @@ -126,7 +126,7 @@ if test -z "${nut_have_aspell_seen}"; then AC_MSG_RESULT(no) AC_MSG_CHECKING([if detected aspell configuration works with built-in paths (tweaked one finds wrong binary modules)]) ASPELL_NUT_TEXMODE_ARGS="-t" - out0="`LANG=C; LC_ALL=C; export LANG; export LC_ALL; exec -- 2>&1; set -x; echo test | eval ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS}`"; res0=$? + out0="`LANG=C; LC_ALL=C; export LANG; export LC_ALL; ( set -x; echo test | eval ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS} ) 2>&1`"; res0=$? AS_IF([test x"$res0" = x0], [ASPELL_FILTER_TEX_PATH=""], [ AC_MSG_NOTICE([FAILED CMD: ${ASPELL} ${ASPELL_NUT_TEXMODE_ARGS} ${ASPELL_NUT_COMMON_ARGS}]) AC_MSG_NOTICE([aspell result ($res0) and output: $out0])