Re: Open with O_APPEND fails
On Saturday 27 December 2008 21:06:58 Jonathan Chen wrote: > On Sun, Dec 28, 2008 at 05:46:39AM +0100, Mitar wrote: > > Hi! > > > > On Sun, Dec 28, 2008 at 5:10 AM, Mel > > > > wrote: > > > open(2) will succeed but write(2) will fail with EBADF as documented > > > (and I verified this behavior). Still no EACCES as you and the > > > bugreporter are seeing. > > > > Where is documented that write would fail if file is opened only with > > O_APPEND? Implicitly in write(2) manpage: The write(), writev(), pwrite() and pwritev() system calls will fail and the file pointer will remain unchanged if: [EBADF]The d argument is not a valid descriptor open for writing. > > Just O_APPEND should also open file for writing as appending > > is also writing. It cannot be used without "write" semantics so file > > has to be open also for writing. > > If I recall correctly, this behaviour has been standard on UNIX-like > OS's for a *very* long time now. If you are seeing a write allowed > with just O_APPEND on Linux, it would very likely be a Linux only > "feature". Yup. Append is a bad english choice for the constant as it implies writes like you say, but really should be O_ATEND, because that's all that it does: seek to EOF. -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
On Sun, Dec 28, 2008 at 05:46:39AM +0100, Mitar wrote: > Hi! > > On Sun, Dec 28, 2008 at 5:10 AM, Mel > wrote: > > open(2) will succeed but write(2) will fail with EBADF as documented (and I > > verified this behavior). Still no EACCES as you and the bugreporter are > > seeing. > > Where is documented that write would fail if file is opened only with > O_APPEND? Just O_APPEND should also open file for writing as appending > is also writing. It cannot be used without "write" semantics so file > has to be open also for writing. If I recall correctly, this behaviour has been standard on UNIX-like OS's for a *very* long time now. If you are seeing a write allowed with just O_APPEND on Linux, it would very likely be a Linux only "feature". Cheers. -- Jonathan Chen -- The Internet: an empirical test of the idea that a million monkeys banging on a million keyboards can produce Shakespeare ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
On Sun, Dec 28, 2008 at 05:03:59AM +0100, Mitar wrote: > Hi! > > On Sun, Dec 28, 2008 at 4:58 AM, Gary Kline wrote: > > Just a thought, but have you figured out what the value of > > that OR is? then check the 6.x and 7.x src. > > You mean O_RDONLY? Is not that 0? So that O_RDONLY | O_APPEND is the > same as O_APPEND? (That is why I am writing about O_APPEND flag and > not O_RDONLY | O_APPEND as that bug report. > > > Mitar i WAS in fact, just looking at man open, but not the header. just check the int values for the two #defines, OR them, then stare at the 6.x and 7.x code. more simply, diff the two this is a bug--thanks for the Clue--but it is fixable. nutshell, it may be zero: i don't know. gary -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 2.17a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
Hi! On Sun, Dec 28, 2008 at 5:10 AM, Mel wrote: > open(2) will succeed but write(2) will fail with EBADF as documented (and I > verified this behavior). Still no EACCES as you and the bugreporter are > seeing. Where is documented that write would fail if file is opened only with O_APPEND? Just O_APPEND should also open file for writing as appending is also writing. It cannot be used without "write" semantics so file has to be open also for writing. Mitar ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
On Saturday 27 December 2008 18:16:41 Mitar wrote: > Hi! > > On Sun, Dec 28, 2008 at 1:17 AM, Mel > > wrote: > >15 fd = open(fname, O_WRONLY|O_APPEND); > > Try only with O_APPEND, without O_WRONLY. Why would you? open(2) will succeed but write(2) will fail with EBADF as documented (and I verified this behavior). Still no EACCES as you and the bugreporter are seeing. If this is really a bug in FreeBSD I'd expect way more applications to suffer issues. There must be something else at play and I certainly don't have an explanation why specifying the O_WRONLY flag would cause this bug to disappear. I suspect priv(9) to be responsible for the change in behavior you're seeing, however that should return EPERM not EACCES. -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
Hi! On Sun, Dec 28, 2008 at 4:58 AM, Gary Kline wrote: > Just a thought, but have you figured out what the value of > that OR is? then check the 6.x and 7.x src. You mean O_RDONLY? Is not that 0? So that O_RDONLY | O_APPEND is the same as O_APPEND? (That is why I am writing about O_APPEND flag and not O_RDONLY | O_APPEND as that bug report. Mitar ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
On Sun, Dec 28, 2008 at 04:16:41AM +0100, Mitar wrote: > Hi! > > On Sun, Dec 28, 2008 at 1:17 AM, Mel > wrote: > >15 fd = open(fname, O_WRONLY|O_APPEND); > > Try only with O_APPEND, without O_WRONLY. > > I have just found a bug report about that: > > https://issues.apache.org/bugzilla/show_bug.cgi?id=45923 > > But the question remains: why this fails? It works on Linux, as it is > seen from bug report it works also on FreeBSD 6.x, why it does not > work anymore on FreeBSD 7.x? Is it correct that it does not work? I > have not found anywhere written that O_WRONLY should be specified with > O_APPEND. > Just a thought, but have you figured out what the value of that OR is? then check the 6.x and 7.x src. gary > > Mitar > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 2.17a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
Hi! On Sun, Dec 28, 2008 at 1:17 AM, Mel wrote: >15 fd = open(fname, O_WRONLY|O_APPEND); Try only with O_APPEND, without O_WRONLY. I have just found a bug report about that: https://issues.apache.org/bugzilla/show_bug.cgi?id=45923 But the question remains: why this fails? It works on Linux, as it is seen from bug report it works also on FreeBSD 6.x, why it does not work anymore on FreeBSD 7.x? Is it correct that it does not work? I have not found anywhere written that O_WRONLY should be specified with O_APPEND. Mitar ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Open with O_APPEND fails
On Saturday 27 December 2008 11:46:03 Mitar wrote: > Hi! > > I discovered that open syscall with only O_APPEND fails with > "permission denied" if an user does not have rights to write to a file > (what is normal) even if it is root (what is a surprise). For example, > if I have a file owned by www:www and with 644 permissions root cannot > do open("testfile", O_APPEND) call. If I change ownership of I change > permission to for example 666, call succeedes. > > This works on Linux (Debian). So this is a feature? Or a bug? > > (I discovered that because htpasswd failed to add new > username/password pair (ran as root) to a file owner by www.) > > Checked on FreeBSD 7.0-STABLE. Can't reproduce: $ ls -al test.txt -rw-r--r-- 1 www www 33 Dec 27 15:12 test.txt $ sudo ./open test.txt opened as fd 3 $ cat test.txt this file cannot be appended to $ cat -n open.c 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 int main(void) 10 { 11 const char fname[] = "test.txt"; 12 const char txt[] = "cannot be appended to\n"; 13 int fd; 14 15 fd = open(fname, O_WRONLY|O_APPEND); 16 if( fd < 0 ) 17 err(EX_NOINPUT, "Failed to open %s", fname); 18 19 printf("%s opened as fd %i\n", fname, fd); 20 if( write(fd, txt, sizeof(txt)) < 0 ) 21 err(EX_DATAERR, "write()"); 22 close(fd); 23 return EX_OK; 24 } -- Mel Problem with today's modular software: they start with the modules and never get to the software part. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Open with O_APPEND fails
Hi! I discovered that open syscall with only O_APPEND fails with "permission denied" if an user does not have rights to write to a file (what is normal) even if it is root (what is a surprise). For example, if I have a file owned by www:www and with 644 permissions root cannot do open("testfile", O_APPEND) call. If I change ownership of I change permission to for example 666, call succeedes. This works on Linux (Debian). So this is a feature? Or a bug? (I discovered that because htpasswd failed to add new username/password pair (ran as root) to a file owner by www.) Checked on FreeBSD 7.0-STABLE. Mitar ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"