Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* Digital Unix message queue programming problem!!
@ 1997-02-27  5:00 Kok Fock Seng
  1997-02-27  5:00 ` Jeremy D. Levine
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Kok Fock Seng @ 1997-02-27  5:00 UTC (permalink / raw)



Hi out there,

I am writing a program utilize the message queue (IPC) feature
in Dec Unix. 

The scenario is the queue can be created using msgget().
I use ipcs to view it. By when I call msgsnd(), it will
block there (no return) if I set the flag to 0. If I
set the flag to IPC_NOWAIT, it will return with errno = 35.
Well, somehow, the data I want to send cannot get thro.
I have check all the manual and man page. No finding.
Is the any system parameters that I need to set?

TIA.

Here's my full test code :

#include  <termio.h>
#include  <sys/types.h>
#include  <fcntl.h>
#include  <stdio.h>
#include  <sys/ipc.h>
#include  <sys/msg.h>

int   nIndexQueueId;            /* message queue id  for INDEX */

extern int   errno;      

typedef  struct {
        long    msgtype;         /* queue type           */
        char    msgbuf [ 100 ];  /* contains the data    */
} MSGQ;

MSGQ m;

void main ()
{
  int   messageid;

 m.msgtype = 1L ;
 strcpy(m.msgbuf,"This is a test msg!") ;

 if  (( messageid = msgget ((key_t)(6000L), IPC_CREAT)) == -1 ) 
       	exit (-1);
 fprintf(stderr, "[%d]", messageid);

  if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, 0) == -1)
	fprintf(stderr, "Test Queue got problem!\n err [%d]", errno);
  else fprintf(stderr, "Test Queue OK!\n");
  printf(stderr, "[%d]\n", errno) ;

}

Regards,
Kok Fock Seng
fskok@silicon.net.my
System Administrator
Silicon Communications.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-27  5:00 Digital Unix message queue programming problem!! Kok Fock Seng
  1997-02-27  5:00 ` Jeremy D. Levine
  1997-02-27  5:00 ` Lawrence Kirby
@ 1997-02-27  5:00 ` Kok Fock Seng
  1997-02-27  5:00 ` Charles M Richmond
  3 siblings, 0 replies; 7+ messages in thread
From: Kok Fock Seng @ 1997-02-27  5:00 UTC (permalink / raw)



Kok Fock Seng wrote:
> 
> Hi out there,
Something extra to at the the previous posting :
I tested the same code on Solaris 2.5. It works!!
So how do you guys think?
> 
> I am writing a program utilize the message queue (IPC) feature
> in Dec Unix.
> 
> The scenario is the queue can be created using msgget().
> I use ipcs to view it. By when I call msgsnd(), it will
> block there (no return) if I set the flag to 0. If I
> set the flag to IPC_NOWAIT, it will return with errno = 35.
> Well, somehow, the data I want to send cannot get thro.
> I have check all the manual and man page. No finding.
> Is the any system parameters that I need to set?
> 
> TIA.
> 
> Here's my full test code :
> 
> #include  <termio.h>
> #include  <sys/types.h>
> #include  <fcntl.h>
> #include  <stdio.h>
> #include  <sys/ipc.h>
> #include  <sys/msg.h>
> 
> int   nIndexQueueId;            /* message queue id  for INDEX */
> 
> extern int   errno;
> 
> typedef  struct {
>         long    msgtype;         /* queue type           */
>         char    msgbuf [ 100 ];  /* contains the data    */
> } MSGQ;
> 
> MSGQ m;
> 
> void main ()
> {
>   int   messageid;
> 
>  m.msgtype = 1L ;
>  strcpy(m.msgbuf,"This is a test msg!") ;
> 
>  if  (( messageid = msgget ((key_t)(6000L), IPC_CREAT)) == -1 )
>         exit (-1);
>  fprintf(stderr, "[%d]", messageid);
> 
>   if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, 0) == -1)
>         fprintf(stderr, "Test Queue got problem!\n err [%d]", errno);
>   else fprintf(stderr, "Test Queue OK!\n");
>   printf(stderr, "[%d]\n", errno) ;
> 
> }
> 
> Regards,
> Kok Fock Seng
> fskok@silicon.net.my
> System Administrator
> Silicon Communications.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-27  5:00 Digital Unix message queue programming problem!! Kok Fock Seng
                   ` (2 preceding siblings ...)
  1997-02-27  5:00 ` Kok Fock Seng
@ 1997-02-27  5:00 ` Charles M Richmond
  3 siblings, 0 replies; 7+ messages in thread
From: Charles M Richmond @ 1997-02-27  5:00 UTC (permalink / raw)
  To: fskok


Your test code worked fine on Dunix 3.2d, SunOS 4.1.4, Ultrix 4.4,
and Solaris 2.5.  The only error was in running as non-root, which
caused an errno 13 (access).



Kok Fock Seng wrote:
> 
> Hi out there,
> 
> I am writing a program utilize the message queue (IPC) feature
> in Dec Unix.
> 
> The scenario is the queue can be created using msgget().
> I use ipcs to view it. By when I call msgsnd(), it will
> block there (no return) if I set the flag to 0. If I
> set the flag to IPC_NOWAIT, it will return with errno = 35.
> Well, somehow, the data I want to send cannot get thro.
> I have check all the manual and man page. No finding.
> Is the any system parameters that I need to set?
> 
> TIA.
> 
> Here's my full test code :
> 
> #include  <termio.h>
> #include  <sys/types.h>
> #include  <fcntl.h>
> #include  <stdio.h>
> #include  <sys/ipc.h>
> #include  <sys/msg.h>
> 
> int   nIndexQueueId;            /* message queue id  for INDEX */
> 
> extern int   errno;
> 
> typedef  struct {
>         long    msgtype;         /* queue type           */
>         char    msgbuf [ 100 ];  /* contains the data    */
> } MSGQ;
> 
> MSGQ m;
> 
> void main ()
> {
>   int   messageid;
> 
>  m.msgtype = 1L ;
>  strcpy(m.msgbuf,"This is a test msg!") ;
> 
>  if  (( messageid = msgget ((key_t)(6000L), IPC_CREAT)) == -1 )
>         exit (-1);
>  fprintf(stderr, "[%d]", messageid);
> 
>   if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, 0) == -1)
>         fprintf(stderr, "Test Queue got problem!\n err [%d]", errno);
>   else fprintf(stderr, "Test Queue OK!\n");
>   printf(stderr, "[%d]\n", errno) ;
> 
> }
> 
> Regards,
> Kok Fock Seng
> fskok@silicon.net.my
> System Administrator
> Silicon Communications.

-- 
***********************************************************************
*  Charles Richmond    Integrated International Systems Corporation   *
*  cmr@iisc.com        cmr@koibito.iisc.com  cmr@shore.net            *
*  UNIX Internals, I18N, L10N, X, Realtime Imaging, and  Custom S/W   *
*  One Longfellow Place Suite 3309 , Boston , Ma. USA 02114-2431      *
*  (617) 723 7695    (617) 367 3151        FAX (617) 723 6861         *
***********************************************************************



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-27  5:00 Digital Unix message queue programming problem!! Kok Fock Seng
  1997-02-27  5:00 ` Jeremy D. Levine
@ 1997-02-27  5:00 ` Lawrence Kirby
  1997-02-28  5:00   ` Andy Knight
  1997-02-27  5:00 ` Kok Fock Seng
  1997-02-27  5:00 ` Charles M Richmond
  3 siblings, 1 reply; 7+ messages in thread
From: Lawrence Kirby @ 1997-02-27  5:00 UTC (permalink / raw)



In article <33162B5F.437B@silicon.net.my>
           fskok@silicon.net.my "Kok Fock Seng" writes:

>Hi out there,
>
>I am writing a program utilize the message queue (IPC) feature
>in Dec Unix. 

Note that your question was not about the C language so it wasnt' really
appropriate to cross-post to comp.lang.c. (Removed from follow-ups)

>void main ()

Since you have cross-posted to comp.lang.c I'd just point out that C defines
main as a function returning int. More specifically as either:

int main(void)

or

int main(int argc, char *argv[])

>{
>  int   messageid;
>
> m.msgtype = 1L ;
> strcpy(m.msgbuf,"This is a test msg!") ;
>
> if  (( messageid = msgget ((key_t)(6000L), IPC_CREAT)) == -1 ) 

(pretending I'm reading this in comp.unix.programmer)

There is a problem here in that you failed to give any read/write
permissions on the queue. Check your man page more carefully for what
the 2nd argument should be (it is basically a collection of bit flags
similar to the 2nd argument of open())

>        exit (-1);

Why -1? C defines 0, EXIT_SUCCESS and EXIT_FAILURE. Unix essentially
takes the lower order 8 bits of the value (i.e. a value 0-255) although
some shells may have a weirdness of treating this like a signed char.

> fprintf(stderr, "[%d]", messageid);
>
>  if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, 0) == -1)
>        fprintf(stderr, "Test Queue got problem!\n err [%d]", errno);
>  else fprintf(stderr, "Test Queue OK!\n");
>  printf(stderr, "[%d]\n", errno) ;

You need to make up your mind whether to printf this to stdout or
fprintf it to stderr! :-)

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-27  5:00 Digital Unix message queue programming problem!! Kok Fock Seng
@ 1997-02-27  5:00 ` Jeremy D. Levine
  1997-02-27  5:00 ` Lawrence Kirby
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jeremy D. Levine @ 1997-02-27  5:00 UTC (permalink / raw)



Kok Fock Seng wrote:
> 
> 
>  if  (( messageid = msgget ((key_t)(6000L), IPC_CREAT|0660)) == -1 )
>         exit (-1);                                    ^^^^^
>  fprintf(stderr, "[%d]", messageid);
> 
>   if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, IPC_NOWAIT) == -1)
>                                                     ^^^^^^^^^^
I think if you do  a ipcs -q  you will you that the queue you created
has no mode bits set ( ie. no read or write bits ). Use ipcrm -q <num>
to remove the queue and change you program to match the above lines.
I tried it and it worked.  

			- jeremy levine - levine@amarex.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-27  5:00 ` Lawrence Kirby
@ 1997-02-28  5:00   ` Andy Knight
  1997-02-28  5:00     ` Stephen Baynes
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Knight @ 1997-02-28  5:00 UTC (permalink / raw)



> Why -1? C defines 0, EXIT_SUCCESS and EXIT_FAILURE.

Could you explain this statement to me?

The X/Open Portability Guide says about msgget() that "On successful
completion, the function msgget() returns a non-negative integer, namely a
message queue identifier; otherwise it returns -1 and errno is set to
indicate the error".

Given that definition I would personally test for < 0 rather than == -1 but
its hard to criticise the explicit test.


-- 
Andy Knight




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Digital Unix message queue programming problem!!
  1997-02-28  5:00   ` Andy Knight
@ 1997-02-28  5:00     ` Stephen Baynes
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Baynes @ 1997-02-28  5:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]


Andy Knight (KnighA@tetraworld.com) wrote:
: > Why -1? C defines 0, EXIT_SUCCESS and EXIT_FAILURE.

: Could you explain this statement to me?

: The X/Open Portability Guide says about msgget() that "On successful
: completion, the function msgget() returns a non-negative integer, namely a
: message queue identifier; otherwise it returns -1 and errno is set to
: indicate the error".

: Given that definition I would personally test for < 0 rather than == -1 but
: its hard to criticise the explicit test.

If you had not cliped the line before th eone you quoted it would be obvious. 
The missing line is:

           exit (-1);

So the program exit status is being talked about. Not the exit status from 
msgget().


--
Stephen Baynes    MBCS  CEng                Stephen.Baynes@soton.sc.philips.com
Philips Semiconductors Ltd                  
Southampton SO15 0DJ                        +44 (01703) 316431
United Kingdom                              My views are my own.
Do you use ISO8859-1? Yes if you see � as copyright, � as division and � as 1/2.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-02-28  5:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-02-27  5:00 Digital Unix message queue programming problem!! Kok Fock Seng
1997-02-27  5:00 ` Jeremy D. Levine
1997-02-27  5:00 ` Lawrence Kirby
1997-02-28  5:00   ` Andy Knight
1997-02-28  5:00     ` Stephen Baynes
1997-02-27  5:00 ` Kok Fock Seng
1997-02-27  5:00 ` Charles M Richmond

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox