06.07.2023 13:41, Murphy Zhou пишет:
Signed-off-by: Stas Sergeev <stsp2@xxxxxxxxx> --- src/t_ofd_locks.c | 73 ++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/t_ofd_locks.c b/src/t_ofd_locks.c index e77f2659..daa6f96c 100644 --- a/src/t_ofd_locks.c +++ b/src/t_ofd_locks.c @@ -297,6 +297,7 @@ int main(int argc, char **argv) semid = semget(semkey, 2, IPC_CREAT|IPC_EXCL); if (semid < 0 && errno == EEXIST) { /* remove sem set after one round of test */ + semid = semget(semkey, 2, IPC_CREAT); if (semctl(semid, 2, IPC_RMID, semu) == -1) Good catch. This RMID is useless unless we have got the existing semaphore. According to SEMGET(2), seems should be: semid = semget(semkey, 2, 0); to obtain an existing semaphore?
Yes, I just wanted to avoid the purely theoretical condition when someone else removed this sem right before we did second semget(). So I added IPC_CREAT just as a safety measure. Should I remove it?
The while loop makes sure we get the semaphore before continuing the test. It's been some time, I'm not sure but now I really can't see this really hurts.
What while loop do you mean and what doesn't hurt? Does the rest of the patch look ok?