php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45013 Semaphore cannot be released under certain circumstances.
Submitted: 2008-05-15 20:47 UTC Modified: 2008-07-19 01:00 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: andre at koethur dot de Assigned:
Status: No Feedback Package: Semaphore related
PHP Version: 4.4.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andre at koethur dot de
New email:
PHP Version: OS:

 

 [2008-05-15 20:47 UTC] andre at koethur dot de
Description:
------------
If I acqure a semaphore in one script, then it is not possible to 
release it in another script, even if I set "auto_release" to false.

As I have found out, it has something to do with the "count" attribute 
of the "sysvsem_sem"-structure. This value is really only needed by 
the 
"auto_release"-functionality, so it should be safe to ignore it in 
php_sysvsem_semop()-function.

The current cvs-version of sysvsem.c says on line 290:
if (!acquire && sem_ptr->count == 0)

I suggest to change it to:
if (!acquire && sem_ptr->count == 0 && sem_ptr->auto_release)






Reproduce code:
---------------
First script, acquire semaphore:

<?php

$sem_id = sem_get(2405, 1, 0666, false);
if ($sem_id !== false) if (sem_acquire($sem_id)) echo 'Sem acquired!';

?>

Second script, release semaphore:

<?php

$sem_id = sem_get(2405, 1, 0666, false);
if ($sem_id !== false) if (sem_release($sem_id)) echo 'Sem released!';

?>



Expected result:
----------------
The second script should run without errors/warnings and the semaphore 
should be released.

Actual result:
--------------
Warning: sem_release() [function.sem-release]: SysV semaphore 2 (key 
0x965) is not currently acquired

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-11 21:46 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

If you can reproduce this problem using latest PHP 5.2 snapshot, update the version string to contain: 5.2CVS-2008mmdd
 [2008-07-19 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-09-01 23:07 UTC] www at qaaa dot de
Same problem now with PHP 5.3.0
 [2009-09-02 00:23 UTC] www at qaaa dot de
/*
if (!acquire && sem_ptr->count == 0) 
{
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "SysVadasdsad semaphore %ld (key 0x%x) is not currently acquired", Z_LVAL_P(arg_id), sem_ptr->key);
		RETURN_FALSE;
	}
*/


this was my way to get the correct result... but ive not sure if any side effects will come up with?!

what do you want to restrict with the 
(!acquire && sem_ptr->count == 0)
? why should not release when the sem counter is 0?
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 03:03:12 2021 UTC