I have the following code:
int rc = 0;
key_t key = ftok("test.sh", 100);
if (key == -1) {
std::cout << "ftok failed" << std::endl;
}
int sem_id = semget(key, 1, IPC_CREAT | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH));
if (sem_id == -1) {
std::cout << "semget failed" << std::endl;
}
//removing semaphore set
union semun sem_union;
rc = semctl(sem_id, 1, IPC_RMID, sem_union);
if (rc == -1) {
std::cout << "semctl failed" << std::endl;
}
struct sembuf command_buf[2];
// Wait for 0
command_buf[0].sem_num = 0;
command_buf[0].sem_op = 0;
command_buf[0].sem_flg = SEM_UNDO;
// Increment by 1
command_buf[1].sem_num = 0;
command_buf[1].sem_op = 1;
command_buf[1].sem_flg = SEM_UNDO;
rc = semop(sem_id, command_buf, 2);
if (rc == -1) {
std::cout << "errno=" << errno << std::endl;
}
I got the output "errno=22" which is EINVAL. Shouldn't I be getting EIDRM instead, given it is the error code for when "the semaphore set was removed" according to the documentation and supported by the answer here?