Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix macos portability issues (second batch) #6468

Merged
merged 10 commits into from
Dec 4, 2024

Conversation

garlick
Copy link
Member

@garlick garlick commented Dec 3, 2024

Problem: flux doesn't build on macos

This resolves a few portability issues, though it is not sufficient to get Flux working.

I have more fixes to post but some unexplained test failures to run down. I thought it might be best to post the first chunk and get that reviewed while I debug then next one.

@garlick garlick changed the title improve portability to macos fix macos portability issues (second batch) Dec 3, 2024
@@ -564,6 +564,12 @@ struct signalfd_siginfo
# endif
#endif

/* disable timerfd on macos */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit message typo "diable"

Comment on lines 128 to 134
#ifdef RUSAGE_THREAD
int who = RUSAGE_THREAD;
#else
int who = RUSAGE_SELF;
#endif
if (flux_request_decode (msg, NULL, NULL) < 0
|| getrusage (RUSAGE_THREAD, &ru) < 0)
|| getrusage (who, &ru) < 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Would it better to return an error instead of using RUSAGE_SELF? B/c the wrong data would probably be returned.

Or perhaps there should be a RUSAGE_THREAD and RUSAGE_SELF variant. SELF for the broker usage (which I guess includes all modules) and RUSAGE_THREAD for the module threads, and the RUSAGE_THREAD one doesn't work if RUSAGE_THREAD not supported. This could be for a different issue/PR of course.

Copy link
Member Author

@garlick garlick Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I hate to complicate this since it's not used much, but I think your idea of a variant (or passing a flag) makes the most sense. Then when a variant/flag is not supported, it could return an appropriate error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I just pushed a change that adds an optional who key to the RPC. The default is to use RUSAGE_SELF but the other who values can be requested. Then I changed flux module stats --rusage to work as follows

$ flux module stats --rusage=[self|children|thread]

so there is now an optional argument. This is now documented it in flux-module(1).

On systems where RUSAGE_THREAD is unsupported, you'll get an error like this:

$ flux module stats --rusage=thread connector-local
flux-module: connector-local.rusage: thread is unsupported

Since this is little used and the documentation before this was ambiguous, I think this change is probably not disruptive to anything.

Copy link
Member

@chu11 chu11 Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, maybe wanna split off those 4 commits to a separate PR since it is more than just a simple portability fix at this point.

@garlick garlick force-pushed the macos2 branch 2 times, most recently from 0a0b12b to ebab9b5 Compare December 3, 2024 20:47
@garlick
Copy link
Member Author

garlick commented Dec 3, 2024

Sorry, noticed a typo in the rusage service side and forced a push.

@garlick
Copy link
Member Author

garlick commented Dec 3, 2024

@chu11 I think this is ready for a final review if you have a moment.

Copy link
Member

@chu11 chu11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only comment is we should split out the rusage changes into a new PR, since it is a feature change and not just simple portability fixes.

@garlick
Copy link
Member Author

garlick commented Dec 3, 2024

Good point, thanks. OK, I split that out and I'll set MWP here.

Problem: macos build fails with struct itimerspec undefined.

Disable timerfd on macos to avoid requiring this in libev.
Problem: compilation fails in various places on macos due to
homebrew installing headers in a non-standard location.

Fix AM_CPPFLAGS where needed.
Problem: compilation fails on macos when %ju or %jd is used with
non-matching integer types.

Cast them to [u]intmax_t.
Problem: some function prototypes that are not used outside of GNU C
are not fully specified, so compilation fails on macos.

Add full specs.
Problem: envz.h includes features.h and malloc.h but those don't
exist on macos.

Drop features.h and replace malloc.h wtih stdlib.h.
Problem: compilation fails on macos with 'environ' undefined.

Just define it locally where needed.
Problem: compilation fails in various places on macos due to
undefined kill(2) and killpg(2).

Include signal.h where needed.
Problem: compilation fails on macos in various places because
SOCK_CLOEXEC is not defined.

Set SO_CLOEXEC with fcntl(2) after socket creation if SOCK_CLOEXEC
is undefined.
Problem: SO_PEERCRED is not defined on macos so compilation fails.

Borrowing from the munge project, implement unix socket authentication
using LOCAL_PEERCRED instead, if defined.

If neither is defined, throw a preprocessor error.

See also:
https://github.com/dun/munge/blob/master/src/munged/auth_recv.c#L315
Problem: KVS module does not compile on macos because EBADE is not
a valid signal name there.

Use EINVAL if EBADE is undefined.
@mergify mergify bot merged commit 27de281 into flux-framework:master Dec 4, 2024
33 of 34 checks passed
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.61%. Comparing base (435756d) to head (9161298).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
src/modules/cron/cron.c 60.00% 4 Missing ⚠️
src/common/libsubprocess/subprocess.c 75.00% 1 Missing ⚠️
src/modules/cron/datetime.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6468      +/-   ##
==========================================
- Coverage   83.62%   83.61%   -0.01%     
==========================================
  Files         523      523              
  Lines       87590    87600      +10     
==========================================
+ Hits        73243    73247       +4     
- Misses      14347    14353       +6     
Files with missing lines Coverage Δ
src/cmd/builtin/proxy.c 78.92% <ø> (ø)
src/cmd/flux-start.c 83.94% <ø> (ø)
src/common/libjob/kvs.c 90.90% <100.00%> (ø)
src/common/librouter/usock.c 86.81% <100.00%> (-0.04%) ⬇️
src/common/libsubprocess/fork.c 77.09% <ø> (ø)
src/common/libsubprocess/server.c 79.29% <ø> (ø)
src/common/libterminus/terminus.c 80.54% <ø> (ø)
src/modules/cron/event.c 81.70% <100.00%> (+0.22%) ⬆️
src/modules/job-info/update.c 76.82% <100.00%> (ø)
src/modules/job-ingest/job-ingest.c 70.10% <100.00%> (ø)
... and 8 more

... and 10 files with indirect coverage changes

@garlick garlick deleted the macos2 branch December 4, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants