podman-container-tools/podman · error

opendir %s: %m

Error message

opendir %s: %m

What it means

do_preexec_hooks_dir() scans a preexec-hooks directory with opendir() (pkg/rootless/rootless_linux.c:423). A missing directory (ENOENT) is silently ignored, so this fatal message means opendir failed with a different errno - most commonly EACCES (no read/execute permission on the directory), ENOTDIR (a path component is a plain file), or ELOOP (symlink loop).

Source

Thrown at pkg/rootless/rootless_linux.c:428

  if (WIFSTOPPED (status))
      exit (EXIT_FAILURE);
}

static void
do_preexec_hooks_dir (const char *dir, char **argv, int argc)
{
  cleanup_free char *buffer = NULL;
  cleanup_dir DIR *d = NULL;
  size_t i, nfiles = 0;
  struct dirent *de;

  /* Store how many FDs were open before the Go runtime kicked in.  */
  d = opendir (dir);
  if (!d)
    {
      if (errno != ENOENT)
        {
          fprintf (stderr, "opendir %s: %m\n", dir);
          exit (EXIT_FAILURE);
        }
      return;
    }

  errno = 0;

  for (de = readdir (d); de; de = readdir (d))
    {
      buffer = realloc (buffer, (nfiles + 1) * (NAME_MAX + 1));
      if (buffer == NULL)
        {
          fprintf (stderr, "realloc buffer: %m\n");
          exit (EXIT_FAILURE);
        }

      if (de->d_type != DT_REG)
        continue;

View on GitHub (pinned to a2409076ef)

Solutions

  1. Check the failing dir reported in the message: 'ls -ld <dir>' and fix permissions with 'chmod a+rx <dir>' or adjust ownership
  2. If SELinux is enforcing, check 'ausearch -m avc -ts recent' and relabel with 'restorecon -Rv <dir>'
  3. Verify the path is really a directory ('test -d <dir>') and fix $PODMAN_PREEXEC_HOOKS_DIR if it is wrong
  4. Disable the hooks mechanism by removing /etc/containers/podman_preexec_hooks.txt to confirm or work around

Example fix

# before
$ ls -ld /etc/containers/pre-exec-hooks
drwx------ 2 root root ... /etc/containers/pre-exec-hooks
$ podman version
opendir /etc/containers/pre-exec-hooks: Permission denied

# after
$ sudo chmod 0755 /etc/containers/pre-exec-hooks
$ podman version
Defensive patterns

Strategy: validation

Validate before calling

# Verify every hooks dir podman will scan is a readable directory
for d in /etc/containers/pre-exec-hooks "${PODMAN_PREEXEC_HOOKS_DIR:-}"; do
  [ -z "$d" ] && continue
  if [ -e "$d" ] && { [ ! -d "$d" ] || [ ! -r "$d" ] || [ ! -x "$d" ]; }; then
    echo "unusable preexec hooks dir: $d" >&2
    exit 1
  fi
done
podman "$@"

Prevention

When it happens

Trigger: The hooks dir exists but mode/ownership denies access to the invoking (often rootless) user; /etc/containers/pre-exec-hooks or $PODMAN_PREEXEC_HOOKS_DIR points at a file instead of a directory; SELinux denial on the directory; hooks dir on an NFS mount with root squashing and restrictive perms.

Common situations: Hook packages installed as root with mode 0700 while podman runs rootless; a custom PODMAN_PREEXEC_HOOKS_DIR typo pointing to a file; SELinux mislabeling after copying hooks with cp -a from another host.

Related errors


AI-assisted analysis of podman-container-tools/podman@a2409076ef (2026-08-15). Data as JSON: /api/errors/0c3f692aabc514ac. Report an issue: GitHub.