Skip to content

Commit 27de281

Browse files
authored
Merge pull request #6468 from garlick/macos2
fix macos portability issues (second batch)
2 parents 435756d + 9161298 commit 27de281

File tree

35 files changed

+124
-30
lines changed

35 files changed

+124
-30
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ AC_CHECK_HEADERS( \
188188
endian.h \
189189
inttypes.h \
190190
link.h \
191+
[sys/ucred.h] \
191192
)
192193

193194
##

src/bindings/lua/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ AM_CPPFLAGS = \
77
-I$(top_srcdir)/src/include \
88
-I$(top_srcdir)/src/common/libccan \
99
-I$(top_builddir)/src/common/libflux \
10+
$(JANSSON_CFLAGS) \
1011
$(LUA_INCLUDE)
1112

1213
fluxluadir = $(luadir)/flux

src/bindings/python/_flux/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ AM_CPPFLAGS = \
55
-I$(top_srcdir)/src/common/libflux \
66
-I$(top_builddir)/src/common/libflux \
77
$(PYTHON_CPPFLAGS) \
8+
$(JANSSON_CFLAGS) \
89
$(CODE_COVERAGE_CPPFLAGS) \
910
$(CODE_COVERAGE_CFLAGS)
1011

src/cmd/builtin/proxy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "src/common/librouter/usock.h"
3939
#include "src/common/librouter/router.h"
4040

41+
extern char **environ;
4142

4243
struct proxy_command {
4344
struct usock_server *server;

src/cmd/flux-start.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
#define DEFAULT_EXIT_TIMEOUT 20.0
5050

51+
extern char **environ;
52+
5153
static struct {
5254
struct termios saved_termios;
5355
double exit_timeout;

src/common/libev/ev.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ struct signalfd_siginfo
564564
# endif
565565
#endif
566566

567+
/* disable timerfd on macos */
568+
#ifdef __APPLE__
569+
# undef EV_USE_TIMERFD
570+
# define EV_USE_TIMERFD 0
571+
#endif
572+
567573
/*****************************************************************************/
568574

569575
#if EV_VERIFY >= 3

src/common/libeventlog/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = libeventlog.la
1617
libeventlog_la_SOURCES = \

src/common/libfilemap/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ AM_CPPFLAGS = \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
1313
-I$(top_builddir)/src/common/libflux \
14-
$(JANSSON_CFLAGS)
14+
$(JANSSON_CFLAGS) \
15+
$(LIBARCHIVE_CFLAGS)
1516

1617
noinst_LTLIBRARIES = \
1718
libfilemap.la

src/common/libfluxutil/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = libfluxutil.la
1617
libfluxutil_la_SOURCES = \

src/common/libioencode/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = \
1617
libioencode.la

src/common/libjob/kvs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int flux_job_kvs_namespace (char *buf, int bufsz, flux_jobid_t id)
7979
int len;
8080
if (buffer_arg_check (buf, bufsz) < 0)
8181
return -1;
82-
if ((len = snprintf (buf, bufsz, "job-%ju", id)) >= bufsz) {
82+
if ((len = snprintf (buf, bufsz, "job-%ju", (uintmax_t)id)) >= bufsz) {
8383
errno = EOVERFLOW;
8484
return -1;
8585
}

src/common/libmissing/envz.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
License along with the GNU C Library; if not, see
1717
<https://www.gnu.org/licenses/>. */
1818

19-
#include <malloc.h>
19+
#include <stdlib.h>
2020
#include <string.h>
2121

2222
#include <envz.h>

src/common/libmissing/envz.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "config.h"
2424
#endif
2525

26-
#include <features.h>
27-
2826
#include <errno.h>
2927

3028
/* Envz's are argz's too, and should be created etc., using the same

src/common/liboptparse/getopt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static struct _getopt_data getopt_data;
154154
whose names are inconsistent. */
155155

156156
#ifndef getenv
157-
extern char *getenv ();
157+
extern char *getenv (const char *name);
158158
#endif
159159

160160
#endif /* not __GNU_LIBRARY__ */

src/common/liboptparse/getopt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ extern int __posix_getopt (int ___argc, char *const *___argv,
167167
# endif
168168
# endif
169169
#else /* not __GNU_LIBRARY__ */
170-
extern int getopt ();
170+
extern int getopt (int argc, char *const argv[], const char *optstring);
171171
#endif /* __GNU_LIBRARY__ */
172172

173173
#ifndef __need_getopt

src/common/libpmi/test/server_thread.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,16 @@ struct pmi_server_context *pmi_server_create (int *cfd, int size)
218218

219219
for (i = 0; i < size; i++) {
220220
int fd[2];
221+
#ifdef SOCK_CLOEXEC
221222
if (socketpair (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0)
222223
BAIL_OUT ("socketpair failed");
224+
#else
225+
if (socketpair (PF_LOCAL, SOCK_STREAM, 0, fd) < 0
226+
|| fd_set_cloexec (fd[0]) < 0
227+
|| fd_set_cloexec (fd[1]) < 0)
228+
BAIL_OUT ("socketpair failed");
229+
#endif
230+
223231
cfd[i] = fd[0];
224232
ctx->cli[i].sfd = fd[1];
225233
ctx->cli[i].rank = i;

src/common/librouter/usock.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#include <sys/un.h>
4040
#include <sys/socket.h>
4141
#include <sys/stat.h>
42+
#if HAVE_SYS_UCRED_H
43+
#include <sys/ucred.h>
44+
#endif
4245
#include <poll.h>
4346
#include <unistd.h>
4447
#include <errno.h>
@@ -387,14 +390,14 @@ void usock_server_destroy (struct usock_server *server)
387390

388391
static int usock_get_cred (int fd, struct flux_msg_cred *cred)
389392
{
390-
struct ucred ucred;
391-
socklen_t crlen;
392393

393394
if (fd < 0 || !cred) {
394395
errno = EINVAL;
395396
return -1;
396397
}
397-
crlen = sizeof (ucred);
398+
#if defined(SO_PEERCRED)
399+
struct ucred ucred;
400+
socklen_t crlen = sizeof (ucred);
398401
if (getsockopt (fd,
399402
SOL_SOCKET,
400403
SO_PEERCRED,
@@ -406,6 +409,19 @@ static int usock_get_cred (int fd, struct flux_msg_cred *cred)
406409
return -1;
407410
}
408411
cred->userid = ucred.uid;
412+
#elif defined(LOCAL_PEERCRED)
413+
struct xucred ucred;
414+
socklen_t crlen = sizeof (ucred);
415+
if (getsockopt (fd, 0, LOCAL_PEERCRED, &ucred, &crlen) < 0)
416+
return -1;
417+
if (ucred.cr_version != XUCRED_VERSION) {
418+
errno = EINVAL;
419+
return -1;
420+
}
421+
cred->userid = ucred.cr_uid;
422+
#else
423+
#error Neither SO_PEERCRED nor LOCAL_PEERCRED are defined
424+
#endif
409425
cred->rolemask = FLUX_ROLE_NONE;
410426
return 0;
411427
}
@@ -460,8 +476,17 @@ static struct usock_conn *server_accept (struct usock_server *server,
460476
struct usock_conn *conn;
461477
int cfd;
462478

479+
#ifdef SOCK_CLOEXEC
463480
if ((cfd = accept4 (server->fd, NULL, NULL, SOCK_CLOEXEC)) < 0)
464481
return NULL;
482+
#else
483+
if ((cfd = accept (server->fd, NULL, NULL)) < 0)
484+
return NULL;
485+
if (fd_set_cloexec (cfd) < 0) {
486+
ERRNO_SAFE_WRAP (close, cfd);
487+
return NULL;
488+
}
489+
#endif
465490
if (!(conn = usock_conn_create (r, cfd, cfd))
466491
|| usock_get_cred (cfd, &conn->cred) < 0) {
467492
ERRNO_SAFE_WRAP (close, cfd);
@@ -537,8 +562,14 @@ struct usock_server *usock_server_create (flux_reactor_t *r,
537562
}
538563
if (!(server = calloc (1, sizeof (*server))))
539564
return NULL;
565+
#ifdef SOCK_CLOEXEC
540566
if ((server->fd = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0)
541567
goto error;
568+
#else
569+
if ((server->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0
570+
|| fd_set_cloexec (server->fd) < 0)
571+
goto error;
572+
#endif
542573
if (!(server->sockpath = strdup (sockpath)))
543574
goto error;
544575
if (remove (sockpath) < 0 && errno != ENOENT)
@@ -688,8 +719,15 @@ int usock_client_connect (const char *sockpath,
688719
errno = EINVAL;
689720
return -1;
690721
}
722+
#ifdef SOCK_CLOEXEC
691723
if ((fd = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) < 0)
692724
return -1;
725+
#else
726+
if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
727+
return -1;
728+
if (fd_set_cloexec (fd) < 0)
729+
goto error;
730+
#endif
693731

694732
memset (&addr, 0, sizeof (addr));
695733
addr.sun_family = AF_UNIX;

src/common/libschedutil/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = \
1617
libschedutil.la

src/common/libsubprocess/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ AM_CPPFLAGS = \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
1313
-I$(top_builddir)/src/common/libflux \
14-
-DLLOG_ENABLE_DEBUG=1
14+
-DLLOG_ENABLE_DEBUG=1 \
15+
$(JANSSON_CFLAGS)
1516

1617
noinst_LTLIBRARIES = \
1718
libsubprocess.la

src/common/libsubprocess/fork.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <sys/wait.h>
1616
#include <unistd.h>
17+
#include <signal.h>
1718
#include <errno.h>
1819

1920
#include <flux/core.h>
@@ -25,6 +26,8 @@
2526
#include "subprocess_private.h"
2627
#include "command_private.h"
2728

29+
extern char **environ;
30+
2831
static int sigmask_unblock_all (void)
2932
{
3033
sigset_t mask;

src/common/libsubprocess/server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "client.h"
3232
#include "util.h"
3333

34+
extern char **environ;
35+
3436
/* Keys used to store subprocess server, exec request
3537
* (i.e. rexec.exec), and 'subprocesses' zlistx handle in the
3638
* subprocess object.

src/common/libsubprocess/subprocess.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sys/wait.h>
1818
#include <unistd.h>
1919
#include <errno.h>
20+
#include <signal.h>
2021
#include <assert.h>
2122

2223
#include <flux/core.h>
@@ -25,6 +26,7 @@
2526
#include "src/common/libutil/log.h"
2627
#include "src/common/libutil/fdwalk.h"
2728
#include "src/common/libutil/aux.h"
29+
#include "src/common/libutil/fdutils.h"
2830
#include "ccan/array_size/array_size.h"
2931
#include "ccan/str/str.h"
3032

@@ -176,8 +178,15 @@ static flux_subprocess_t *subprocess_create (
176178

177179
/* set CLOEXEC on sync_fds, so on exec(), child sync_fd is closed
178180
* and seen by parent */
181+
#if SOCK_CLOEXEC
179182
if (socketpair (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, p->sync_fds) < 0)
180183
goto error;
184+
#else
185+
if (socketpair (PF_LOCAL, SOCK_STREAM, 0, p->sync_fds) < 0
186+
|| fd_set_cloexec (p->sync_fds[0]) < 0
187+
|| fd_set_cloexec (p->sync_fds[1]) < 0)
188+
goto error;
189+
#endif
181190

182191
if (!(p->channels = zhash_new ()))
183192
goto error;

src/common/libtaskmap/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = \
1617
libtaskmap.la

src/common/libterminus/terminus.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <stdio.h>
5555
#include <errno.h>
5656
#include <string.h>
57+
#include <signal.h>
5758

5859
#include <jansson.h>
5960

src/modules/content-files/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir) \
1111
-I$(top_srcdir)/src/include \
1212
-I$(top_srcdir)/src/common/libccan \
13-
-I$(top_builddir)/src/common/libflux
13+
-I$(top_builddir)/src/common/libflux \
14+
$(JANSSON_CFLAGS)
1415

1516
noinst_LTLIBRARIES = libcontent-files.la
1617

0 commit comments

Comments
 (0)