Skip to content

Commit

Permalink
Merge pull request #2096 from jimklimov/fightwarn
Browse files Browse the repository at this point in the history
A little bit of Fightwarn
  • Loading branch information
jimklimov authored Oct 11, 2023
2 parents 5dc7970 + ce37a62 commit 523a123
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 105 deletions.
36 changes: 25 additions & 11 deletions Jenkinsfile-dynamatrix
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ import org.nut.dynamatrix.*;
dynacfgPipeline.disableSlowBuildCIBuild_QEMU = false
}

dynacfgPipeline.traceBuildShell_configureEnvvars = false// true
dynacfgPipeline.traceBuildShell = false //true
dynacfgPipeline.traceBuildShell_configureEnvvars = false // true
dynacfgPipeline.traceBuildShell = false // true

//if (false) // <<< (Un-)comment away in select runs/branches
//if (true) // <<< (Un-)comment away in select runs/branches
if ( env?.BRANCH_NAME ==~ /.*fightwarn-verbose.*/ )
{
dynacfgPipeline.traceBuildShell_configureEnvvars = true // false
dynacfgPipeline.traceBuildShell = true // false
}

dynacfgPipeline.failFast = //true //
false
Expand Down Expand Up @@ -98,7 +106,7 @@ import org.nut.dynamatrix.*;
//'stageNameFunc': null,
//'dynamatrixAxesLabels': [~/^OS_.+/, 'MAKE'],
'dynamatrixAxesLabels': ['OS_FAMILY', 'OS_DISTRO', 'MAKE'],
'single': '( \${MAKE} shellcheck )',
'single': '( if [ x"\${MAKE-}" = x ]; then echo "WARNING: MAKE is somehow unset, defaulting!" >&2; MAKE=make; fi; \${MAKE} shellcheck )',
'multi': '(cd tests && SERVICE_FRAMEWORK="selftest" SHELL_PROGS="$SHELL_PROGS" ./nut-driver-enumerator-test.sh )',
'multiLabel': 'SHELL_PROGS',
'skipShells': [ 'zsh', 'tcsh', 'csh' ]
Expand Down Expand Up @@ -233,7 +241,10 @@ import org.nut.dynamatrix.*;
if (!dynacfgPipeline.containsKey('buildPhases')) {
dynacfgPipeline.buildPhases = [:]
}
dynacfgPipeline.buildPhases['distcheck'] = """( eval \${CONFIG_ENVVARS} time \${MAKE} \${MAKE_OPTS} distcheck DISTCHECK_FLAGS="\${CONFIG_OPTS}" )"""

// Imported from jenkins-dynamatrix JSL vars/autotools.groovy:
// a workaround for the cases of curiously missing MAKE envvar...
dynacfgPipeline.buildPhases['distcheck'] = """( if [ x"\${MAKE-}" = x ]; then echo "WARNING: MAKE is somehow unset, defaulting!" >&2; MAKE=make; fi; eval \${CONFIG_ENVVARS} time \${MAKE} \${MAKE_OPTS} distcheck DISTCHECK_FLAGS="\${CONFIG_OPTS}" )"""

// Note: shellcheck/spellcheck/... require autotools currently
// or need to be redefined with respective BUILD_TYPE
Expand All @@ -246,7 +257,8 @@ import org.nut.dynamatrix.*;
def dsbcClone = dsbc.clone()

stage('Investigate envvars (Autotools DEBUG)') {
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}"
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}" +
(dynacfgPipeline?.configureEnvvars ? "" : " (note: has no dynacfgPipeline.configureEnvvars)")
// Trick about endianness via ELF binary header picked up from https://serverfault.com/a/749469/490516
sh label: 'Inspect initial envvars', script: """ hostname; date -u; uname -a
echo "LONG_BIT:`getconf LONG_BIT` WORD_BIT:`getconf WORD_BIT`" || true
Expand Down Expand Up @@ -275,7 +287,8 @@ set | sort -n """
def dsbcClone = dsbc.clone()

stage('Investigate envvars (CI_Build DEBUG)') {
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}"
echo "Running default custom build for '${stageNameClone}' ==> ${dsbcClone.toString()}" +
(dynacfgPipeline?.configureEnvvars ? "" : " (note: has no dynacfgPipeline.configureEnvvars)")
// Trick about endianness via ELF binary header picked up from https://serverfault.com/a/749469/490516
sh label: 'Inspect initial envvars', script: """ hostname; date -u; uname -a
echo "LONG_BIT:`getconf LONG_BIT` WORD_BIT:`getconf WORD_BIT`" || true
Expand Down Expand Up @@ -1263,14 +1276,15 @@ def stageNameFunc_ShellcheckCustom(DynamatrixSingleBuildConfig dsbc) {

///////////////////////////////////////////////////////////////////////////

// Hacky big switch for a max debug option
if (true)
if (false)
{
// Hacky big switch for a max debug option
//if (true) // <<< (Un-)comment away in select runs/branches
//if (false) // <<< (Un-)comment away in select runs/branches
if ( env?.BRANCH_NAME ==~ /.*verbose.*/ )
{
dynamatrixGlobalState.enableDebugTrace = true
dynamatrixGlobalState.enableDebugErrors = true
dynamatrixGlobalState.enableDebugMilestones = true
dynamatrixGlobalState.enableDebugMilestonesDetails = true
}
}

dynamatrixPipeline(dynacfgBase, dynacfgPipeline)
7 changes: 7 additions & 0 deletions clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ static int upscli_sslinit(UPSCONN_t *ups, int verifycert)
return -1;
}

#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type-strict"
#endif
if (verifycert) {
status = SSL_AuthCertificateHook(ups->ssl,
(SSLAuthCertificate)AuthCertificate, CERT_GetDefaultCertDB());
Expand Down Expand Up @@ -938,6 +942,9 @@ static int upscli_sslinit(UPSCONN_t *ups, int verifycert)
nss_error("upscli_sslinit / SSL_HandshakeCallback");
return -1;
}
#if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT)
#pragma GCC diagnostic pop
#endif

cert = upscli_find_host_cert(ups->host);
if (cert != NULL && cert->certname != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ static void start_daemon(TYPE_FD lockfd)
if (d > 0 && d < 0.2) {
d = (1.0 - d) * 1000000.0;
upsdebugx(5, "Enforcing a throttling sleep: %f usec", d);
usleep(d);
usleep((useconds_t)d);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ double difftimeval(struct timeval x, struct timeval y)
result.tv_sec = x.tv_sec - y.tv_sec;
result.tv_usec = x.tv_usec - y.tv_usec;

d = 0.000001 * result.tv_usec + result.tv_sec;
d = 0.000001 * (double)(result.tv_usec) + (double)(result.tv_sec);
return d;
}

Expand Down Expand Up @@ -718,7 +718,7 @@ static usec_t timespec_load(const struct timespec *ts) {
if (ts->tv_sec < 0 || ts->tv_nsec < 0)
return USEC_INFINITY;

if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
if ((usec_t) ts->tv_sec > (UINT64_MAX - ((uint64_t)(ts->tv_nsec) / NSEC_PER_USEC)) / USEC_PER_SEC)
return USEC_INFINITY;

return
Expand Down Expand Up @@ -767,7 +767,7 @@ double difftimespec(struct timespec x, struct timespec y)
result.tv_sec = x.tv_sec - y.tv_sec;
result.tv_nsec = x.tv_nsec - y.tv_nsec;

d = 0.000000001 * result.tv_nsec + result.tv_sec;
d = 0.000000001 * (double)(result.tv_nsec) + (double)(result.tv_sec);
return d;
}
#endif /* HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC */
Expand Down Expand Up @@ -1265,7 +1265,7 @@ static void vupslog(int priority, const char *fmt, va_list va, int use_strerror)
if (((uintmax_t)ret) > (SIZE_MAX - LARGEBUF)) {
goto vupslog_too_long;
}
newbufsize = ret + LARGEBUF;
newbufsize = (size_t)ret + LARGEBUF;
} /* else: errno, e.g. ERANGE printing:
* "...(34 => Result too large)" */
if (nut_debug_level > 0) {
Expand Down
190 changes: 188 additions & 2 deletions common/wincompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
#include "wincompat.h"
#include "nut_stdint.h"

#if ! HAVE_INET_PTON
# include <string.h>
# include <ctype.h>
# if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
# if HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif
#endif

#if (0)
extern int errno;
#endif
Expand Down Expand Up @@ -204,6 +215,181 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t cnt)
}
#endif /* HAVE_INET_NTOP */

#if ! HAVE_INET_PTON
/* Fallback implementation of inet_pton() for systems that lack it,
* such as older versions of Windows (including MinGW builds that do
* not specifically target _WIN32_WINNT or newer).
*
* Based on code attributed to Paul Vixie, 1996,
* sourced from https://stackoverflow.com/a/15370175/4715872
*/

#define NS_INADDRSZ sizeof(struct in_addr) /* 4 */
#define NS_IN6ADDRSZ sizeof(struct in6_addr) /* 16 */
#define NS_INT16SZ sizeof(uint16_t) /* 2 */

static int inet_pton4(const char *src, void *dst)
{
uint8_t tmp[NS_INADDRSZ], *tp; /* for struct in_addr *dst */

int saw_digit = 0;
int octets = 0;
int ch;

*(tp = tmp) = 0;

while ((ch = *src++) != '\0')
{
if (ch >= '0' && ch <= '9')
{
uint32_t n = *tp * 10 + (ch - '0');

if (saw_digit && *tp == 0)
return 0;

if (n > 255)
return 0;

*tp = n;
if (!saw_digit)
{
if (++octets > 4)
return 0;
saw_digit = 1;
}
}
else if (ch == '.' && saw_digit)
{
if (octets == 4)
return 0;
*++tp = 0;
saw_digit = 0;
}
else
return 0;
}
if (octets < 4)
return 0;

memcpy(dst, tmp, NS_INADDRSZ);

return 1;
}

static int inet_pton6(const char *src, void *dst)
{
static const char xdigits[] = "0123456789abcdef";
uint8_t tmp[NS_IN6ADDRSZ]; /* for struct in6_addr *dst */

uint8_t *tp = (uint8_t*) memset(tmp, '\0', NS_IN6ADDRSZ);
uint8_t *endp = tp + NS_IN6ADDRSZ;
uint8_t *colonp = NULL;

const char *curtok = NULL;
int saw_xdigit = 0;
uint32_t val = 0;
int ch;

/* Leading :: requires some special handling. */
if (*src == ':')
{
if (*++src != ':')
return 0;
}

curtok = src;

while ((ch = tolower(*src++)) != '\0')
{
const char *pch = strchr(xdigits, ch);
if (pch != NULL)
{
val <<= 4;
val |= (pch - xdigits);
if (val > 0xffff)
return 0;
saw_xdigit = 1;
continue;
}
if (ch == ':')
{
curtok = src;
if (!saw_xdigit)
{
if (colonp)
return 0;
colonp = tp;
continue;
}
else if (*src == '\0')
{
return 0;
}
if (tp + NS_INT16SZ > endp)
return 0;
*tp++ = (uint8_t) (val >> 8) & 0xff;
*tp++ = (uint8_t) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
inet_pton4(curtok, (char*) tp) > 0)
{
tp += NS_INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return 0;
}
if (saw_xdigit)
{
if (tp + NS_INT16SZ > endp)
return 0;
*tp++ = (uint8_t) (val >> 8) & 0xff;
*tp++ = (uint8_t) val & 0xff;
}
if (colonp != NULL)
{
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;

if (tp == endp)
return 0;

for (i = 1; i <= n; i++)
{
endp[-i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if (tp != endp)
return 0;

memcpy(dst, tmp, NS_IN6ADDRSZ);

return 1;
}

int inet_pton(int af, const char *src, void *dst)
{
switch (af)
{
case AF_INET:
return inet_pton4(src, dst);
case AF_INET6:
return inet_pton6(src, dst);
default:
return -1;
}
}
#endif /* ! HAVE_INET_PTON */

/* "system" call seems to handle path with blank name incorrectly */
int win_system(const char * command)
{
Expand Down Expand Up @@ -1448,9 +1634,9 @@ speed_t cfgetospeed(const struct termios *t)
return t->c_ospeed;
}

#else
#else /* !WIN32 */

/* Just avoid: ISO C forbids an empty translation unit [-Werror=pedantic] */
int main (int argc, char ** argv);

#endif
#endif /* WIN32 */
Loading

0 comments on commit 523a123

Please sign in to comment.