sem_open 'permision denied' when open another account

I have problem with open already exist semaphor created other user in one group. sem_open(3) failed with 'Permission denied' error.
Metaphor created with all permission.

test.c
Code:
sem_t * s = sem_open("/testsem5", O_CREAT, S_IRWXG | S_IRWXO |S_IRWXU);
if(s == SEM_FAILED){
  int err =  errno;
  printf("%s(%i)\n", strerror(err), err);
}else{
  printf("ok\n");
}

Expl output:
Code:
[anotheruser@server]./test.out
ok

[aircrazy@server]./test.out
Permission denied(13)
@aircrazy and @anotheruser in one group. FreeBSD 9.1 under jails.


Please, explain why I have this error?
 
Last edited by a moderator:
I'm not a programmer but the sem_open(3) man page states:
Code:
The mode is modified according to the process's file creation mask; see umask(2).

The default umask(2) is 022. So you end up with 644 permissions. And although both users are in the same group the semaphore will have @aircrazy's primary group, which is usually @aircrazy. Only the owner has write permissions.
 
Last edited by a moderator:
Thanks.
I think third parameters override umask.
But found next problem - i use freebsd about ten hours and not understand many things. Sorry for my next dummy question.
Why file created in /tmp have group 'wheel' ?

Named semaphores shows in /tmp aka SEMD[semaphore name] and i see group owner as 'wheel'.

Gratitude for answer.
 
Back
Top