cygipc ENOSYS patch (was Re: cygipc-1.13pre1)

Jason Tishler jason@tishler.net
Wed Nov 13 06:37:00 GMT 2002


Chuck,

On Tue, Nov 12, 2002 at 02:44:45PM -0500, Charles Wilson wrote:
> The attached src tarball contains cygipc-1.13pre1.  It has been
> reverted to the 32bit key_t treatment (e.g. pre-1.12), but other
> improvements in 1.12 remain.  Please generate your ENOSYS patches --
> if there are more beyond has been posted on the list -- against this.
> That'll make my job easier.

My patch (against cygipc-1.13pre1) changes the following cygipc
functions to return ENOSYS instead of EACCES if ipc-daemon is not
running:

    msgctl()
    msgget()
    msgrcv()
    msgsnd()

    semctl()
    semget()
    semop()

    shmat()
    shmctl()
    shmget()
    shmdt()

Since I could only (easily) test semget() and shmget() under PostgreSQL,
I decided to write a simply test program, cygtest.cc, to exercise all of
my cygipc changes.

Attached are the following files:

    o cygipc-1.13pre1.patch: ENOSYS patch
    o cygipc-1.13pre1.ChangeLog: corresponding ChangeLog entry
    o cygtest.cc: test program
    o cygtest.out: test program output before patch
    o cygtest2.out: test program output after patch

Thanks,
Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-------------- next part --------------
diff -rup cygipc-1.13pre1.orig/msg.c cygipc-1.13pre1/msg.c
--- cygipc-1.13pre1.orig/msg.c	2001-02-10 18:50:01.000000000 -0500
+++ cygipc-1.13pre1/msg.c	2002-11-13 07:44:19.000000000 -0500
@@ -168,8 +168,8 @@ static int findkey (key_t key)
 
 	if (msg_connect() == 0)
 	{
-debug_printf("findkey : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("findkey : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	} 
 	for (id = 0; id <= max_msqid; id++) { 
 		if (msgque[id] == IPC_UNUSED)
@@ -212,8 +212,8 @@ debug_printf("msgsnd : return -EFAULT\n"
 	LBloc = 0 ;
 	if (msg_connect() == 0)
 	{
-debug_printf("msgsnd : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("msgsnd : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	id = (unsigned int) msqid % MSGMNI;
@@ -251,8 +251,8 @@ slept:
 	{
 	 if (msg_connect() == 0)
 	 {
-debug_printf("msgsnd : return -EACCES\n");
- 	  CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("msgsnd : return -ENOSYS\n");
+ 	  CYGWIN_IPCNT_RETURN (-ENOSYS) ;
  	 }
 	}
 
@@ -339,8 +339,8 @@ debug_printf("msgrcv : return -EFAULT\n"
 	LBloc = 0 ;
 	if (msg_connect() == 0)
 	{
-debug_printf("msgrcv : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("msgrcv : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	id = (unsigned int) msqid % MSGMNI;
@@ -373,8 +373,8 @@ debug_printf("msgrcv : return -EIDRM\n")
 		{
 		 if (msg_connect() == 0)
 		 {
-debug_printf("msgrcv : return -EACCES\n");
-	 	  CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("msgrcv : return -ENOSYS\n");
+	 	  CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	 	 }
 		}
 
@@ -522,8 +522,8 @@ static int newque (key_t key, int msgflg
 debug_printf("newque : key=%X msgflg=%X\n",key,msgflg);
 	if (msg_connect() == 0)
 	{
-debug_printf("newque : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("newque : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	for (id = 0; id < MSGMNI; id++)
@@ -590,8 +590,8 @@ debug_printf("msgget : return -EEXIST\n"
 	}
 	if (msg_connect() == 0)
 	{
-debug_printf("newque : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("newque : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	msq = (struct msqid_ds *)
@@ -655,8 +655,8 @@ debug_printf("msgctl : return -EINVAL\n"
 
 	if (msg_connect() == 0)
 	{
-debug_printf("msgctl : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("msgctl : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	id = (unsigned int) msqid % MSGMNI;
diff -rup cygipc-1.13pre1.orig/sem.c cygipc-1.13pre1/sem.c
--- cygipc-1.13pre1.orig/sem.c	2001-11-26 18:41:32.000000000 -0500
+++ cygipc-1.13pre1/sem.c	2002-11-13 07:44:41.000000000 -0500
@@ -326,8 +326,8 @@ debug_printf("semget : return -EINVAL\n"
 
 	if (sem_connect() == 0)
 	{
-debug_printf("semget : return -EACCES\n");
-	    CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("semget : return -ENOSYS\n");
+	    CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	if (key == IPC_PRIVATE)
@@ -385,8 +385,8 @@ debug_printf("do_semop : sma=%p, sops=%p
 		{
 		    if (sem_connect() == 0)
 		    {
-debug_printf("do_semop : return -EACCES\n");
-			CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("do_semop : return -ENOSYS\n");
+			CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 		    }
     	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
 				sop->sem_op ;
@@ -402,8 +402,8 @@ debug_printf("do_semop : return -EAGAIN\
 			}
 			if (sem_connect() == 0)
 			{
-debug_printf("do_semop : return -EACCES\n");
-			    CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("do_semop : return -ENOSYS\n");
+			    CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 			}
 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op;
 			sem_deconnect() ;
@@ -419,8 +419,8 @@ debug_printf("do_semop : return -EACCES\
  
 			if (sem_connect() == 0)
 			{
-debug_printf("do_semop : return -EACCES\n");
-			    CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("do_semop : return -ENOSYS\n");
+			    CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 			}
 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op ;
 			    sem_deconnect() ;
@@ -488,8 +488,8 @@ debug_printf("semctl : return -EINVAL\n"
 
 	if (sem_connect() == 0)
 	{
-debug_printf("semctl : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("semctl : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	switch (cmd) {
@@ -740,8 +740,8 @@ debug_printf("semop : return -EFAULT\n")
 
 	if (sem_connect() == 0)
 	{
-debug_printf("semop : return -EACCES\n");
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("semop : return -ENOSYS\n");
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 	sem_deconnect() ;
 
diff -rup cygipc-1.13pre1.orig/shm.c cygipc-1.13pre1/shm.c
--- cygipc-1.13pre1.orig/shm.c	2001-02-10 18:50:01.000000000 -0500
+++ cygipc-1.13pre1/shm.c	2002-11-13 07:45:50.000000000 -0500
@@ -262,8 +262,8 @@ int shmget (key_t key, int size, int shm
 debug_printf("shmget : key=%p size=%X shmflg=%X\n",key,size,shmflg);	
 	if (shm_connect() == 0)
 	{
-debug_printf("shmget : return -EACCES\n");
-	    CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("shmget : return -ENOSYS\n");
+	    CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	if (size < 0 )
@@ -344,8 +344,8 @@ debug_printf("shmctl : return -EINVAL\n"
 
 	if (shm_connect() == 0)
 	{
-debug_printf("shmctl : return -EACCES\n");	
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("shmctl : return -ENOSYS\n");	
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	id = (unsigned int) shmid % SHMMNI;
@@ -508,11 +508,11 @@ char *shmat (int shmid, char *shmaddr, i
 debug_printf("shmat : shmid=%X shmaddr=%p shmflag=%X\n",shmid,shmaddr,shmflg);	
 	if (shm_connect() == 0)
 	{
-debug_printf("shmat : return -EACCESS\n");	
+debug_printf("shmat : return -ENOSYS\n");	
 #if SHMAT_LINUX
-	 CYGWIN_IPCNT_RETURN (-EACCES) ;
+	 CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 #else
-	 errno=EACCES;
+	 errno=ENOSYS;
 	 return (char *)-1;
 #endif
 	}
@@ -614,8 +614,8 @@ debug_printf("shmdt : shmaddr=%p\n",shma
 
 	if (shm_connect() == 0)
 	{
-debug_printf("shmdt : return -EACCES\n");	
-	    CYGWIN_IPCNT_RETURN (-EACCES) ;
+debug_printf("shmdt : return -ENOSYS\n");	
+	    CYGWIN_IPCNT_RETURN (-ENOSYS) ;
 	}
 
 	for (LId = 0; LId < SHMMNI; LId++)
-------------- next part --------------
Wed Nov 13 08:46:17 2002  <jason@tishler.net>

	* msg.c (findkey): Return ENOSYS instead of EACCES if ipc-daemon is
	not running.
	(msgsnd): Ditto.
	(msgrcv): Ditto.
	(newque): Ditto.
	(msgget): Ditto.
	(msgctl): Ditto.
	* sem.c (semget): Ditto:
	(do_semop): Ditto.
	(semctl): Ditto.
	(semop): Ditto.
	* shm.c (shmget): Ditto:
	(shmctl): Ditto.
	(shmat): Ditto.
	(shmdt): Ditto.
-------------- next part --------------
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/msg.h>

void check(const char* name, int status);
void check2(const char* name, const void* status);

int
main()
{
	// Test msgctl
	int msqid = 0;
	int cmd = 0;
	struct msqid_ds buf2;
	int status = msgctl(msqid, cmd, &buf2);
	check("msgctl", status);

	// Test msgget
	key_t key = IPC_PRIVATE;
	int msgflg = 0;
	status = msgget(key, msgflg);
	check("msgget", status);

	// Test msgrcv
	struct msgbuf msgp;
	msgp.mtype = 1;
	size_t msgsz = 0;
	long msgtyp = 0;
	status = msgrcv(msqid, &msgp, msgsz, msgtyp, msgflg);
	check("msgrcv", status);

	// Test msgsnd
	status = msgsnd(msqid, &msgp, msgsz, msgflg);
	check("msgsnd", status);
	printf("\n");

	// Test semctl
	int semid = 0;
	int semnum = 0;
	status = semctl(semid, semnum, cmd);
	check("semctl", status);

	// Test semget
	int nsems = 0;
	int semflg = 0;
	status = semget(key, nsems, semflg);
	check("semget", status);

	// Test semop
	struct sembuf sops;
	unsigned nsops = 1;
	status = semop(semid, &sops, nsops);
	check("semop", status);
	printf("\n");

	// Test shmat
	int shmid = 0;
	char* shmaddr = 0;
	int shmflg = 0;
	void* status2 = shmat(shmid, shmaddr, shmflg);
	check2("shmat", status2);

	// Test shmctl
	struct shmid_ds buf;
	status = shmctl(shmid, cmd, &buf);
	check("shmctl", status);

	// Test shmget
	int size = 0;
	status = shmget(key, size, shmflg);
	check("shmget", status);

	// Test shmdt
	status = shmdt(shmaddr);
	check("shmdt", status);
}

void
check(const char* name, int status)
{
	if (status < 0)
		printf("%s() failed: %s (errno = %d)\n", name, strerror(errno), errno);
}

void
check2(const char* name, const void* status)
{
	if (status == (const void*) -1)
		printf("%s() failed: %s (errno = %d)\n", name, strerror(errno), errno);
}
-------------- next part --------------
msgctl() failed: Permission denied (errno = 13)
msgget() failed: Permission denied (errno = 13)
msgrcv() failed: Permission denied (errno = 13)
msgsnd() failed: Permission denied (errno = 13)

semctl() failed: Permission denied (errno = 13)
semget() failed: Permission denied (errno = 13)
semop() failed: Permission denied (errno = 13)

shmat() failed: Permission denied (errno = 13)
shmctl() failed: Permission denied (errno = 13)
shmget() failed: Permission denied (errno = 13)
shmdt() failed: Permission denied (errno = 13)
-------------- next part --------------
msgctl() failed: Function not implemented (errno = 88)
msgget() failed: Function not implemented (errno = 88)
msgrcv() failed: Function not implemented (errno = 88)
msgsnd() failed: Function not implemented (errno = 88)

semctl() failed: Function not implemented (errno = 88)
semget() failed: Function not implemented (errno = 88)
semop() failed: Function not implemented (errno = 88)

shmat() failed: Function not implemented (errno = 88)
shmctl() failed: Function not implemented (errno = 88)
shmget() failed: Function not implemented (errno = 88)
shmdt() failed: Function not implemented (errno = 88)

-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list