Skip to content

unix: include <libutil.h> for openpty() on FreeBSD - #1

Open
neilpang wants to merge 1 commit into
MoarVM:1-50-0-with-ptyfrom
neilpang:freebsd-libutil-h
Open

unix: include <libutil.h> for openpty() on FreeBSD#1
neilpang wants to merge 1 commit into
MoarVM:1-50-0-with-ptyfrom
neilpang:freebsd-libutil-h

Conversation

@neilpang

Copy link
Copy Markdown

FreeBSD has no <util.h>. Its openpty(3) manual page gives the synopsis as
#include <libutil.h>, linked with "System Utilities Library (libutil, -lutil)".
The include guard here listed FreeBSD alongside the other BSDs, so every FreeBSD
build of this branch stopped at:

src/unix/process.c:45:10: fatal error: 'util.h' file not found
   45 | #include <util.h>
      |          ^~~~~~~~

/usr/include/util.h is absent on FreeBSD 13.5, 14.3 and 15.1; /usr/include/libutil.h
is present on all three.

This branch is what MoarVM pins as its 3rdparty/libuv submodule, so the effect is
that MoarVM cannot be built on any current FreeBSD. With this change it builds and
the NQP test suite passes (145 files, 13476 tests) on all three releases:
https://github.com/neilpang/MoarVM/actions/runs/30350124514

Note for the MoarVM side: openpty lives in libutil, not libc, on every FreeBSD
release checked, so MoarVM/build/setup.pm also needs util added to the FreeBSD
syslibs -- otherwise libmoar.so links with openpty unresolved and a pty spawn
fails at runtime. That is a separate change in the MoarVM repo.

FreeBSD has no <util.h>; openpty(3) is declared in <libutil.h> there. The
include guard listed FreeBSD alongside the other BSDs, so every FreeBSD
build of this branch stopped at

    src/unix/process.c:45:10: fatal error: 'util.h' file not found

Verified on FreeBSD 13.5, 14.3 and 15.1: with this change MoarVM builds
against this libuv and the NQP test suite passes (145 files, 13476 tests).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes FreeBSD builds by using the correct header for openpty(3)<libutil.h>—instead of <util.h>, aligning with FreeBSD’s documented synopsis for PTY support in src/unix/process.c.

Changes:

  • Remove __FreeBSD__ from the <util.h> include guard used for other BSDs.
  • Add a FreeBSD-specific branch to include <libutil.h>.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/unix/process.c
Comment on lines 41 to 47
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__)
#include <util.h>
#elif defined(__FreeBSD__)
#include <libutil.h>
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants