utime returning -1 BAD File DEscriptor


 
Thread Tools Search this Thread
Top Forums Programming utime returning -1 BAD File DEscriptor
# 1  
Old 01-25-2011
utime returning -1 BAD File DEscriptor

Hi All,
First of all thanks for reading this post.
In my application, I am trying to create a new message queue . I am attaching the code below.
Code:
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 */

   buf.mq_msgsize = 1024;

   buf.mq_maxmsg = 16;

   /* 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%x  maxmsg: %d  msgsize: %d  curmsgs: %d\n",

         buf.mq_flags, buf.mq_maxmsg, buf.mq_msgsize, buf.mq_curmsgs);

      }

      else

         perror("mq_getattr()");

   }

   else

      perror("mq_open()");
return mqd;
}

But mq_open is return -1 with EFAULT as error code. This is a part of my big application So for checking the method i wrote a sample code with the same method and tried to create a message queue. It was working perfectly fine.
I run strace for the program to get the details of the bug.
(i have attached the entire strace for reference.)
In that it is mentioned as
Code:
utimes("iothread8", {{...}, {...}})     = -1 EFAULT (Bad address)

Please help me to get out of this issue. Thanks again,
Parvathy

Last edited by pludi; 01-25-2011 at 09:38 AM.. Reason: code tags please
# 2  
Old 01-25-2011
A message queue is not a file. You can't call utimes() on it.
# 3  
Old 01-25-2011
I forget how to open a queue, already, because MQ came with examples I just hacked! Each call depends on prior calls. Is mq_open first, and is the target queue manager already running? Is this a tcp client, or local?
# 4  
Old 01-27-2011
Hi All,
Thanks for your time. Pls help me to solve it out.
Quote:
Originally Posted by Corona688
A message queue is not a file. You can't call utimes() on it.
I am not calling utimes(), i am calling only mq_open(), but in the strace report i am getting it as utime() returns BAD DESCRIPTOR error.

@DGPickett: It is not a TCP Client. and i dint get you fully? How can I know that the queue manager is already running.

Regards,
Parvathy.
# 5  
Old 01-27-2011
Perhaps the message queue exists already, so O_CREAT causes it to refuse to create it again?
# 6  
Old 01-27-2011
Well, you can ask the person who put the queue up, or put it up yourself, or "ps -ef | grep mq".

As I said, there is example code included, great to round out the explanations.
# 7  
Old 01-28-2011
@Corona688: I also got the same doubt, so I tried removing O_CREATE with O_EXCL; but that also dint workSmilie
@DGPickett: Sorry I dint get you fully. Can you please elaborate a little more?

Once Again Thanks AllSmilie
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