-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 Dan Nicholson wrote: > On Sat, Aug 04, 2007 at 04:04:17PM -0400, Bryan Kadzban wrote: >> (if normal "read(0, ...);" works, why doesn't "test -r <that >> device>"?) > > Why do you think read(0,...) works?
I assumed that the normal C-program method for reading standard input (that is, fgets(..., stdin);) was equivalent to read(0, ...);, with the addition of possible line buffering. Perhaps it isn't? Let me do some testing... OK, testing shows that calling read(0, ...); works, even when /dev/stdin "test"s not readable. The program I used is attached. I su'ed to root, then to another nonprivileged user, then ran "[ -r /dev/stdin ] ; echo $?" and got 1. Then I ran this program, and it echo'ed my input, so its read succeeded. > I don't see anything in the tests that tries to read from stdin. Right, it doesn't actually try to perform the read (if it did, then that would be a better test of what I think it's trying to look for). It just looks to see whether /dev/stdin's permissions mask (which it gets from stat) allows reading. IMO that check is a poor one -- it should just try to do the read, because there are cases where the test will fail but reading is still possible. > An alternative to using /dev/null is to use /dev/tty. This is what's > done in the perl tests (not by us), but I guess we can't guarantee > that'll be readable either. Well, /dev/tty is "the process's controlling TTY", and its permissions (AFAIK) should always be 0666. So that sounds like it might work better too. On your patch: Looks fine to me, unless we want to use /dev/tty. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGt8W+S5vET1Wea5wRAxLPAJ944U6ypnq/szhHbORXzwplyV10HwCdHNzy n9AUy3lIebsKc2w3Hl3COVU= =570e -----END PGP SIGNATURE-----
#include <stdio.h> #include <unistd.h> int main() { ssize_t bytes; char buf[1024]; bytes = read(0, buf, sizeof(buf)); if(bytes < 0) { perror("read"); return 1; } if(bytes >= 1024) bytes = 1023; buf[bytes] = 0; printf("Success: %s", buf); return 0; }
-- http://linuxfromscratch.org/mailman/listinfo/lfs-dev FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page