Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - call to open() fails in main().: (6 Items)
   
call to open() fails in main().  
Hi,
   When i tried to open() a path attached using resmgr_attach() in the same process (but different thread) the call to 
open() fails.
Please help....

Thanks in advance,
Lingaraj.

/*
 * ResMgr and Message Server Process
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/neutrino.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include<fcntl.h>

resmgr_connect_funcs_t  ConnectFuncs;
resmgr_io_funcs_t       IoFuncs;
iofunc_attr_t           IoFuncAttr;



void* path_register_thread(void *temp)
{
	
    resmgr_attr_t        resmgr_attr;
    message_attr_t       message_attr;
    dispatch_t           *dpp;
    dispatch_context_t   *ctp, *ctp_ret;
    int                  resmgr_id;

    /* Create the Dispatch Interface */
    dpp = dispatch_create();
    if( dpp == NULL )
    {
        fprintf( stderr, "dispatch_create() failed: %s\n", 
                 strerror( errno ) );
        return NULL;
    }

    memset( &resmgr_attr, 0, sizeof( resmgr_attr ) );
    resmgr_attr.nparts_max = 1;
    resmgr_attr.msg_max_size = 2048;

    /* Setup the default I/O functions to handle open/read/write/... */
    iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &ConnectFuncs,
                      _RESMGR_IO_NFUNCS, &IoFuncs );

    /* Setup the attribute for the entry in the filesystem */
    iofunc_attr_init( &IoFuncAttr, S_IFNAM | 0666, 0, 0 );

    resmgr_id = resmgr_attach( dpp, &resmgr_attr, "serv", _FTYPE_ANY, 
                               0, &ConnectFuncs, &IoFuncs, &IoFuncAttr );
    if( resmgr_id == -1 )
    {
        fprintf( stderr, "resmgr_attach() failed: %s\n", strerror( errno ) );
        return NULL;
    }

    /* Setup our message callback */
    memset( &message_attr, 0, sizeof( message_attr ) );
    message_attr.nparts_max = 1;
    message_attr.msg_max_size = 4096;


    /* Setup a context for the dispatch layer to use */
    ctp = dispatch_context_alloc( dpp );
    if( ctp == NULL )
    {
        fprintf( stderr, "dispatch_context_alloc() failed: %s\n", 
                 strerror( errno ) );
        return NULL;
    }



    /* The "Data Pump" - get and process messages */
    while( 1 )
    {
        ctp_ret = dispatch_block( ctp );
        if( ctp_ret )
        {
            dispatch_handler( ctp );
        }
        else
        {
            fprintf( stderr, "dispatch_block() failed: %s\n", 
                     strerror( errno ) );
            return NULL;
        }
    }
}
	


int main( int argc, char **argv )
{

    int fd = -1;
    pthread_t *threadId = NULL;
    
    pthread_create(threadId, NULL,path_register_thread ,NULL);
    
    sleep(2);	

    fd = open("serv", O_RDWR);
    while(1)
    {
	if(fd == -1)
	    printf("%d\n", fd);
	sleep(1);
    }

    return EXIT_SUCCESS;
}


Re: call to open() fails in main().  
On Fri, Mar 20, 2009 at 10:20:46AM -0400, lingaraj patil wrote:
> Hi,
>    When i tried to open() a path attached using resmgr_attach() in the same process (but different thread) the call to
 open() fails.
> Please help....

Look at the _RESMGR_FLAG_SELF flag to resmgr_attach().

-seanb
Re: call to open() fails in main().  
hi,

    If i use that flag also, still it doesn't work.

Thanks,
Lingaraj
Re: call to open() fails in main().  
lingaraj patil wrote:
> hi,
>
>     If i use that flag also, still it doesn't work.
>   
It would probably be easier if you posted your snipped of code for us to 
see.  What error
code are you getting back from the open .. are permissions a problem now?

It may be kind of heavy handed, but if you can take a trace of the open 
using the System Profiler
and kernel instrumentation then you would be able to see if the open 
message is making it to
your server or not.

Hope this helps,
 Thomas
RE: call to open() fails in main().  
Try registering and opening a fully qualified path, eg "/serv"  It would be useful to post the errno
that open sets when it fails, too.
 
Colin

________________________________

From: Thomas Fletcher [mailto:community-noreply@qnx.com]
Sent: Sun 3/22/2009 9:47 AM
To: ostech-core_os
Subject: Re: call to open() fails in main().



lingaraj patil wrote:
> hi,
>
>     If i use that flag also, still it doesn't work.
>  
It would probably be easier if you posted your snipped of code for us to
see.  What error
code are you getting back from the open .. are permissions a problem now?

It may be kind of heavy handed, but if you can take a trace of the open
using the System Profiler
and kernel instrumentation then you would be able to see if the open
message is making it to
your server or not.

Hope this helps,
 Thomas


_______________________________________________
OSTech
http://community.qnx.com/sf/go/post24957



Attachment: Text winmail.dat 3.9 KB
Re: call to open() fails in main().  
> lingaraj patil wrote:
> > hi,
> >
> >     If i use that flag also, still it doesn't work.
> >   
> It would probably be easier if you posted your snipped of code for us to 
> see.  What error
> code are you getting back from the open .. are permissions a problem now?
> 
> It may be kind of heavy handed, but if you can take a trace of the open 
> using the System Profiler
> and kernel instrumentation then you would be able to see if the open 
> message is making it to
> your server or not.
> 
> Hope this helps,
>  Thomas

I did set that flag lingaraj's source  and thing are working (QNX640,x86).

Just wondering about the info->priority 2584 in event 47904.
Isn't that a little outof range or how is this explainable ?


Event, Time, Owner, Type, Data
47897, 3s 109ms 245us, self Thread 1, ConnectAttach Enter, nd 0x0 pid 1 chid 0x1 index 0 flags 0x1 process procnto-smp-
instr
47898, 3s 109ms 247us, self Thread 1, ConnectAttach Exit, coid 0x3
47899, 3s 109ms 247us, self Thread 1, MsgSendv Enter, coid 0x3 sparts 2 rparts 2 msg0 0x20100 msg1 0x0 msg2 0x100a18 
function _IO_CONNECT_OPEN
47900, 3s 109ms 248us, self Thread 1, Send Message, rcvid 0x2c pid 1 process procnto-smp-instr
47901, 3s 109ms 248us, self Thread 1, Reply, pid 1105962 tid 1 priority 10 policy 2
47902, 3s 109ms 249us, procnto-smp-instr Thread 5, Running, pid 1 tid 5 priority 10 policy 2
47903, 3s 109ms 249us, procnto-smp-instr Thread 5, Receive Message, rcvid 0x2c pid 1 process procnto-smp-instr

47904, 3s 109ms 249us, procnto-smp-instr Thread 5, MsgReceivev Exit, rcvid 0x2c rmsg0 0x20100 rmsg1 0x0 rmsg2 0x100a18 
info->nd 0 info->srcnd 0 info->pid 1105962 info->tid 1 info->chid 1 info->scoid 1073741868 info->msglen 3 info->
srcmsglen 45 info->dstmsglen 45 info->priority 2584 info->flags 10 info->reserved 0

47905, 3s 109ms 251us, procnto-smp-instr Thread 5, Path Manager, pid 1105962 tid 1 path_name serv process self
47906, 3s 109ms 256us, procnto-smp-instr Thread 5, MsgReplyv Enter, rcvid 0x2c sparts 4 status 0x800b0000 msg0 0x20100 
msg1 0x0 msg2 0xa00
47907, 3s 109ms 257us, procnto-smp-instr Thread 5, Reply, tid 1 pid 1105962 process self
47908, 3s 109ms 257us, self Thread 1, Ready, pid 1105962 tid 1 priority 10 policy 2
47909, 3s 109ms 258us, procnto-smp-instr Thread 5, MsgReplyv Exit, ret_val 0
47910, 3s 109ms 258us, procnto-smp-instr Thread 5, MsgReceivev Enter, chid 0x1 rparts 1
47911, 3s 109ms 259us, procnto-smp-instr Thread 5, Receive, pid 1 tid 5 priority 10 policy 2
47912, 3s 109ms 259us, self Thread 1, Running, pid 1105962 tid 1 priority 10 policy 2
47913, 3s 109ms 260us, self Thread 1, MsgSendv Exit, status 2148204544 rmsg 0x20100
47914, 3s 109ms 261us, self Thread 1, ConnectDetach Enter, coid 0x3
47915, 3s 109ms 262us, self Thread 1, ConnectDetach Exit, ret_val 0x0
47916, 3s 109ms 263us, self Thread 1, ConnectAttach Enter, nd 0x0 pid 1105962 chid 0x1 index 0 flags 0x1 process self
47917, 3s 109ms 264us, self Thread 1, ConnectAttach Exit, coid 0x3
47918, 3s 109ms 265us, self Thread 1, MsgSendv Enter, coid 0x3 sparts 2 rparts 2 msg0 0x20100 msg1 0x0 msg2 0xf0998 
function _IO_CONNECT_OPEN
47919, 3s 109ms 265us, self Thread 1, Send Message, rcvid 0x3 pid 1105962 process self
47920, 3s 109ms 266us, self Thread 1, Reply, pid 1105962 tid 1 priority 10 policy 2
47921, 3s 109ms 266us, self Thread 2, Running, pid 1105962 tid 2 priority 10 policy 2
47922, 3s 109ms 267us, self Thread 2, Receive Message, rcvid 0x3 pid 1105962 process self

tracelogger was started like:
tracelogger -w -r -k64

and logging was controled by 	

TraceEvent( _NTO_TRACE_START );
TraceEvent( _NTO_TRACE_STOP );

Within above self process.

Thx,
Jeevan