saleyn / erlexec

Execute and control OS processes from Erlang/OTP
https://hexdocs.pm/erlexec/readme.html
Other
525 stars 139 forks source link

Mac OS error: use of undeclared identifier 'pipe2' #153

Closed mattste closed 2 years ago

mattste commented 2 years ago

I'm running into an error when compiling the latest erlexec on master.

Error Message

 mix deps.compile erlexec
===> Compiling app/deps/erlexec/c_src/exec.cpp
===> app/deps/erlexec/c_src/exec.cpp:197:9: error: use of undeclared identifier 'pipe2'
    if (pipe2(sigchld_pipe, O_CLOEXEC) < 0) {
        ^
1 error generated.

** (Mix) Could not compile dependency :erlexec, "/Users/mattste/.asdf/installs/elixir/1.12.3-otp-23/.mix/rebar3 bare compile --paths /app/_build/dev/lib/*/ebin" command failed. You can recompile this dependency with "mix deps.compile erlexec", update it with "mix deps.update erlexec" or clean it with "mix deps.clean erlexec"

Possible Fix

This appears to be caused by the transition to pipe2 in https://github.com/saleyn/erlexec/commit/95a654be22a3c2aa6ba9daa7b5e4f041a5d0b9e9. It appears pipe2 is not available on Mac OS. Perhaps we could fallback to pipe when pipe2 is not available? Another project ran into this issue.

System Information

Operating System: macOS Big Sur version 11.5.2 (20G95)

saleyn commented 2 years ago

@mattste, could you check the latest commit? I implemented fallback to pipe(2) for MacOS, but don't have a Mac to test it on.

ewildgoose commented 2 years ago

It fails on my mac with:

===> Compiling /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/c_src/exec.cpp
===> /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/c_src/exec.cpp:211:10: error: no matching function for call to 'set_cloexec_flag'
    if (!set_cloexec_flag(sigchld_pipe, true)) {
         ^~~~~~~~~~~~~~~~
c_src/exec.hpp:370:9: note: candidate function not viable: no known conversion from 'int [2]' to 'int' for 1st argument
bool    set_cloexec_flag(int fd, bool value);
        ^
1 error generated.