1

This is a tough one.

Cannot create a POSIX named semaphore (sem_open) no matter the name on a system where there are no semaphores (thus no chance of name overlapping). This is a non-privileged user able to create a shared memory using shmget.

Platform: Solaris 10

Hardware: Intel Xeon E5000 series CPU

Does not happen on other Solaris 10 platforms running AMD CPUs with non-privileged users. Does not happen on Linux machines. No apparent differences between these machines, other than the fact that this machine is very likely virtualized.

Code:

    const char* name = "/permission_test_semaphore";

    sem_t* sem = sem_open(name, O_CREAT | O_EXCL, 0644, 0);
    if (SEM_FAILED == sem)
    {
            printf("Could not create test semaphore %s, errno = %d\n", name, errno);
    }

Output is:

Could not create test semaphore /permission_test_semaphore, errno = 13

Any ideas are welcome -- my hopes are not up.

Makanaky
  • 33
  • 1
  • 4

3 Answers3

0

The first thing that comes to mind is that security or resource-limiting settings are preventing it. I'd look through http://docs.oracle.com/cd/E19575-01/821-0182/fxxtz/index.html for ideas on that.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Good lead. Unfortunately, there are no differences for `prctl $$` compared to the working Solaris machines, e.g. `prctl -n process.max-sem-ops $$` yields the default values. – Makanaky Feb 21 '13 at 14:22
0

On linux, /dev/shm must exist for POSIX shared memory and semaphores. I suspect Solaris needs something similar.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • The other Solaris machines do not have anything on `dev/shm` and creating semaphores just works. – Makanaky Feb 21 '13 at 14:18
  • I confirm that on the working Linux machines `/dev/shm` is set up. – Makanaky Feb 21 '13 at 14:25
  • 2
    Did not know about `strace`, but it did not work (unable to open /dev/log). However, googling, I found `truss`, which showed a system access to `/tmp/.SEMLpermission_test_semaphore`, where my user does not have permissions. Apparently, `sem_open` on Solaris creates a file by the name of `/tmp/.SEML` -- how weird and undocumented is that... – Makanaky Feb 21 '13 at 17:39
  • 1
    Not so undocumented, actually -- if one read this book (Solaris Internals, Core Kernel Architecture) it would be plain obvious -- http://books.google.com/books?id=r_cecYD4AKkC&lpg=PA454&ots=oCueg2AGyR&dq=sem_open%20sunos%20creates%20a%20file%20in%20the%20%2Ftmp%20directory&pg=PA454#v=onepage&q=sem_open%20sunos%20creates%20a%20file%20in%20the%20/tmp%20directory&f=false – Makanaky Feb 21 '13 at 17:52
0

The reason is no permissions in the /tmp directory. The SunOS implementation for creating POSIX named semaphores requires creating files in the hardcoded /tmp path. This is documented in the SOLARIS Internals, Core Kernel Architecture book, page 454:

The POSIX semaphore code uses the /tmp file system for the creation and storage of the files that the code memory maps based on the argument passed in the sem_open(3R) call.

Running truss <executable> will show access to /tmp/.SEML<sem_name> right before giving the on-screen error.

Makanaky
  • 33
  • 1
  • 4