[comp.bugs.sys5] System V messages problem

rosko@runx.ips.oz (Ross McKay) (10/16/88)

Hello,
	I have been trying to get message passing to work on my Microport
System (System V.2, uPort version 2.3, a '286 box (yes, I know it's hideous,
but it's also cheap)).  I tried using an example programme from Bach's book,
"The Design of the Unix Operating System", shown below.  The problem is that
on the first msgget() call, the operating system return ENOENT, which according
to the manual means "A message queue identifier does not exist for key and
(msgflg & IPC_CREAT) is false."  msgflg & IPC_CREAT is true, however, but
uPort nicely returns the error anyway.

	I am running the kernel with message passing enabled, so I am wondering
just what Microport did to message passing ...

			Jan Mikkelsen
			c/o rosko@runx.ips.oz.AU

------CUT HERE FOR EXAMPLE CODE---8<-----------------------------------------
#include	<sys/types.h>
#include	<sys/ipc.h>
#include	<sys/msg.h>

#define		MSGKEY	75

	struct	msgform
		{
		long	mtype;
		char	mtext[256];
		} msg;

	int	msgid;

main()
{
	int	i, pid, *pint;
	extern	cleanup();

	for(i = 0; i < 20; ++i)
		signal(i, cleanup);

	if((msgid = msgget(MSGKEY, -1)) == -1)
		{
		perror("msgget");	/* error check added by janm */
		exit(1);
		}

	for(;;)
		{
		pint = (int *) msg.mtext;
		pid = *pint;
		printf("server: receive from pid %d\n", pid);
		msg.mtype = pid;
		*pint = getpid();
		msgsnd(msgid, &msg, sizeof(int), 0);
		}
}

cleanup()
{
	msgctl(msgid, IPC_RMID, 0);
	exit();
}

gregg@ihlpb.ATT.COM (Wonderly) (10/19/88)

From article <1794@runx.ips.oz>, by rosko@runx.ips.oz (Ross McKay):
> 
> Hello,
> 	I have been trying to get message passing to work on my Microport
> System.
> .....
>
> ------CUT HERE FOR EXAMPLE CODE---8<-----------------------------------------
> 
> 	for(i = 0; i < 20; ++i)
                      ^^^
PLEASE, PLEASE, PLEASE use NSIG here or something a little more portable.
Signal numbers start at 1 besides...

> 		signal(i, cleanup);
> 
> 	if((msgid = msgget(MSGKEY, -1)) == -1)
                                  ^^^
Try using the actual flag here.  MAKE IT OBVIOUS WHAT THE HECK YOU ARE
DOING.

You are also setting IPC_EXCL, IPC_NOWAIT besides IPC_CREATE.  If the key
already exists, then this will fail with EEXIST.

-- 
Gregg Wonderly
AT&T Bell Laboratories                   DOMAIN: gregg@ihlpb.att.com
IH2D217 - (312) 979-2794                 UUCP:   att!ihlpb!gregg

wietse@wzv.UUCP (Wietse Z. Venema) (10/20/88)

In article <1794@runx.ips.oz> rosko@runx.ips.oz (Ross McKay) writes:
>	I have been trying to get message passing to work on my Microport
>System (System V.2, uPort version 2.3, a '286 box (yes, I know it's hideous,
>but it's also cheap)).  I tried using an example programme from Bach's book,
>[problem description deleted]
>	I am running the kernel with message passing enabled, so I am wondering
>just what Microport did to message passing ...
>[example program deleted]

Before accusing Microport of anything, it would be a good idea 
to lint your program first, then flame about the example program.

    function argument ( number ) used inconsistently
	msgget( arg 1 )   	llib-lc(84) :: example.c(55)
	msgsnd( arg 2 )   	llib-lc(86) :: example.c(68)
	msgsnd( arg 3 )   	llib-lc(86) :: example.c(68)
	msgctl( arg 3 )   	llib-lc(82) :: example.c(74)
-- 
work:	wswietse@eutrc3.uucp	| Eindhoven University of Technology
ditto:	wswietse@heitue5.bitnet	| Mathematics and Computing Science
home:	wietse@wzv.uucp		| 5600 MB Eindhoven, The Netherlands