From:             ein at anti-logic dot com
Operating system: linux 2.6
PHP version:      4.4.7
PHP Bug Type:     Filesystem function related
Bug description:  sem_get / sem_aquire cannot ensure exclusive access

Description:
------------
It is impossible to duplicate flock functionality with the sem controls
due to sem_get's and sem_aquire's inability to ensure exclusive access.

For example with flock, if we create a non exclusive (shared) lock,
followed by an exclusive lock, it will block on the second lock creation.
This is the expected behaviour, and allows us to ensure that there is
exclusive access to the file.

Reproduce code:
---------------
$fp = sem_get(fileinode('lock_file', 100, 666);
sem_acquire($fp);
echo "one lock is in place, we should Block on the second lock request";
$fp2 = sem_get(fileinode('lock_file', 1, 666);
sem_acquire($fp2);
echo "but we have not";

$fp3 = fopen('lock_file', 'w');
flock($fp3, LOCK_SH);
echo "one flock is in place, we should block on the next lock request";
$fp4 = fopen('lock_file', 'w');
flock($fp4, LOCK_EX);
echo "we will never see this text due to proper indefinite blocking";

Expected result:
----------------
sem_aquire should block on the second lock creation.

Actual result:
--------------
It will not block, nor will sem_get or sem_aquire return an error.

I believe the confusion may be caused by this line in the documentation,
"Actually this value is set only if the process finds it is the only
process currently attached to the semaphore."  However, that is reffering
only to the perm field, and not max_aquire.  Either the documentation
should be updated to reflect the (broken) implementation, or the
sem_aquire/sem_get functions should be modified to ensure an exclusive lock
request (max_aquire=1) will block when an existing lock is in place.

-- 
Edit bug report at http://bugs.php.net/?id=41805&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41805&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41805&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41805&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41805&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41805&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41805&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41805&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41805&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41805&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41805&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41805&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41805&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41805&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41805&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41805&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41805&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41805&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41805&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41805&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41805&r=mysqlcfg

Reply via email to