Skip to content

linux.getdents64 may return EINVAL #11178

Closed

Description

@17dec

Zig Version

0.9.1

Steps to Reproduce

Unclear (so far) how to reproduce, but observed in the wild: getdents64() returning EINVAL even when used correctly. Here's one case: https://code.blicky.net/yorhel/ncdu/issues/192#issuecomment-1110

I'm still trying to gather more data about the when, why and how.
Could be a bug in ncdu that I've overlooked, but the strace suggests correct use (EDIT: indeed, I see find reports the same error).
Could be a bug in the Linux kernel, but if it is, it'll be around in the wild for a bit longer, so is probably worth handling in the standard library anyway.

Expected Behavior

fs.Dir.Iterator should probably return an UnexpectedError; or at least something that can be handled application-side.

Actual Behavior

unreachable.

Activity

  1. added
    bug
    on Mar 15, 2022
  2. added
    standard library
    on Mar 15, 2022
  3. 17dec commented on Mar 16, 2022

    @17dec
    Author

    Found a way to reproduce it. This seems to happen for zombie processes:

    const std = @import("std");
    
    pub fn main() !void {
        // Spawn a zombie process
        var child = try std.ChildProcess.init(&.{"/bin/true"}, std.heap.page_allocator);
        try child.spawn();
        std.time.sleep(10 * std.time.ns_per_ms);
    
        // Attempt to list /proc/$PID/net
        var pathbuf: [128]u8 = undefined;
        const path = try std.fmt.bufPrint(&pathbuf, "/proc/{}/net", .{ child.pid });
        const dir = try std.fs.openDirAbsolute(path, .{ .iterate = true });
        var it = dir.iterate();
        _ = try it.next(); // <- hits unreachable
    }
  4. added a commit that references this issue on Mar 25, 2022
    dc36d25
  5. added a commit that references this issue on Mar 27, 2022
    a303022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstandard library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions