How to stop sem_open () using ENOSYS?

I have two Slackware Linux systems where the POSIX semaphore sem_open()crashes with an error set to 38. Sample code for playback below (the code works fine on CentOS / RedHat).

Are there any kernel or system configuration options that can cause this? Other offers?

Release systems 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 2.4.20 / lib / kernel librt-2.3.2.so/lib/tls/libpthread-0.29.so. (and also runs on the CentOS 5 kernel 2.6.18 / lib / librt-2.5.so / lib / i686 / nosegneg / libpthread-2.5.so).

man sem_openassumes errno is a value that is sem_open()not supported by the system.

#define ENOSYS          38      /* Function not implemented */

User space sem_open()is located in librtwhich we associate dynamically and is librtpresent in the affected systems.

The damaged system claims to support POSIX semaphores: _POSIX_SEMAPHOREStrue, but sysconf(_SC_SEMAPHORES)confirms this.

Thank you Kieran

Edit 1: I added more details about the software versions used and deleted some unulocal comments.

Edit 2: / dev / shm is mounted on good systems and not installed on bad systems. Its installation did not affect the behavior of the affected systems. I think / dev / shm is also necessary, but sem_open () does not work before that, and strace supports this.

# /* 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 <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <semaphore.h>


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);
 }
}
+3
source share
5 answers

/dev/shm? slackware, , . /etc/fstab:

tmpfs  /dev/shm  tmpfs  defaults  0   0

: , . , ​​, , librt.

Edit2: , slackware 11, , , , , , 2.6.13, NPTL (libs in/lib/tls), , , sem_open .

Edit3: slackware 11, : a) mount/dev/shm b) LD_ASSUME_KERNEL 2.6.13 ( a > 2.6.12 ). , , ​​2.6.11.11, , , .

+4

POSIX . man sem_init

pshared , (pshared ) (pshared ). LinuxThreads , , sem_init error ENOSYS, pshared .

sem_open() , .

sem_init() Slackware 10

  • libpthread () librt
  • ​​

, sem_open()

  • /etc/fstab, /dev/shm tmpfs

    tmpfs/dev/shm tmpfs 0 0

  • mount /dev/shm

+1

" sema4s " . , , , : , "-" :

  • , sem_init ( ). , sema4s .

  • . , . , , , USER sema4, , .

+1

posix. . mq_open errono 38 (ENOSYS).

arround - POSIX MESSGE QUEUE .

​​ POSIX, .

0

Source: https://habr.com/ru/post/1699240/


All Articles