# sem_open 'permision denied' when open another account



## aircrazy (Mar 28, 2014)

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

```
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:

```
[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?


----------



## SirDice (Mar 28, 2014)

I'm not a programmer but the sem_open(3) man page states:

```
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.


----------



## aircrazy (Apr 1, 2014)

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.


----------

