return -ERRNO_TO_DSS_ERROR(errno);
}
-static int mutex_lock(int id)
-{
- struct sembuf sops[4];
-
- DSS_DEBUG_LOG(("locking\n"));
-
- sops[0].sem_num = 0;
- sops[0].sem_op = 0;
- sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- sops[1].sem_num = 0;
- sops[1].sem_op = 1;
- sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- sops[2].sem_num = 1;
- sops[2].sem_op = 0;
- sops[2].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- sops[3].sem_num = 1;
- sops[3].sem_op = 1;
- sops[3].sem_flg = SEM_UNDO | IPC_NOWAIT;
-
- return do_semop(id, sops, 4);
-}
-
static bool mutex_is_locked(int id)
{
struct sembuf sops;
int lock_dss(char *config_file)
{
- int ret;
+ int ret, id;
+ struct sembuf sops[4];
key_t key = get_key(config_file);
ret = mutex_get(key, IPC_CREAT | 0600);
if (ret < 0)
return ret;
- return mutex_lock(ret);
+ id = ret;
+
+ sops[0].sem_num = 0;
+ sops[0].sem_op = 0;
+ sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+ sops[1].sem_num = 0;
+ sops[1].sem_op = 1;
+ sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+ sops[2].sem_num = 1;
+ sops[2].sem_op = 0;
+ sops[2].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+ sops[3].sem_num = 1;
+ sops[3].sem_op = 1;
+ sops[3].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+ return do_semop(id, sops, 4);
}
int get_dss_pid(char *config_file, pid_t *pid)