Skip to content

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

Closed
@furkanonder

Description

@furkanonder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-netbsdbuildThe build process and cross-buildtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions