Skip to content

bug: sysopen() with O_NONBLOCK fatally croaks — flag missing from SUPPORTED_SYSOPEN_MODES #412

Description

@toddr

Summary

sysopen() on a mocked path dies with "Some of your permissions are not yet supported by Test::MockFile" whenever O_NONBLOCK (0x800) is part of the mode. O_NONBLOCK is not listed in SUPPORTED_SYSOPEN_MODES, and the mode-validation check confesses on any bit outside that whitelist.

Reproduction

use Fcntl;
use Test::MockFile qw< nostrict >;

my $dir = Test::MockFile->new_dir('/home/bob', { autovivify => 1 });

# Works (0xc1):
sysopen(my $ok, '/home/bob/a', O_WRONLY | O_CREAT | O_EXCL, 0600) or die "sysopen: $!";

# Dies (0x8c1):
#   Sorry, can't open /home/bob/b with 0x8c1 permissions.
#   Some of your permissions are not yet supported by Test::MockFile
sysopen(my $no, '/home/bob/b', O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK, 0600);

Cause

use constant SUPPORTED_SYSOPEN_MODES =>
    O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_TRUNC | O_EXCL | O_CREAT | O_NOFOLLOW;
...
if ( ( $sysopen_mode & SUPPORTED_SYSOPEN_MODES ) != $sysopen_mode ) {
    confess( ... "Some of your permissions are not yet supported ..." );
}

O_NONBLOCK is absent from the whitelist, so any sysopen including it is fatal.

Impact

O_NONBLOCK is routinely OR'd into open flags for lock files and other guarded opens — it prevents blocking on FIFOs/devices and is harmless on regular files. For an in-memory mock it has no meaningful effect and can be safely accepted (and ignored). Today, any code under test that opens files with O_NONBLOCK cannot be exercised against mocked paths.

Suggested fix

Add O_NONBLOCK to SUPPORTED_SYSOPEN_MODES (accept-and-ignore). The same reasoning likely applies to O_CLOEXEC and O_NOCTTY, which are similarly benign for mocked files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions