Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Apr 2011 16:51:38 +0400
From:      Sergey Kandaurov <pluknet@gmail.com>
To:        freebsd-standards@freebsd.org
Subject:   O_ACCMODE doesn't respect O_EXEC
Message-ID:  <BANLkTi=Uzo1FE9O0pvdr2zGcf_SAz=auMA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTi=Uzo1FE9O0pvdr2zGcf_SAz=auMA>