Skip to content

Build failure on NetBSD: UT_NAMESIZE undeclared due to missing utmp.h include #135108

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

Closed
furkanonder opened this issue Jun 3, 2025 · 1 comment
Labels
build The build process and cross-build OS-netbsd type-bug An unexpected behavior, bug, or error

Comments

@furkanonder
Copy link
Contributor

furkanonder commented Jun 3, 2025

Bug report

Bug description:

CPython fails to build on NetBSD with the following error:

./Modules/posixmodule.c: In function 'os_getlogin_impl':
./Modules/posixmodule.c:9569:15: error: 'UT_NAMESIZE' undeclared (first use in this function)
 9569 |     char name[UT_NAMESIZE + 1];
      |               ^~~~~~~~~~~

Root Cause

The issue is in the header inclusion logic for PTY-related headers. The <utmp.h> header (which defines UT_NAMESIZE) is incorrectly nested inside the HAVE_PTY_H conditional block:

#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX)
#ifdef HAVE_PTY_H
#include <pty.h>
#ifdef HAVE_UTMP_H
#include <utmp.h>         // ← Only included if HAVE_PTY_H is defined!
#endif /* HAVE_UTMP_H */
#elif defined(HAVE_LIBUTIL_H)
#include <libutil.h>
#elif defined(HAVE_UTIL_H)
#include <util.h>         // ← NetBSD takes this path
#endif /* HAVE_PTY_H */
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) */

On NetBSD:

  • HAVE_OPENPTY is defined ✓
  • HAVE_PTY_H is not defined (NetBSD doesn't have /usr/include/pty.h)
  • HAVE_UTIL_H is defined ✓ (PTY functions are in /usr/include/util.h)
  • HAVE_UTMP_H is defined ✓ (but never gets included due to nesting)

Proposed Fix

Move the <utmp.h> inclusion outside the PTY header conditional so it can be included regardless of which PTY header is used:

#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX)
#ifdef HAVE_PTY_H
#include <pty.h>
#elif defined(HAVE_LIBUTIL_H)
#include <libutil.h>
#elif defined(HAVE_UTIL_H)
#include <util.h>
#endif /* HAVE_PTY_H */
#ifdef HAVE_UTMP_H
#include <utmp.h>          // Now included regardless of PTY header choice
#endif /* HAVE_UTMP_H */
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) */

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

@furkanonder furkanonder added type-bug An unexpected behavior, bug, or error build The build process and cross-build OS-netbsd labels Jun 3, 2025
@furkanonder
Copy link
Contributor Author

bisect to 1ffe913
@colesbury @duaneg

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 4, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 4, 2025
colesbury pushed a commit that referenced this issue Jun 4, 2025
colesbury pushed a commit that referenced this issue Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build OS-netbsd type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants