Sponsored Content
Top Forums Programming Msgget(2) returns 0 - a workaround fix Post 302906955 by mr_bandit on Tuesday 24th of June 2014 07:15:20 PM
Old 06-24-2014
errno after msgget() returns 0

To be honest, I did not look at errno after msgget() returned 0 (It was in the wee early hours and I had bigger fish..). I will try that and get back with the results. This will also tell me if the original key returns 0.

The interesting thing is we loaded a *way* earlier version of the code to test a completely different thing. I jut did a ipcs and got

Code:
------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x000000f0 0          gfi        666        0            0

where you can see msgqid == 0 and the system seems to be performing happily (at least this part of it). This would seem to enforce the observation / theory that once the msgqid becomes 0, it stays 0. No complaints from msgsnd() or msgrcv().

So - this may be a brainfart on my part. After all, I did have another bug throwing a SIGSEGV at the same time. And it was very late/early. If it is a brainfart, my apologies.

Again, this an unpatched Ubuntu 8

@achenlehas an interesting suggestion. I had not thought of setting errno to a value before making the call. The question then becomes: why not set it to (-1)? errno values are positive, at least on Linux. (I seem to remember them being negative numbers on BSD 4.1, but that was a *long* time ago...)
 

9 More Discussions You Might Find Interesting

1. Programming

about msgget troble

hi,all i have in trouble about msgget. i create a queue and the program like blow: openMsg( pid_t key ) { .... int msgid; .... msgid=msgget(key,IPC_CREAT|IPC_EXCL|0666) if( msgid<=0 ){ fprintf( stdout,"%s,%d",strerror(errno),errno ); return -1; ... (9 Replies)
Discussion started by: subrain
9 Replies

2. Shell Programming and Scripting

find & sed -i work fine. Now need -i workaround for old OS.

I have a script that does a search and replace on a tree using find, xargs and sed that looks something like this. find . -type f -print0 | xargs -0 sed -i 's/fromthis/tothis/g' Now this works fine on new versions on Linux but I need to make the script work on an old RAQ550 that has an older... (3 Replies)
Discussion started by: simonb
3 Replies

3. Programming

Problem with msgget()

Hi, I am having problem with msgget() function. Here is the problem that I am having on Unix : I have two processes sender and receiver. Sender generates queue (msgget()) with some key e.g. 938, for output. Receiver reads from the same queue. i.e. receiver also tries to get queue... (2 Replies)
Discussion started by: Ashwini
2 Replies

4. UNIX for Dummies Questions & Answers

Workaround for macros in sftp command

Hi, I've some existing scripts wherein am using ftp + .netrc. I've defined my macros in .netrc file. I want to switch to sftp now but it seems it doesn't support macros and .netrc and it gives "command invalid" error. Is there any other alternative? Note: I don't want help for... (1 Reply)
Discussion started by: ps51517
1 Replies

5. Windows & DOS: Issues & Discussions

Samba trouble shoot / workaround ?

Hello, I've setup a ubuntu 10.04 server running samba 3.4.7 as domain controler / file server at a customer site, that works great most of the time but I face a random problem. Of course I'm never on the site when the problem occurs, so I cannot investigate in real time. What happens is that... (2 Replies)
Discussion started by: Manu.b
2 Replies

6. Shell Programming and Scripting

Calculation returns no value

#/bin/sh ..... #convert memory to MB let "mmsize_a= ($mmsize)/256" let "mminuse_a= ($mminuse)/256" let "mmfree_a= ($mmsize_a -$mminuse_a)" let "mmfreepercent= (($mmfree_a)/($mmsize_a))*100" # #format output echo "\n\n######################" >>$sndFile echo "\n$sysName Total Memory usage"... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

7. Programming

msgget message queue always get permission denied

I want to use msgget() to obtain a message queue between two processes, here is my code: the first one create the mq, the second one open it and add a message to it. But when I execute the second one, I get permission denied. I've already desperately tried everything I can think of to solve this... (2 Replies)
Discussion started by: tefino
2 Replies

8. UNIX for Advanced & Expert Users

stuck in CLOSE_WAIT Solaris 10 - Patch and workaround

Solaris 10 Sparc: When you got a connection locking a tcp/port, and the status is CLOSE_WAIT (for ever :wall:), you just use the tcpdrop, to close the connection. This is a OS bug. I wrote the bug id bellow: BUG-ID 6468753 connections stuck in CLOSE_WAIT The patch that's correct the bug:... (0 Replies)
Discussion started by: thiagofborn
0 Replies

9. AIX

AIO workaround AIX 5.3 to AIX 7.1

Hello Folks, Facing a problem starting Apache Services on AIX 7.1 This is the error i'm getting /oraapp/prodora/iAS/Apache/Apache/bin/apachectl start: httpd started Syntax error on line 17 of /oraapp/prodora/iAS/Apache/modplsql/cfg/plsql_pls.conf: Cannot load... (0 Replies)
Discussion started by: filosophizer
0 Replies
MSGOP(2)						     Linux Programmer's Manual							  MSGOP(2)

NAME
msgop - message operations SYNOPSIS
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg); DESCRIPTION
To send or receive a message, the calling process allocates a structure of the following general form: struct msgbuf { long mtype; /* message type, must be > 0 */ char mtext[1]; /* message data */ }; The mtext field is an array (or other structure) whose size is specified by msgsz, a non-negative integer value. Messages of zero length (i.e., no mtext field) are permitted. The mtype field must have a strictly positive integer value that can be used by the receiving process for message selection (see the section about msgrcv). The calling process must have write permission to send and read permission to receive a message on the queue. The msgsnd system call appends a copy of the message pointed to by msgp to the message queue whose identifier is specified by msqid. If sufficient space is available on the queue, msgsnd succeeds immediately. (The queue capacity is defined by the msg_bytes field in the associated data structure for the message queue. During queue creation this field is initialised to MSGMNB bytes, but this limit can be modified using msgctl.) If insufficient space is available on the queue, then the default behaviour of msgsnd is to block until space becomes available. If IPC_NOWAIT is asserted in msgflg then the call instead fails with the error EAGAIN. A blocked msgsnd call may also fail if the queue is removed (in which case the system call fails with errno set to EIDRM), or a signal is caught (in which case the system call fails with errno set to EINTR). (msgsnd and msgrcv are never automatically restarted after being interrupted by a signal handler, regardless of the setting of the SA_RESTART flag when establishing a signal handler.) Upon successful completion the message queue data structure is updated as follows: msg_lspid is set to the process ID of the calling process. msg_qnum is incremented by 1. msg_stime is set to the current time. The system call msgrcv reads a message from the message queue specified by msqid into the msgbuf pointed to by the msgp argument, removing the read message from the queue. The argument msgsz specifies the maximum size in bytes for the member mtext of the structure pointed to by the msgp argument. If the mes- sage text has length greater than msgsz, then if the msgflg argument asserts MSG_NOERROR, the message text will be truncated (and the trun- cated part will be lost), otherwise the message isn't removed from the queue and the system call fails returning with errno set to E2BIG. The argument msgtyp specifies the type of message requested as follows: If msgtyp is 0, then the first message in the queue is read. If msgtyp is greater than 0, then the first message on the queue of type msgtyp is read, unless MSG_EXCEPT was asserted in msgflg, in which case the first message on the queue of type not equal to msgtyp will be read. If msgtyp is less than 0, then the first message on the queue with the lowest type less than or equal to the absolute value of msg- typ will be read. The msgflg argument asserts none, one or more (or-ing them) of the following flags: IPC_NOWAIT For immediate return if no message of the requested type is on the queue. The system call fails with errno set to ENOMSG. MSG_EXCEPT Used with msgtyp greater than 0 to read the first message on the queue with message type that differs from msgtyp. MSG_NOERROR To truncate the message text if longer than msgsz bytes. If no message of the requested type is available and IPC_NOWAIT isn't asserted in msgflg, the calling process is blocked until one of the following conditions occurs: A message of the desired type is placed on the queue. The message queue is removed from the system. In this case the system call fails with errno set to EIDRM. The calling process catches a signal. In this case the system call fails with errno set to EINTR. Upon successful completion the message queue data structure is updated as follows: msg_lrpid is set to the process ID of the calling process. msg_qnum is decremented by 1. msg_rtime is set to the current time. RETURN VALUE
On a failure both functions return -1 with errno indicating the error, otherwise msgsnd returns 0 and msgrvc returns the number of bytes actually copied into the mtext array. ERRORS
When msgsnd fails, at return errno will be set to one among the following values: EAGAIN The message can't be sent due to the msg_qbytes limit for the queue and IPC_NOWAIT was asserted in mgsflg. EACCES The calling process has no write permission on the message queue. EFAULT The address pointed to by msgp isn't accessible. EIDRM The message queue was removed. EINTR Sleeping on a full message queue condition, the process caught a signal. EINVAL Invalid msqid value, or nonpositive mtype value, or invalid msgsz value (less than 0 or greater than the system value MSGMAX). ENOMEM The system has not enough memory to make a copy of the supplied msgbuf. When msgrcv fails, at return errno will be set to one among the following values: E2BIG The message text length is greater than msgsz and MSG_NOERROR isn't asserted in msgflg. EACCES The calling process does not have read permission on the message queue. EFAULT The address pointed to by msgp isn't accessible. EIDRM While the process was sleeping to receive a message, the message queue was removed. EINTR While the process was sleeping to receive a message, the process received a signal that had to be caught. EINVAL Illegal msgqid value, or msgsz less than 0. ENOMSG IPC_NOWAIT was asserted in msgflg and no message of the requested type existed on the message queue. NOTES
The followings are system limits affecting a msgsnd system call: MSGMAX Maximum size for a message text: the implementation set this value to 8192 bytes. MSGMNB Default maximum size in bytes of a message queue: 16384 bytes. The super-user can increase the size of a message queue beyond MSGMNB by a msgctl system call. The implementation has no intrinsic limits for the system wide maximum number of message headers (MSGTQL) and for the system wide maximum size in bytes of the message pool (MSGPOOL). CONFORMING TO
SVr4, SVID. NOTE
The pointer argument is declared as struct msgbuf * with libc4, libc5, glibc 2.0, glibc 2.1. It is declared as void * (const void * for msgsnd()) with glibc 2.2, following the SUSv2. SEE ALSO
ipc(5), msgctl(2), msgget(2), msgrcv(2), msgsnd(2) Linux 2.4.18 2002-06-01 MSGOP(2)
All times are GMT -4. The time now is 01:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy