#include <stddef.h>
#include <limits.h>
#include <sys/param.h>
+#include <stdbool.h>
#include "gcc-compat.h"
#include "str.h"
return 1;
}
-static int mutex_try_lock(int id)
+static bool mutex_is_locked(int id)
{
- struct sembuf sops[2];
+ struct sembuf sops;
int ret;
DSS_DEBUG_LOG(("trying to lock\n"));
- sops[0].sem_num = 0;
- sops[0].sem_op = 0;
- sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
+ sops.sem_num = 0;
+ sops.sem_op = 0;
+ sops.sem_flg = SEM_UNDO | IPC_NOWAIT;
- sops[1].sem_num = 0;
- sops[1].sem_op = 1;
- sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- ret = do_semop(id, sops, 2);
+ ret = do_semop(id, &sops, 1);
if (ret < 0)
- return -ERRNO_TO_DSS_ERROR(errno);
- return 1;
+ return true;
+ return false;
}
int lock_dss(char *config_file)
return -E_NOT_RUNNING;
if (pid)
*pid = ret;
- ret = mutex_try_lock(semid);
- if (ret >= 0)
- return -E_NOT_RUNNING;
- return 1;
+ return mutex_is_locked(semid)? 1 : -E_NOT_RUNNING;
}