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
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.
#
#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";
sem_t *mutex = SEM_FAILED;
#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);
}
}
source
share