From a0137feb7179faa6760ba3dc45c4753dfa5ddf9a Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 07:58:05 -0800 Subject: [PATCH 01/10] use portable _POSIX_HOST_NAME_MAX Problem: HOST_NAME_MAX is not defined on macos. Convert HOST_NAME_MAX and MAXHOSTNAMELEN to _POSIX_HOST_NAME_MAX which appears to be the most portable option. --- src/broker/boot_pmi.c | 4 ++-- src/broker/broker.h | 4 ++-- src/cmd/builtin/relay.c | 4 ++-- src/common/libhostlist/hostlist.c | 6 ------ src/common/libhostlist/hostrange.c | 13 +++---------- src/common/libutil/ipaddr.c | 4 ++-- src/common/libutil/test/getaddr.c | 4 ++-- src/common/libutil/test/ipaddr.c | 4 ++-- src/shell/internal.h | 4 ++-- 9 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/broker/boot_pmi.c b/src/broker/boot_pmi.c index 075ab6f6a2ae..0ea01f0556dd 100644 --- a/src/broker/boot_pmi.c +++ b/src/broker/boot_pmi.c @@ -11,7 +11,7 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include #include @@ -164,7 +164,7 @@ static int format_bind_uri (char *buf, int bufsz, attr_t *attrs, int rank) goto overflow; } else { - char ipaddr[HOST_NAME_MAX + 1]; + char ipaddr[_POSIX_HOST_NAME_MAX + 1]; flux_error_t error; int flags = 0; const char *interface = NULL; diff --git a/src/broker/broker.h b/src/broker/broker.h index 351b9c6c1065..c51c91e9442f 100644 --- a/src/broker/broker.h +++ b/src/broker/broker.h @@ -11,7 +11,7 @@ #ifndef _BROKER_H #define _BROKER_H -#include +#include #include #include "src/common/libczmqcontainers/czmq_containers.h" @@ -23,7 +23,7 @@ struct broker { flux_watcher_t *w_internal; flux_reactor_t *reactor; optparse_t *opts; - char hostname[MAXHOSTNAMELEN + 1]; + char hostname[_POSIX_HOST_NAME_MAX + 1]; struct overlay *overlay; uint32_t rank; diff --git a/src/cmd/builtin/relay.c b/src/cmd/builtin/relay.c index cdeb62e373ac..fd5e8fc99803 100644 --- a/src/cmd/builtin/relay.c +++ b/src/cmd/builtin/relay.c @@ -36,7 +36,7 @@ #include "builtin.h" #include #include -#include +#include #include #include #include @@ -131,7 +131,7 @@ static int cmd_relay (optparse_t *p, int ac, char *av[]) flux_t *h; int optindex; char *uri; - char hostname [HOST_NAME_MAX + 1]; + char hostname [_POSIX_HOST_NAME_MAX + 1]; /* If possible, initialize logging prefix as local hostname. (In the * unlikely event gethostname(3) fails, use "unknown-host".) diff --git a/src/common/libhostlist/hostlist.c b/src/common/libhostlist/hostlist.c index b05372fd4805..d2acba4f3517 100644 --- a/src/common/libhostlist/hostlist.c +++ b/src/common/libhostlist/hostlist.c @@ -41,12 +41,6 @@ /* max number of ranges that will be processed between brackets */ #define MAX_RANGES 10240 /* 10K Ranges */ -/* size of internal hostname buffer (+ some slop), hostnames will probably - * be truncated if longer than MAXHOSTNAMELEN */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 -#endif - /* max size of internal hostrange buffer */ #define MAXHOSTRANGELEN 1024 diff --git a/src/common/libhostlist/hostrange.c b/src/common/libhostlist/hostrange.c index 93b1c1ac8760..e362f24cf63e 100644 --- a/src/common/libhostlist/hostrange.c +++ b/src/common/libhostlist/hostrange.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -31,13 +31,6 @@ /* max number of ranges that will be processed between brackets */ #define MAX_RANGES 10240 /* 10K Ranges */ -/* size of internal hostname buffer (+ some slop), hostnames will probably - * be truncated if longer than MAXHOSTNAMELEN - */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 -#endif - /* max size of internal hostrange buffer */ #define MAXHOSTRANGELEN 1024 @@ -457,7 +450,7 @@ size_t hostrange_numstr (struct hostrange * hr, size_t n, char *buf) char * hostrange_host_tostring (struct hostrange * hr, int depth) { - char buf[MAXHOSTNAMELEN + 16]; + char buf[_POSIX_HOST_NAME_MAX + 16]; int len; if (!hr || depth < 0) { @@ -475,7 +468,7 @@ char * hostrange_host_tostring (struct hostrange * hr, int depth) errno = ERANGE; return NULL; } - snprintf (buf+len, MAXHOSTNAMELEN+15 - len, "%0*lu", + snprintf (buf+len, sizeof (buf) - len, "%0*lu", hr->width, hr->lo + depth); } return strdup (buf); diff --git a/src/common/libutil/ipaddr.c b/src/common/libutil/ipaddr.c index e2efe7e11b72..a71c7f582956 100644 --- a/src/common/libutil/ipaddr.c +++ b/src/common/libutil/ipaddr.c @@ -11,7 +11,7 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include #include @@ -178,7 +178,7 @@ static int getprimary_hostaddr (char *buf, int prefer_family, flux_error_t *error) { - char hostname[HOST_NAME_MAX + 1]; + char hostname[_POSIX_HOST_NAME_MAX + 1]; struct addrinfo hints, *res = NULL; struct addrinfo *rp; int e; diff --git a/src/common/libutil/test/getaddr.c b/src/common/libutil/test/getaddr.c index 7c364895902d..a307dff43ff0 100644 --- a/src/common/libutil/test/getaddr.c +++ b/src/common/libutil/test/getaddr.c @@ -11,7 +11,7 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include "src/common/libutil/ipaddr.h" @@ -20,7 +20,7 @@ int main(int argc, char** argv) { - char buf[MAXHOSTNAMELEN + 1]; + char buf[_POSIX_HOST_NAME_MAX + 1]; flux_error_t error; char *name = getenv ("FLUX_IPADDR_INTERFACE"); int flags = 0; diff --git a/src/common/libutil/test/ipaddr.c b/src/common/libutil/test/ipaddr.c index 59b5671372f4..f90138a0429d 100644 --- a/src/common/libutil/test/ipaddr.c +++ b/src/common/libutil/test/ipaddr.c @@ -11,7 +11,7 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include "src/common/libtap/tap.h" @@ -20,7 +20,7 @@ int main(int argc, char** argv) { - char host[MAXHOSTNAMELEN + 1]; + char host[_POSIX_HOST_NAME_MAX + 1]; flux_error_t error; int n; diff --git a/src/shell/internal.h b/src/shell/internal.h index 01be0140c16b..2ac7356e1781 100644 --- a/src/shell/internal.h +++ b/src/shell/internal.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "src/common/libutil/aux.h" #include "src/common/libczmqcontainers/czmq_containers.h" @@ -27,7 +27,7 @@ struct flux_shell { flux_jobid_t jobid; int broker_rank; uid_t broker_owner; - char hostname [MAXHOSTNAMELEN + 1]; + char hostname [_POSIX_HOST_NAME_MAX + 1]; int protocol_fd[2]; optparse_t *p; From 27c18cb0daba7b60632ff47abbbb1bf643507b2f Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 08:08:08 -0800 Subject: [PATCH 02/10] handle missing link.h Problem: link.h is missing (or hard to find) on macos. Just skip the dlinfo() call if link.h is missing and log "unknown" for the library name in the PMI client. --- configure.ac | 1 + src/common/libpmi/upmi_libpmi.c | 16 +++++++++------- src/common/libpmi/upmi_libpmi2.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 7d3f297c687b..246abfaec129 100644 --- a/configure.ac +++ b/configure.ac @@ -187,6 +187,7 @@ AC_CHECK_HEADERS( \ xlocale.h \ endian.h \ inttypes.h \ + link.h \ ) ## diff --git a/src/common/libpmi/upmi_libpmi.c b/src/common/libpmi/upmi_libpmi.c index 64782ff4d8fe..a699eb501ae3 100644 --- a/src/common/libpmi/upmi_libpmi.c +++ b/src/common/libpmi/upmi_libpmi.c @@ -14,7 +14,9 @@ #include #include #include +#if HAVE_LINK_H #include +#endif #include "src/common/libutil/errprintf.h" #include "ccan/array_size/array_size.h" @@ -46,10 +48,13 @@ static const char *plugin_name = "libpmi"; static const char *dlinfo_name (void *dso) { - struct link_map *p; - if (dlinfo (dso, RTLD_DI_LINKMAP, &p) < 0) - return NULL; - return p->l_name; +#if HAVE_LINK_H + struct link_map *p = NULL; + (void)dlinfo (dso, RTLD_DI_LINKMAP, &p); + if (p && p->l_name) + return p->l_name; +#endif + return "unknown"; } static int dlopen_wrap (const char *path, @@ -304,9 +309,6 @@ static int op_preinit (flux_plugin_t *p, int spawned; const char *name = dlinfo_name (ctx->dso); - if (!name) - name = "unknown"; - result = ctx->init (&spawned); if (result != PMI_SUCCESS) goto error; diff --git a/src/common/libpmi/upmi_libpmi2.c b/src/common/libpmi/upmi_libpmi2.c index e160746dccfc..81502a9956ee 100644 --- a/src/common/libpmi/upmi_libpmi2.c +++ b/src/common/libpmi/upmi_libpmi2.c @@ -14,7 +14,9 @@ #include #include #include +#if HAVE_LINK_H #include +#endif #include "src/common/libutil/errprintf.h" #include "src/common/libutil/errno_safe.h" @@ -58,10 +60,13 @@ static const char *plugin_name = "libpmi2"; static const char *dlinfo_name (void *dso) { - struct link_map *p; - if (dlinfo (dso, RTLD_DI_LINKMAP, &p) < 0) - return NULL; - return p->l_name; +#if HAVE_LINK_H + struct link_map *p = NULL; + (void)dlinfo (dso, RTLD_DI_LINKMAP, &p); + if (p && p->l_name) + return p->l_name; +#endif + return "unknown"; } static int dlopen_wrap (const char *path, @@ -413,9 +418,6 @@ static int op_preinit (flux_plugin_t *p, int result; const char *name = dlinfo_name (ctx->dso); - if (!name) - name = "unknown"; - result = ctx->init (&spawned, &ctx->size, &ctx->rank, &appnum); if (result != PMI2_SUCCESS) goto error; From 655c325e6e1e8aef23e693a89af61a39e3c812c7 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 08:45:59 -0800 Subject: [PATCH 03/10] libutil: fix compile warnings in fdwalk on non-linux Problem: fdwalk build fails on macos Move unused variables/functions inside #ifdef __linux__ to avoid warnings that are fatal to the build. --- src/common/libutil/fdwalk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/libutil/fdwalk.c b/src/common/libutil/fdwalk.c index 735f22d37de8..78a77ce8c6ab 100644 --- a/src/common/libutil/fdwalk.c +++ b/src/common/libutil/fdwalk.c @@ -93,6 +93,7 @@ struct linux_dirent64 #include "fdwalk.h" +#ifdef __linux__ // Parses a file descriptor number in base 10, requiring the strict format used // in /proc/*/fd. Returns the value, or -1 if not a valid string. static int parse_fd(const char *s) { @@ -111,6 +112,7 @@ static int parse_fd(const char *s) { } while (*s); return val; } +#endif /* __linux__ */ int _fdwalk_portable (void (*func)(void *, int), void *data) { @@ -121,15 +123,16 @@ int _fdwalk_portable (void (*func)(void *, int), void *data) } -int fdwalk (void (*func)(void *, int), void *data) { - int fd; - int rc = 0; +int fdwalk (void (*func)(void *, int), void *data){ /* On Linux use getdents64 to avoid malloc in opendir() and * still walk only open fds. If not on linux or open() of /proc/self * fails, fall back to iterating over all possible fds. */ #ifdef __linux__ + int fd; + int rc = 0; + int dir_fd = open ("/proc/self/fd", O_RDONLY | O_DIRECTORY); if (dir_fd >= 0) { char buf [4096]; From b55b7356fef5e1ed10dccf83bd931c184ced70e5 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 09:10:56 -0800 Subject: [PATCH 04/10] libmissing: add pipe2 Problem: pipe2() is missing on macos. Proide a substitute implementation if missing. --- configure.ac | 1 + src/common/libmissing/Makefile.am | 3 +- src/common/libmissing/pipe2.c | 46 ++++++++++++++++++++++++++++++ src/common/libmissing/pipe2.h | 16 +++++++++++ src/common/librouter/test/sendfd.c | 4 +++ src/common/libutil/popen2.c | 3 ++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/common/libmissing/pipe2.c create mode 100644 src/common/libmissing/pipe2.h diff --git a/configure.ac b/configure.ac index 246abfaec129..573d3a5b7f1e 100644 --- a/configure.ac +++ b/configure.ac @@ -233,6 +233,7 @@ AC_REPLACE_FUNCS( \ argz_add \ envz_add \ strerrorname_np \ + pipe2 \ ) X_AC_CHECK_PTHREADS X_AC_CHECK_COND_LIB(rt, clock_gettime) diff --git a/src/common/libmissing/Makefile.am b/src/common/libmissing/Makefile.am index 2e084802baad..b9b6a7ae3049 100644 --- a/src/common/libmissing/Makefile.am +++ b/src/common/libmissing/Makefile.am @@ -50,4 +50,5 @@ EXTRA_libmissing_la_SOURCES = \ envz.c \ macros.h \ strerrorname_np.h \ - json_object_update_recursive.h + json_object_update_recursive.h \ + pipe2.h diff --git a/src/common/libmissing/pipe2.c b/src/common/libmissing/pipe2.c new file mode 100644 index 000000000000..a38057eb6db3 --- /dev/null +++ b/src/common/libmissing/pipe2.c @@ -0,0 +1,46 @@ +/************************************************************\ + * Copyright 2024 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include + +#include "pipe2.h" + +static int setflags (int fd, int flags) +{ + int oflags; + if ((oflags = fcntl (fd, F_GETFL)) < 0 + || fcntl (fd, F_SETFL, oflags | flags) < 0) + return -1; + return 0; +} + +int pipe2 (int pipefd[2], int flags) +{ + int pfd[2]; + if (pipe (pfd) < 0) + return -1; + if (setflags (pfd[0], flags) < 0 || setflags (pfd[1], flags) < 0) { + int saved_errno = errno; + (void)close (pfd[0]); + (void)close (pfd[1]); + errno = saved_errno; + return -1; + } + pipefd[0] = pfd[0]; + pipefd[1] = pfd[1]; + return 0; +} + +// vi:ts=4 sw=4 expandtab diff --git a/src/common/libmissing/pipe2.h b/src/common/libmissing/pipe2.h new file mode 100644 index 000000000000..4c9c346fb710 --- /dev/null +++ b/src/common/libmissing/pipe2.h @@ -0,0 +1,16 @@ +/************************************************************\ + * Copyright 2024 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#ifndef _PIPE2_H +#define _PIPE2_H 1 + +int pipe2 (int pipefd[2], int flags); + +#endif // !_PIPE2_H diff --git a/src/common/librouter/test/sendfd.c b/src/common/librouter/test/sendfd.c index bd5b571a9830..d74e53822781 100644 --- a/src/common/librouter/test/sendfd.c +++ b/src/common/librouter/test/sendfd.c @@ -15,6 +15,10 @@ #include #include #include +#ifndef HAVE_PIPE2 +#include "src/common/libmissing/pipe2.h" +#endif + #include diff --git a/src/common/libutil/popen2.c b/src/common/libutil/popen2.c index 02c20a61e67f..e58cbddf7bf6 100644 --- a/src/common/libutil/popen2.c +++ b/src/common/libutil/popen2.c @@ -22,6 +22,9 @@ #include #include #include +#ifndef HAVE_PIPE2 +#include "src/common/libmissing/pipe2.h" +#endif #include "popen2.h" #include "fdwalk.h" From d5b0ece9e5c23491ad6af2051bf121e9896ff892 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 09:23:02 -0800 Subject: [PATCH 05/10] libmissing: add mempcpy Problem: mempcpy() is missing on macos. Proide a substitute implementation if missing. Update users. --- configure.ac | 1 + src/common/libmissing/Makefile.am | 3 ++- src/common/libmissing/argz.c | 4 +++- src/common/libmissing/mempcpy.c | 24 ++++++++++++++++++++++++ src/common/libmissing/mempcpy.h | 16 ++++++++++++++++ src/common/liboptparse/getopt.c | 4 ++++ 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/common/libmissing/mempcpy.c create mode 100644 src/common/libmissing/mempcpy.h diff --git a/configure.ac b/configure.ac index 573d3a5b7f1e..ddb17dba2d42 100644 --- a/configure.ac +++ b/configure.ac @@ -234,6 +234,7 @@ AC_REPLACE_FUNCS( \ envz_add \ strerrorname_np \ pipe2 \ + mempcpy \ ) X_AC_CHECK_PTHREADS X_AC_CHECK_COND_LIB(rt, clock_gettime) diff --git a/src/common/libmissing/Makefile.am b/src/common/libmissing/Makefile.am index b9b6a7ae3049..58a8920936c8 100644 --- a/src/common/libmissing/Makefile.am +++ b/src/common/libmissing/Makefile.am @@ -51,4 +51,5 @@ EXTRA_libmissing_la_SOURCES = \ macros.h \ strerrorname_np.h \ json_object_update_recursive.h \ - pipe2.h + pipe2.h \ + mempcpy.h diff --git a/src/common/libmissing/argz.c b/src/common/libmissing/argz.c index c2b6307276f7..1b340a508ca9 100644 --- a/src/common/libmissing/argz.c +++ b/src/common/libmissing/argz.c @@ -22,7 +22,9 @@ #include #include #include - +#ifndef HAVE_MEMPCPY +#include "mempcpy.h" +#endif /* Add BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ diff --git a/src/common/libmissing/mempcpy.c b/src/common/libmissing/mempcpy.c new file mode 100644 index 000000000000..6f140c880687 --- /dev/null +++ b/src/common/libmissing/mempcpy.c @@ -0,0 +1,24 @@ +/************************************************************\ + * Copyright 2024 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include + +#include "mempcpy.h" + +void *mempcpy (void *dest, const void *src, size_t len) +{ + return memcpy (dest, src, len) + len; +} + +// vi:ts=4 sw=4 expandtab diff --git a/src/common/libmissing/mempcpy.h b/src/common/libmissing/mempcpy.h new file mode 100644 index 000000000000..ef5f260e214b --- /dev/null +++ b/src/common/libmissing/mempcpy.h @@ -0,0 +1,16 @@ +/************************************************************\ + * Copyright 2024 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#ifndef _MEMPCPY_H +#define _MEMPCPY_H 1 + +void *mempcpy (void *dest, const void *src, size_t len); + +#endif // !_MEMPCPY diff --git a/src/common/liboptparse/getopt.c b/src/common/liboptparse/getopt.c index ea8a897afb9c..8c236406fb24 100644 --- a/src/common/liboptparse/getopt.c +++ b/src/common/liboptparse/getopt.c @@ -65,6 +65,10 @@ #include +#ifndef HAVE_MEMPCPY +#include "src/common/libmissing/mempcpy.h" +#endif + #ifdef VMS # include #endif From 7bf3bb3394e500cbd20bb182edc730a7507bb7ef Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 09:28:19 -0800 Subject: [PATCH 06/10] build: add missing JANSSON_CFLAGS Problem: compilation of libutil fails due to missing jansson headers. Add $(JANSSON_CFLAGS) to AM_CPPFLAGS. --- src/common/libutil/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/libutil/Makefile.am b/src/common/libutil/Makefile.am index 3c01d4527d14..c06b71112d7e 100644 --- a/src/common/libutil/Makefile.am +++ b/src/common/libutil/Makefile.am @@ -13,7 +13,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/common/libccan \ -I$(top_builddir)/src/common/libflux \ - -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\" + -DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\" \ + $(JANSSON_CFLAGS) noinst_LTLIBRARIES = libutil.la From 645ee7dabbacd533599e07218b36a3902fd087e3 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 09:31:11 -0800 Subject: [PATCH 07/10] libutil: fix sigutil portability issues Problem: compilation of sigutil fails on macos. Conditionally use non-portable signal defines. Rename internal function that conflicts with a ctypes.h one. --- src/common/libutil/sigutil.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/libutil/sigutil.c b/src/common/libutil/sigutil.c index 4d1c7554127a..5c05b9379a0b 100644 --- a/src/common/libutil/sigutil.c +++ b/src/common/libutil/sigutil.c @@ -55,7 +55,9 @@ static const struct signal_info signals[] = { SIGDEF(SIGPIPE), SIGDEF(SIGALRM), SIGDEF(SIGTERM), +#ifdef SIGSTKFLT SIGDEF(SIGSTKFLT), +#endif SIGDEF(SIGCHLD), SIGDEF(SIGCONT), SIGDEF(SIGSTOP), @@ -69,11 +71,13 @@ static const struct signal_info signals[] = { SIGDEF(SIGPROF), SIGDEF(SIGWINCH), SIGDEF(SIGIO), +#ifdef SIGPWR SIGDEF(SIGPWR), +#endif SIGDEF(SIGSYS), }; -static bool isnumber (const char *s, int *result) +static bool strisnumber (const char *s, int *result) { char *endptr; long int l; @@ -94,7 +98,7 @@ int sigutil_signum (const char *s) errno = EINVAL; return -1; } - if (isnumber (s, &signum)) { + if (strisnumber (s, &signum)) { if (signum <= 0) { errno = EINVAL; return -1; From ec9d92d36d5bd360d823296149c619f40cba76a7 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 10:44:32 -0800 Subject: [PATCH 08/10] Use EDEADLK when EDEADLOCK is unavailable Problem: EDEADLOCK is not defined on macos or other BSD systems. Substitute EDEADLK if undefined. Update flux_future_get(3) man page. --- doc/man3/flux_future_get.rst | 2 +- doc/test/spell.en.pws | 2 ++ src/common/libflux/future.c | 4 ++++ src/common/libflux/test/future.c | 4 ++++ src/common/libkvs/test/kvs_checkpoint.c | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/man3/flux_future_get.rst b/doc/man3/flux_future_get.rst index 2a4235c6057a..9253fe9fd047 100644 --- a/doc/man3/flux_future_get.rst +++ b/doc/man3/flux_future_get.rst @@ -118,7 +118,7 @@ ETIMEDOUT A timeout passed to :func:`flux_future_wait_for` expired before the future was fulfilled. -EDEADLOCK +EDEADLOCK (or EDEADLK on BSD systems) :func:`flux_future_wait_for` would likely deadlock due to an improperly initialized future. diff --git a/doc/test/spell.en.pws b/doc/test/spell.en.pws index 16a0edb5da66..ef391019f256 100644 --- a/doc/test/spell.en.pws +++ b/doc/test/spell.en.pws @@ -625,6 +625,8 @@ gc tgz tmpfiles EDEADLOCK +EDEADLK +BSD setpgrp nosetpgrp checkpointed diff --git a/src/common/libflux/future.c b/src/common/libflux/future.c index f4c9e8b01201..78d65cdf06d6 100644 --- a/src/common/libflux/future.c +++ b/src/common/libflux/future.c @@ -18,6 +18,10 @@ #include #include +#ifndef EDEADLOCK +#define EDEADLOCK EDEADLK +#endif + #include "src/common/libczmqcontainers/czmq_containers.h" #include "src/common/libutil/aux.h" diff --git a/src/common/libflux/test/future.c b/src/common/libflux/test/future.c index 8ee0206d3f7d..3d01b624e2f8 100644 --- a/src/common/libflux/test/future.c +++ b/src/common/libflux/test/future.c @@ -16,6 +16,10 @@ #include #include +#ifndef EDEADLOCK +#define EDEADLOCK EDEADLK +#endif + #include "src/common/libczmqcontainers/czmq_containers.h" #include "src/common/libutil/xzmalloc.h" #include "src/common/libtap/tap.h" diff --git a/src/common/libkvs/test/kvs_checkpoint.c b/src/common/libkvs/test/kvs_checkpoint.c index 5bdc4630bf9f..d4a975d522f7 100644 --- a/src/common/libkvs/test/kvs_checkpoint.c +++ b/src/common/libkvs/test/kvs_checkpoint.c @@ -16,6 +16,10 @@ #include #include +#ifndef EDEADLOCK +#define EDEADLOCK EDEADLK +#endif + #include "src/common/libtap/tap.h" #include "kvs_checkpoint.h" From 7a358f9f78827e1a5b29590a04da96aef9216062 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 10:40:59 -0800 Subject: [PATCH 09/10] build: handle epoll() via libepoll-shim Problem: macos does not support epoll() Look for epoll() in libepoll-shim. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index ddb17dba2d42..a049a81e0393 100644 --- a/configure.ac +++ b/configure.ac @@ -241,6 +241,7 @@ X_AC_CHECK_COND_LIB(rt, clock_gettime) X_AC_CHECK_COND_LIB(dl, dlerror) X_AC_MALLOC AC_CHECK_LIB(m, floor) +AC_SEARCH_LIBS(epoll, libepoll-shim) AC_ARG_ENABLE([docs], AS_HELP_STRING([--disable-docs], [disable building docs])) From 6e3bc875f7518c80f22d8767b8f05bca42381072 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 21 Nov 2024 08:31:59 -0800 Subject: [PATCH 10/10] build: add scripts for macos Problem: building flux on macos is a bit finicky. Add scripts to install dependencies and run configure in the required environment. --- Makefile.am | 4 +++- scripts/configure-macos.sh | 29 ++++++++++++++++++++++++++ scripts/install-deps-macos.sh | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100755 scripts/configure-macos.sh create mode 100755 scripts/install-deps-macos.sh diff --git a/Makefile.am b/Makefile.am index 71f2f79cfcb8..361e819f8e7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,9 @@ EXTRA_DIST = \ NEWS.md \ scripts/requirements-dev.txt \ scripts/install-deps-deb.sh \ - scripts/install-deps-rpm.sh + scripts/install-deps-rpm.sh \ + scripts/install-deps-macos.sh \ + scripts/configure-macos.sh ACLOCAL_AMFLAGS = -I config diff --git a/scripts/configure-macos.sh b/scripts/configure-macos.sh new file mode 100755 index 000000000000..3fde1e3ea0ce --- /dev/null +++ b/scripts/configure-macos.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +die() { + echo "$(basename $0): $@" >&2 + exit 1 +} + +DEPS_SCRIPT=scripts/install-deps-macos.sh + +test -f $DEPS_SCRIPT || die "please run from the top level of the source tree" +test -d macos-venv || die "please run $DEPS_SCRIPT first" + +eval "$(/opt/homebrew/bin/brew shellenv)" + +CPPFLAGS=-I${HOMEBREW_PREFIX}/include/lua +CPPFLAGS="-I$(brew --prefix epoll-shim)/include/libepoll-shim ${CPPFLAGS}" +LDFLAGS=-L${HOMEBREW_PREFIX}/lib + +PKG_CONFIG_PATH=$(pkg-config --variable pc_path pkg-config) +PKG_CONFIG_PATH=$(brew --prefix libarchive)/lib/pkgconfig:${PKG_CONFIG_PATH} + +PATH=$(brew --prefix libtool)/libexec/gnubin:$PATH + +source macos-venv/bin/activate + +./autogen.sh + +CPPFLAGS=$CPPFLAGS LDFLAGS=$LDFLAGS PKG_CONFIG_PATH=$PKG_CONFIG_PATH \ + ./configure diff --git a/scripts/install-deps-macos.sh b/scripts/install-deps-macos.sh new file mode 100755 index 000000000000..b7b4262d3562 --- /dev/null +++ b/scripts/install-deps-macos.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +die() { + echo "$(basename $0): $@" >&2 + exit 1 +} + +test -f scripts/requirements-dev.txt || die "Please run from top of source tree" + +eval "$(/opt/homebrew/bin/brew shellenv)" + +brew install \ + autoconf \ + automake \ + libtool \ + make \ + pkg-config \ + epoll-shim \ + zeromq \ + jansson \ + lz4 \ + libarchive \ + hwloc \ + sqlite \ + lua@5.3 \ + python3 \ + cffi \ + libyaml \ + jq + +brew link lua@5.3 + +python3 -m venv macos-venv +source macos-venv/bin/activate + +pip3 install setuptools +pip3 install -r scripts/requirements-dev.txt + +echo "Now run scripts/configure-macos.sh"