From: <ro...@us...> - 2003-04-01 17:17:07
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/flock In directory sc8-pr-cvs1:/tmp/cvs-serv24121 Modified Files: flock03.c Log Message: Applied Matthew Wilcox flock03 patch: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< The reason flock03 currently fails on both Linux 2.4 and 2.5 is because it's wrong ;-) I suspect the test author didn't understand flock locks -- they're very different from POSIX locks. flocks are associated with a file descriptor, but the child process was opening a new file descriptor and expecting to be able to unlock it. That won't work; you have to pass the file descriptor to the child from the parent. This patch does just that. I'm not sure it's exactly what the author wanted to achieve. I've added the flock06 test too which tests that flocks on two fds on the same file do conflict with each other. flock03 still fails. This is due to a real bug in both Linux 2.4 and 2.5. Andrea's kernel picked up the fix, but Marcelo has declined it. I hope to fix it properly in 2.5 in the next couple of weeks. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Index: flock03.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/flock/flock03.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- flock03.c 27 Jan 2003 22:30:31 -0000 1.3 +++ flock03.c 1 Apr 2003 17:17:02 -0000 1.4 @@ -74,14 +74,13 @@ void setup(void); void cleanup(void); -void childfunc(void); +void childfunc(int); char *TCID = "flock03"; /* Test program identifier */ int TST_TOTAL = 3; /* Total number of test cases */ extern int Tst_count; char filename[100]; -int fd; /* for opening the temporary file */ int main(int argc, char **argv) { @@ -89,6 +88,7 @@ char *msg; /* message returned from parse_opts */ pid_t pid; int status; + int fd; /* for opening the temporary file */ /* parse standard options */ @@ -107,18 +107,19 @@ /* reset Tst_count in case we are looping */ Tst_count = 0; + /* PARENT */ + fd = open(filename, O_RDWR); + if(fd == -1) + tst_brkm(TFAIL, cleanup, "parent failed to open the" + "file, errno %d", errno); + pid = fork(); if(pid == -1) tst_brkm(TFAIL, cleanup, "fork() failed, errno %d", errno); if(pid == 0) - childfunc(); + childfunc(fd); - /* PARENT */ - fd = open(filename, O_RDWR); - if(fd == -1) - tst_brkm(TFAIL, cleanup, "parent failed to open the" - "file, errno %d", errno); TEST(flock(fd, LOCK_EX | LOCK_NB)); if(TEST_RETURN != 0) tst_resm(TFAIL, "Parent: Initial attempt to flock() failed, " @@ -143,33 +144,39 @@ } -void childfunc(void ) +void childfunc(int fd) { + int fd2; /* give the parent a chance to lock the file */ sleep(2); - fd = open(filename, O_RDWR); - if(fd == -1) + fd2 = open(filename, O_RDWR); + if(fd2 == -1) tst_brkm(TFAIL, cleanup, "child failed to open the" - "file, errno %d", errno); - if(flock(fd, LOCK_EX | LOCK_NB) != -1) + "file, errno %d", errno); + if(flock(fd2, LOCK_EX | LOCK_NB) != -1) tst_resm(TFAIL, "Child: The file was not already locked"); TEST(flock(fd, LOCK_UN)); + /* XXX: LOCK_UN does not return an error if there was nothing to + * unlock. + */ if(TEST_RETURN == -1) tst_resm(TFAIL, "Child: Unable to unlock file locked by parent, " "errno %d", TEST_ERRNO); else tst_resm(TPASS, "Child: Unlocked file locked by parent"); - TEST(flock(fd, LOCK_EX | LOCK_NB)); + TEST(flock(fd2, LOCK_EX | LOCK_NB)); if(TEST_RETURN == -1) tst_resm(TFAIL, "Child: Unable to relock file after unlocking, " "errno %d", TEST_ERRNO); else tst_resm(TPASS, "Child: flock after unlocking passed"); + close(fd2); + tst_exit(); /* NOT REACHED */ return; @@ -182,6 +189,7 @@ */ void setup(void) { + int fd; /* capture signals */ tst_sig(FORK, DEF_HANDLER, cleanup); |