title: How do I stop sem_open() failing with ENOSYS?
body: <p>I have two Slackware Linux systems on which the POSIX semaphore <code>sem_open()</code> call fails with errno set to 38. Sample code to reproduce below (the code works fine on CentOS / RedHat).</p>
  
  <p>Are there any kernel or system configuration options that could cause this? Other suggestions?</p>
  
  <p>Systems with issue are Slackware 10.1.0 kernel 2.6.11 /lib/librt-2.3.4.so /lib/libpthread-0.10.so, but the same code works on the much older RedHat 9 kernel 2.4.20 /lib/librt-2.3.2.so /lib/tls/libpthread-0.29.so. (and also works on CentOS 5 kernel 2.6.18 /lib/librt-2.5.so /lib/i686/nosegneg/libpthread-2.5.so).</p>
  
  <p><code>man sem_open</code> suggests this errno means <code>sem_open()</code> is not supported by system.</p>
  
  <pre><code>#define ENOSYS          38      /* Function not implemented */
  </code></pre>
  
  <p>The <code>sem_open()</code> userspace is in <code>librt</code> which we link against dynamically and <code>librt</code> is present on the affected systems.</p>
  
  <p>The affected system claims to support POSIX semaphores: <code>_POSIX_SEMAPHORES</code> is true and <code>sysconf(_SC_SEMAPHORES)</code> confirms this.</p>
  
  <p>Thanks,
  Kieran</p>
  
  <p>Edit 1: I've added more detail on the software versions in use and removed some irrelevant comments.</p>
  
  <p>Edit 2: /dev/shm is mounted on the good systems and not mounted on the bad systems. Mounting it did not change the behaviour on the affected systems. I think /dev/shm is necessary too but sem_open() is failing before that, and strace supports this.</p>
  
  <pre><code># /* Quick'n'dirty test program to illustrate sem_open failure
  #Run this file to auto-build test and run as a.out
  
  # Build
  gcc $0 -lrt
  if [ $? -ne 0 ] ; then exit ; fi
  
  # Run
  $( dirname $0)/a.out
  exit
  */
  
  #include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;semaphore.h&gt;
  
  
  int main(int argc, char *argv[]) {
  
   const char *SEM_NAME = "SHRMEM_SCXL";  /* name of mutex */
   sem_t *mutex = SEM_FAILED;             /* ptr to mutex */
  
  #ifdef _POSIX_SEMAPHORES
    printf("_POSIX_SEMAPHORES %ld\n", _POSIX_SEMAPHORES);
  #else
    puts("Undefined");
  #endif
  
   printf("sysconf %s\n", sysconf(_SC_SEMAPHORES) ? "Yes" : "No" );
  
   mutex = sem_open(SEM_NAME, O_CREAT, 0666, 1);
  
   if (mutex == SEM_FAILED) printf("Failed %d\n", errno);
   else {
          puts("Success - pause while you check /dev/shm ");
          sleep(5);
          sem_close(mutex);
          sem_unlink(SEM_NAME);
   }
  }
  </code></pre>