This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

semget() crash


Please find attached a short test programme derived from the semaphore handling code in Poco. The test crashes in the call to semget(), reporting 'Bad system call (core dumped)'. I am using the latest 32-bit snapshot (2013-06-08).

The test programme runs correctly under Fedora 18 x64.

BTW, the man page for ftok(3) states that the second parameter ('proj_id') must be non-zero. Contrary to this, Poco uses zero for 'proj_id'. This is easy enough to patch, but does anyone know the effect of using zero here? If there's no good reason for it then I'll raise a ticket with Poco and get it changed.

Many thanks in advance for looking at this problem,

Dave.

/* Compile: gcc -o poco_ne poco_ne.c
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

/* Error handling. */
void FatalError(const char* const pmsg)
{
	fprintf(stderr, "%s\n", pmsg);
	exit(1);
}

int main()
{
	/* Create a file. */
	const char* const pfilename = "try.txt";
	int fd = open(pfilename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if (fd == -1)
		FatalError("open() failed.");
	close(fd);

	/* Generate a key, using the file we just created. */
	key_t key = ftok(pfilename, 'a');
	if (key == -1)
		FatalError("ftok() failed.");

	/* Get the semaphore set identifier */
	fprintf(stderr, "Trying semget()\n");
	fprintf(stderr, "This causes 'Bad system call (core dumped)' in Cygwin.\n");
	int semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);
	fprintf(stderr, "OK - that worked. semget() returned %i\n", semid);
	return 0;
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]