From: mlemos at acm dot org Operating system: PHP version: 4.3.4 PHP Bug Type: Filesystem function related Bug description: flock does not initialize the wouldblock argument when it succeeds locking
Description: ------------ flock() does not initialize the wouldblock argument when present and it succeeds locking, even when non-blocking locking is requested. It is also failing when wouldblock argument is not present but non blocking locking is requested and flock() system call returns EWOULDBLOCK. This is a minor issue. This patch should fix both issues: *** ext/standard/file.c 2003-11-21 18:39:13.000000000 -0200 --- ext/standard/file.c.fixed 2003-11-21 18:39:00.000000000 -0200 *************** *** 251,261 **** if (arg2 & 4) we won't block on the lock */ act = flock_values[act - 1] | (Z_LVAL_PP(arg2) & 4 ? LOCK_NB : 0); if (flock(fd, act)) { ! if (errno == EWOULDBLOCK && arg_count == 3) { ! ZVAL_LONG(*arg3, 1); } else { RETURN_FALSE; ! } } RETURN_TRUE; } --- 251,269 ---- if (arg2 & 4) we won't block on the lock */ act = flock_values[act - 1] | (Z_LVAL_PP(arg2) & 4 ? LOCK_NB : 0); if (flock(fd, act)) { ! if ((Z_LVAL_PP(arg2) & 4) && errno == EWOULDBLOCK) { ! if(arg_count == 3) { ! ZVAL_LONG(*arg3, 1); ! } } else { RETURN_FALSE; ! } ! } ! else ! { ! if(arg_count == 3) { ! ZVAL_LONG(*arg3, 0); ! } } RETURN_TRUE; } Reproduce code: --------------- <?php if(!($file=(fopen("testfile","w")))) die("could not open file"); if(flock($file,6,&$wouldblock)) echo "flock succeed, wouldblock ",serialize($wouldblock),"\n"; else echo "flock failed\n"; fclose($file); ?> Expected result: ---------------- flock succeed, wouldblock i:0; Actual result: -------------- flock succeed, wouldblock N; -- Edit bug report at http://bugs.php.net/?id=26355&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26355&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26355&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26355&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26355&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26355&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=26355&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26355&r=support Expected behavior: http://bugs.php.net/fix.php?id=26355&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26355&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26355&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26355&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26355&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26355&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26355&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26355&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26355&r=float