--- APC-3.1.9/apc_sem.c_orig Sat May 14 15:14:56 2011
+++ APC-3.1.9/apc_sem.c Tue Dec 13 16:01:59 2011
@@ -76,12 +76,16 @@
union semun arg;
key_t key = IPC_PRIVATE;
- if ((semid = semget(key, 1, IPC_CREAT | IPC_EXCL | perms)) >= 0) {
+ if ((semid = semget(key, 2, IPC_CREAT | IPC_EXCL | perms)) >= 0) {
/* sempahore created for the first time, initialize now */
arg.val = initval;
if (semctl(semid, 0, SETVAL, arg) < 0) {
apc_error("apc_sem_create: semctl(%d,...) failed:" TSRMLS_CC, semid);
}
+ arg.val = getpid();
+ if (semctl(semid, 1, SETVAL, arg) < 0) {
+ apc_error("apc_sem_create: semctl(%d,...) failed:", TSRMLS_CC, semid);
+ }
}
else if (errno == EEXIST) {
/* sempahore already exists, don't initialize */
@@ -101,7 +105,10 @@
{
/* we expect this call to fail often, so we do not check */
union semun arg;
- semctl(semid, 0, IPC_RMID, arg);
+ int semPid = semctl(semid, 1, GETVAL, 0);
+ if (semPid == getpid()) {
+ semctl(semid, 0, IPC_RMID, arg);
+ }
}
void apc_sem_lock(int semid TSRMLS_DC)