utime returning -1 BAD File DEscriptor


 
Thread Tools Search this Thread
Top Forums Programming utime returning -1 BAD File DEscriptor
# 8  
Old 01-28-2011
Hmmmm. EFAULT is a really strange error code for it to give you.

Your name looks correct, as man mq_overview demands it, to wit, "a null-terminated string of up to NAME_MAX (i.e., 255) characters consisting of an initial slash, followed by one or more characters, none of which are slashes."

Your permissions and flags also look sane.

What's left? buf. Try opening with NULL instead of &buf.

mq_attr has at least four members:
Code:
           struct mq_attr {
               long mq_flags;       /* Flags: 0 or O_NONBLOCK */
               long mq_maxmsg;      /* Max. # of messages on queue */
               long mq_msgsize;     /* Max. message size (bytes) */
               long mq_curmsgs;     /* # of messages currently in queue */
           };

...but you don't set mq_flags could contain garbage. mq_curmsgs probably doesn't care what's in it but to be sure I'd just blank the whole thing with memset(&buf, 0, sizeof(buf)); then set the things I want.
# 9  
Old 01-28-2011
Well, it looks like you are following an example, so perhaps there is a permission or name collision problem with PATH. Try flags 0 if it exists.
Chapter 6. Message Queues
# 10  
Old 02-02-2011
Hi All,
Thanks for your time and valuable suggestions. For the last few days i was out of station. So could not reply to your post. Sorry for the delay in my response.
@Corona688 : I tried using NULL and also with tried clearing buf with memset. But it is giving the same old error.
Is there any other hidden problems? It is a critical part of my project. Please help me out.
Regards,
Parvathy
# 11  
Old 02-02-2011
The following code works for me:

Code:
$ cat mq.c
#include <fcntl.h>           /* For O_* constants */
#include <sys/stat.h>        /* For mode constants */
#include <mqueue.h>

#include <stdio.h>
#include <string.h>

mqd_t mqopen2(const char * pName,
                    unsigned long Flags,
                    long  maxMsg,
                    long  msgSz);

int main(void)
{
        mqd_t m=mqopen2(NULL, 0, 16, 1024);

        printf("mq is %d\n", m);

        mq_close(m);
}

mqd_t mqopen2(const char * pName,
                    unsigned long Flags,
                    long  maxMsg,
                    long  msgSz)
{
   int perms = 0600;          /* permissions */
   int oflags= O_RDWR| O_CREAT;
   int rd=0, wr=0;            /* -r and -w options */
   mqd_t mqd;                 /* returned msg queue descriptor */
   int c;
   char *path="/iothread8";                /* ->first non-option argument */
   struct mq_attr buf;        /* buffer for stat info */

   memset(&buf, 0, sizeof(buf)); // WILL NOT WORK without this!

   buf.mq_msgsize = msgSz;
   buf.mq_maxmsg = maxMsg;
   buf.mq_flags = Flags;

   /* while */
   //if (optind < argc)
   //   path = argv[optind]; /* first non-option argument */
   //else
   //   { printf("Queue pathname required\n"); return -1; }
   mqd = mq_open(path,oflags,perms,&buf);
   if (-1 != mqd)
   {
    printf("Reached inside the loop\n");

      if ( ! mq_getattr(mqd,&buf) )
      {
         printf("flags: 0x%lx  maxmsg: %ld  msgsize: %ld  curmsgs: %ld\n",
         buf.mq_flags, buf.mq_maxmsg, buf.mq_msgsize, buf.mq_curmsgs);
      }
      else
         perror("mq_getattr()");
   }
   else
      perror("mq_open()");

   return mqd;
}
$ gcc mq.c -o mq -lrt
$ ./mq
Reached inside the loop
flags: 0x0  maxmsg: 10  msgsize: 8192  curmsgs: 0
mq is 3
$

It doesn't give you the sizes you want but it does go... Try it in a .c file by itself like above. I'm beginning to suspect the problem isn't related to message queues but an error somewhere else in the larger part of your code (the part we of course haven't seen).
# 12  
Old 02-03-2011
Hi,
@Corona688: Yes you are ryt. when i tried in a seperate it is working perfectly fine. So now how can i debug it. it is code base of more than 500 classes. So can you please suggest some insights for me to start with.
# 13  
Old 02-03-2011
I can't help you with code I can't see.

On reflection, I think EFAULT implies you have memory corruption somewhere that's causing things to get fed invalid pointers. Check every pointer and reference (including class pointers and references) in the call chain leading up to mqopen2 to make sure they're all sane.
# 14  
Old 02-03-2011
Also, you can truss/tusc/strace to get a better idea of what it was up to.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bad file descriptor - error with sed

I'm learning SED command. And while doing that i got to this place where i'm taking a copy of my existing file. The code i used is - sed -n '/Storm/ w Storm.txt' books.txt As expected, the file 'books.txt' is read , and lines with 'Storm' is put in to the new file 'Storm.txt'. However, it also... (4 Replies)
Discussion started by: justo
4 Replies

2. Solaris

Bad exchange descriptor : not able to remove files under zpool

Hi , One of my zone went down and when i booted it up i could see the pool in degraded state with some check sum errors . we have brought the pool online after scrubbing. But few files are showing this error Bad exchange descriptor Please let me know how to remove these files (2 Replies)
Discussion started by: chidori
2 Replies

3. Shell Programming and Scripting

Error in the o/p says bad file descriptor...

grt=`sort -nr line_count.txt|head -1` while read $dline do if $grt" -eq "`wc -l combo_operncount.$dline|awk '{print $1}'`" ] then awk -F, '{print $1}' combo_operncount.$dline > FULLD7 else echo combo_operncount.$dline >> filecoll.txt fname=`cat filecoll.txt|tr -s "\n" " "` echo $fname... (6 Replies)
Discussion started by: nikhil jain
6 Replies

4. UNIX for Dummies Questions & Answers

Find command returning bad status--

would like to remove the post (8 Replies)
Discussion started by: vk39221
8 Replies

5. Ubuntu

ufsdump from Solaris to ubuntu fails with bad file descriptor

Hi All I have a dedicated backup server running ubuntu 10.04, which has recently been rebuilt (same OS, just different h/w) This is used to receive ufsdump output from a number of Solaris servers, using the following syntax: ufsdump 1uf :/path/to/backup/file /fs/to/be/backed/up This has... (1 Reply)
Discussion started by: in2deep
1 Replies

6. Shell Programming and Scripting

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (2 Replies)
Discussion started by: shilendrajadon
2 Replies

7. UNIX for Advanced & Expert Users

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (1 Reply)
Discussion started by: shilendrajadon
1 Replies

8. Programming

equivalent to utime

Hi, Is there any system call which changes the time of symbolic link apart from utime? or if tere is no system call any other option of how to do it? Thanks (4 Replies)
Discussion started by: naan
4 Replies

9. Shell Programming and Scripting

Utime Command

Hello ! Do you have any example of the utime command ? I'm trying to change the time of last change of a file to a defined time. Thanks. (3 Replies)
Discussion started by: margue
3 Replies

10. UNIX for Dummies Questions & Answers

bad file descriptor?

Ok, I'm sure this is a total newbie question, but I think I'm in the right place, no? I'm trying to call a perl module from a cgi script - Mail::Sendmail - and my web host installed the module in a directory that doesn't seem to be accessible, at least not the way I'm trying. But I thought you... (1 Reply)
Discussion started by: ftb
1 Replies
Login or Register to Ask a Question