O_ACCMODE doesn't respect O_EXEC

Sergey Kandaurov pluknet at gmail.com
Fri Apr 29 13:17:48 UTC 2011


Hi.

As of now, O_ACCMODE is a conjunction of O_{RDONLY,WRONLY,RDWR} flags
as it was from the beginning. Its definition hasn't changed with
addition of O_EXEC.

POSIX states:
O_ACCMODE - Mask for file access modes.

O_EXEC falls into this access modes category, so I think O_ACCMODE
should include O_EXEC.
This may require review of O_ACCMODE usage throughout the kernel, though..

This simple test demonstrates the problem:

flags: 0x0
flags: 0x0
flags: 0x1
flags: 0x1
flags: 0x2
flags: 0x2
flags: 0x3ffff
flags: 0x3
^^ decremented due OFLAGS macro that also doesn't respect new access
mode flag(s)
^^ correct version would show 0x40000

int
main(void)
{

        test_with(O_RDONLY);
        test_with(O_WRONLY);
        test_with(O_RDWR);
        test_with(O_EXEC);

        return (0);
}

static void
test_with(int openflag)
{
        int fd, flags;

        if ((fd = open("file", openflag)) < 0)
                err(1, "open");
        if ((flags = fcntl(fd, F_GETFL)) < 0)
                err(1, "fcntl(fd, GETFL)");
        printf("flags: 0x%x\n", flags);
        printf("flags: 0x%x\n", flags&O_ACCMODE);
        close(fd);
}

-- 
wbr,
pluknet


More information about the freebsd-standards mailing list