Tim Gessner
|
ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 4:04 PM
post13103
|
ConnectAttach fails connecting to a daemon
I have code that was working correctly, ChannelCreate ... ConnectAttach to send messages, but now fails with ESRCH.
The PID is correct and ChannelCreate succeeds. The thing that has changed is that I was using fork to create a daemon
and switched to procmgr_daemon in the process I am trying to attach to.
Now I can't attach. Any ideas on what is wrong?
Thanx
Tim
|
|
|
Xiaodan Tang(deleted)
|
RE: ConnectAttach fails connecting to a daemon
|
Xiaodan Tang(deleted)
09/09/2008 4:12 PM
post13104
|
RE: ConnectAttach fails connecting to a daemon
Look at "procmgr_daemon()" in library reference, make sure you set the
flag correct. Especial the "PROCMGR_DAEMON_NOCLOSE" flag :)
-xtang
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 4:04 PM
> To: ostech-core_os
> Subject: ConnectAttach fails connecting to a daemon
>
> I have code that was working correctly, ChannelCreate ...
> ConnectAttach to send messages, but now fails with ESRCH.
>
> The PID is correct and ChannelCreate succeeds. The thing
> that has changed is that I was using fork to create a daemon
> and switched to procmgr_daemon in the process I am trying to
> attach to.
>
> Now I can't attach. Any ideas on what is wrong?
>
> Thanx
> Tim
>
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post13103
>
>
|
|
|
Shiv Nagarajan(deleted)
|
Re: ConnectAttach fails connecting to a daemon
|
Shiv Nagarajan(deleted)
09/09/2008 4:12 PM
post13105
|
Re: ConnectAttach fails connecting to a daemon
can u post the code to this .. especially around what happens
before the procmgr_daemon call, and the procmgr_daemon call
itself. Are some of the fd's being closed by the procmgr_daemon
call
thanks
shvi
Tue Sep 9 16:12:43 EDT 2008
--> According to Tim Gessner <--
I have code that was working correctly, ChannelCreate ... ConnectAttach to send messages, but now fails with ESRCH.
The PID is correct and ChannelCreate succeeds. The thing that has changed is that I was using fork to create a daemon
and switched to procmgr_daemon in the process I am trying to attach to.
Now I can't attach. Any ideas on what is wrong?
Thanx
Tim
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13103
--
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
|
|
|
Tim Gessner
|
RE: ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 4:31 PM
post13112
|
RE: ConnectAttach fails connecting to a daemon
Both the process I am connecting from and the process I am connecting to
look similar at this point. All channels and file descriptors are
created after I call procmgr_daemon. In main I have
int main(int argc, char *argv[])
{
... // output some text and make sure there aren't other
copies of this process running, etc.
...
if (( eRunMode != RUNMODE_CONSOLE )
&& ( eRunMode != RUNMODE_DEBUG ))
{
// starting as a daemon
if ( ::procmgr_daemon(0,0) == -1 )
{
// <<ERROR>>
...
...
try
{
// here is where all threads are created and all the
work gets done
CService theApp;
if ( theApp.Initialize() )
{
theApp.Run();
theApp.Shutdown();
}
else
EventLog.LogEvent(CDCSEventLog::COMP_SERVER,CDCSEventLog::ELL_BASIC,CDCS
EventLog::SEV_ERROR,"Service failed to initialize, closing
appliction\n");
}
catch( ... )
{
EventLog.LogEvent(CDCSEventLog::COMP_HMICLIENT,CDCSEventLog::ELL_BASIC,C
DCSEventLog::SEV_ERROR,"An unknown exception was caught. Shutting
down.\n");
}
}
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 1:13 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
can u post the code to this .. especially around what happens
before the procmgr_daemon call, and the procmgr_daemon call
itself. Are some of the fd's being closed by the procmgr_daemon
call
thanks
shvi
Tue Sep 9 16:12:43 EDT 2008
--> According to Tim Gessner <--
I have code that was working correctly, ChannelCreate ...
ConnectAttach to send messages, but now fails with ESRCH.
The PID is correct and ChannelCreate succeeds. The thing that
has changed is that I was using fork to create a daemon and switched to
procmgr_daemon in the process I am trying to attach to.
Now I can't attach. Any ideas on what is wrong?
Thanx
Tim
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13103
--
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13105
|
|
|
Shiv Nagarajan(deleted)
|
Re: ConnectAttach fails connecting to a daemon
|
Shiv Nagarajan(deleted)
09/09/2008 5:03 PM
post13116
|
Re: ConnectAttach fails connecting to a daemon
procmgr_daemon(0,0) ends up
doing the following according to the docs
PROCMGR_DAEMON_NOCHDIR -- unless this flag is set,
procmgr_daemon() changes the current working directory to the
root "/".
PROCMGR_DAEMON_NOCLOSE -- unless this flag is set,
procmgr_daemon() closes all file descriptors other than standard
input, standard output and standard error.
PROCMGR_DAEMON_NODEVNULL -- unless this flag is set,
procmgr_daemon() redirects standard input, standard output and
standard error to /dev/null.
PROCMGR_DAEMON_KEEPUMASK -- unless this flag is set,
procmgr_daemon() sets the umask to 0 (zero).
Are any of the other initialisation routines failing?
The only difference between what u used to do with fork and now,
is that with procmgr_daemon the pid is the same as it was before
the call.
where does the connecting process get the pid from to call
ConnectAttach
shiv
Tue Sep 9 17:02:55 EDT 2008
--> According to Tim Gessner <--
Both the process I am connecting from and the process I am connecting to
look similar at this point. All channels and file descriptors are
created after I call procmgr_daemon. In main I have
int main(int argc, char *argv[])
{
... // output some text and make sure there aren't other
copies of this process running, etc.
...
if (( eRunMode != RUNMODE_CONSOLE )
&& ( eRunMode != RUNMODE_DEBUG ))
{
// starting as a daemon
if ( ::procmgr_daemon(0,0) == -1 )
{
// <<ERROR>>
...
...
try
{
// here is where all threads are created and all the
work gets done
CService theApp;
if ( theApp.Initialize() )
{
theApp.Run();
theApp.Shutdown();
}
else
EventLog.LogEvent(CDCSEventLog::COMP_SERVER,CDCSEventLog::ELL_BASIC,CDCS
EventLog::SEV_ERROR,"Service failed to initialize, closing
appliction\n");
}
catch( ... )
{
EventLog.LogEvent(CDCSEventLog::COMP_HMICLIENT,CDCSEventLog::ELL_BASIC,C
DCSEventLog::SEV_ERROR,"An unknown exception was caught. Shutting
down.\n");
}
}
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 1:13 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
can u post the code to this .. especially around what happens
before the procmgr_daemon call, and the procmgr_daemon call
itself. Are some of the fd's being closed by the procmgr_daemon
call
thanks
shvi
Tue Sep 9 16:12:43 EDT 2008
--> According to Tim Gessner <--
I have code that was working correctly, ChannelCreate ...
ConnectAttach to send messages, but now fails with ESRCH.
The PID is correct and ChannelCreate succeeds. The thing that
has changed is that I was using fork to create a daemon and switched to
procmgr_daemon in the process I am trying to attach to.
Now I can't attach. Any ideas on what is wrong?
Thanx
Tim
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13103
--
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13105
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post13112
--
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
|
|
|
Tim Gessner
|
RE: ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 5:07 PM
post13119
|
RE: ConnectAttach fails connecting to a daemon
Later in the program I search /proc and look for the process name. I
use the PID returned to connect. I have stepped through the debugger
and can see that the PID is correct (at least it matches what ps -A
shows me).
So when a particular event occurs later in the program I query for the
PID, call ChannelCreate() and then call ConnectAttach. The PID is
correct and ChannelCreate returns successfully. Those two parameters
are then passed into ConnectAttach(). Here is the code.
if ( ! m_MsgService.isConnected() )
{
pid_t pid = -1;
__QueryProcess("cadred",pid);
if ( pid != -1 )
m_MsgService.Connect(pid);
}
int CMsgSender::Connect(pid_t tPID)
{
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
if ( nCoID != -1 )
{
m_nChID = nChID;
m_nCoID = nCoID;
return 0;
}
::ChannelDestroy(nChID);
}
return -1;
}
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:03 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
procmgr_daemon(0,0) ends up
doing the following according to the docs
PROCMGR_DAEMON_NOCHDIR -- unless this flag is set,
procmgr_daemon() changes the current working directory to the
root "/".
PROCMGR_DAEMON_NOCLOSE -- unless this flag is set,
procmgr_daemon() closes all file descriptors other than standard
input, standard output and standard error.
PROCMGR_DAEMON_NODEVNULL -- unless this flag is set,
procmgr_daemon() redirects standard input, standard output and
standard error to /dev/null.
PROCMGR_DAEMON_KEEPUMASK -- unless this flag is set,
procmgr_daemon() sets the umask to 0 (zero).
Are any of the other initialisation routines failing?
The only difference between what u used to do with fork and now,
is that with procmgr_daemon the pid is the same as it was before
the call.
where does the connecting process get the pid from to call
ConnectAttach
shiv
Tue Sep 9 17:02:55 EDT 2008
--> According to Tim Gessner <--
Both the process I am connecting from and the process I am
connecting to
look similar at this point. All channels and file descriptors
are
created after I call procmgr_daemon. In main I have
int main(int argc, char *argv[])
{
... // output some text and make sure there aren't
other
copies of this process running, etc.
...
if (( eRunMode != RUNMODE_CONSOLE )
&& ( eRunMode != RUNMODE_DEBUG ))
{
// starting as a daemon
if ( ::procmgr_daemon(0,0) == -1 )
{
// <<ERROR>>
...
...
try
{
// here is where all threads are created and all
the
work gets done
CService theApp;
if ( theApp.Initialize() )
{
theApp.Run();
theApp.Shutdown();
}
else
EventLog.LogEvent(CDCSEventLog::COMP_SERVER,CDCSEventLog::ELL_BASIC,CDCS
EventLog::SEV_ERROR,"Service failed to initialize, closing
appliction\n");
}
catch( ... )
{
EventLog.LogEvent(CDCSEventLog::COMP_HMICLIENT,CDCSEventLog::ELL_BASIC,C
DCSEventLog::SEV_ERROR,"An unknown exception was caught.
Shutting
down.\n");
}
}
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 1:13 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
can u post the code to this .. especially around what happens
before the procmgr_daemon call, and the procmgr_daemon call
itself. Are some of the fd's being closed by the procmgr_daemon
call
thanks
shvi
Tue Sep 9 16:12:43 EDT 2008
--> According to Tim Gessner <--
I have code that was working correctly, ChannelCreate
...
ConnectAttach to send messages, but now fails with ESRCH.
The PID is correct and...
View Full Message
|
|
|
Shiv Nagarajan(deleted)
|
Re: ConnectAttach fails connecting to a daemon
|
Shiv Nagarajan(deleted)
09/09/2008 5:13 PM
post13120
|
Re: ConnectAttach fails connecting to a daemon
So I guess there is a server and a client.
shouldnt the server be the one doing the ChannelCreate, and the
client the one just doing the connectattach?
Unless I am reading this wrong, should the ChannelCreate be done
in the process whose pid you are fishing out in the QueryProcess
function (i.e. the process that is becoming the daemon) and the
connectattach in the client that is connecting? Or maybe I am
confused about what is being done here
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:12:47 EDT 2008
--> According to Tim Gessner <--
Later in the program I search /proc and look for the process name. I
use the PID returned to connect. I have stepped through the debugger
and can see that the PID is correct (at least it matches what ps -A
shows me).
So when a particular event occurs later in the program I query for the
PID, call ChannelCreate() and then call ConnectAttach. The PID is
correct and ChannelCreate returns successfully. Those two parameters
are then passed into ConnectAttach(). Here is the code.
if ( ! m_MsgService.isConnected() )
{
pid_t pid = -1;
__QueryProcess("cadred",pid);
if ( pid != -1 )
m_MsgService.Connect(pid);
}
int CMsgSender::Connect(pid_t tPID)
{
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
if ( nCoID != -1 )
{
m_nChID = nChID;
m_nCoID = nCoID;
return 0;
}
::ChannelDestroy(nChID);
}
return -1;
}
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:03 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
procmgr_daemon(0,0) ends up
doing the following according to the docs
PROCMGR_DAEMON_NOCHDIR -- unless this flag is set,
procmgr_daemon() changes the current working directory to the
root "/".
PROCMGR_DAEMON_NOCLOSE -- unless this flag is set,
procmgr_daemon() closes all file descriptors other than standard
input, standard output and standard error.
PROCMGR_DAEMON_NODEVNULL -- unless this flag is set,
procmgr_daemon() redirects standard input, standard output and
standard error to /dev/null.
PROCMGR_DAEMON_KEEPUMASK -- unless this flag is set,
procmgr_daemon() sets the umask to 0 (zero).
Are any of the other initialisation routines failing?
The only difference between what u used to do with fork and now,
is that with procmgr_daemon the pid is the same as it was before
the call.
where does the connecting process get the pid from to call
ConnectAttach
shiv
Tue Sep 9 17:02:55 EDT 2008
--> According to Tim Gessner <--
Both the process I am connecting from and the process I am
connecting to
look similar at this point. All channels and file descriptors
are
created after I call procmgr_daemon. In main I have
int main(int argc, char *argv[])
{
... // output some text and make sure there aren't
other
copies of this process running, etc.
...
if (( eRunMode != RUNMODE_CONSOLE )
&& ( eRunMode != RUNMODE_DEBUG ))
{
// starting as a daemon
if ( ::procmgr_daemon(0,0) == -1 )
{
// <<ERROR>>
...
...
try
{
// here is where all threads are created and all
the
work gets done
CService theApp;
if ( theApp.Initialize() )
{
theApp.Run();
theApp.Shutdown();
}
else
EventLog.LogEvent(CDCSEventLog::COMP_SERVER,CDCSEventLog::ELL_BASIC,CDCS
EventLog::SEV_ERROR,"Service failed to initialize, closing
appliction\n");
}
catch( ......
View Full Message
|
|
|
Tim Gessner
|
RE: ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 5:19 PM
post13121
|
RE: ConnectAttach fails connecting to a daemon
Yes there is a server and a client and they are both daemons. Proc A
gets an event and querys for Proc B's PID. Proc A then calls
ChannelCreate and ConnectAttach to connect to Proc B. Proc A then sends
a message to Proc B. The code snippet I just sent was from Proc A, the
process which is trying to connect. The code to create the daemons is
identical other than the printf messages they display, "Server
starting... " "Client Starting..." and the class that is created CServer
CClient, etc.
Does that make sense? Essentially I have two daemons which both access
shared memory. They communicate to each other (when necessary) through
messages.
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:14 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
So I guess there is a server and a client.
shouldnt the server be the one doing the ChannelCreate, and the
client the one just doing the connectattach?
Unless I am reading this wrong, should the ChannelCreate be done
in the process whose pid you are fishing out in the QueryProcess
function (i.e. the process that is becoming the daemon) and the
connectattach in the client that is connecting? Or maybe I am
confused about what is being done here
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:12:47 EDT 2008
--> According to Tim Gessner <--
Later in the program I search /proc and look for the process
name. I
use the PID returned to connect. I have stepped through the
debugger
and can see that the PID is correct (at least it matches what ps
-A
shows me).
So when a particular event occurs later in the program I query
for the
PID, call ChannelCreate() and then call ConnectAttach. The PID
is
correct and ChannelCreate returns successfully. Those two
parameters
are then passed into ConnectAttach(). Here is the code.
if ( ! m_MsgService.isConnected() )
{
pid_t pid = -1;
__QueryProcess("cadred",pid);
if ( pid != -1 )
m_MsgService.Connect(pid);
}
int CMsgSender::Connect(pid_t tPID)
{
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID =
::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
if ( nCoID != -1 )
{
m_nChID = nChID;
m_nCoID = nCoID;
return 0;
}
::ChannelDestroy(nChID);
}
return -1;
}
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:03 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
procmgr_daemon(0,0) ends up
doing the following according to the docs
PROCMGR_DAEMON_NOCHDIR -- unless this flag is set,
procmgr_daemon() changes the current working directory to the
root "/".
PROCMGR_DAEMON_NOCLOSE -- unless this flag is set,
procmgr_daemon() closes all file descriptors other than standard
input, standard output and standard error.
PROCMGR_DAEMON_NODEVNULL -- unless this flag is set,
procmgr_daemon() redirects standard input, standard output and
standard error to /dev/null.
PROCMGR_DAEMON_KEEPUMASK -- unless this flag is set,
procmgr_daemon() sets the umask to 0 (zero).
Are any of the other initialisation routines failing?
The only difference between what u used to do with fork and now,
is that with procmgr_daemon the pid is the same as it was before
the call.
where does the connecting process get the pid from to call
ConnectAttach
shiv
Tue Sep 9 17:02:55 EDT 2008
--> According to Tim Gessner <--
Both the process I am connecting from and the process I
am
connecting to
look similar at this...
View Full Message
|
|
|
Shiv Nagarajan(deleted)
|
Re: ConnectAttach fails connecting to a daemon
|
Shiv Nagarajan(deleted)
09/09/2008 5:24 PM
post13122
|
Re: ConnectAttach fails connecting to a daemon
So if process A is looking for proc B's pid, it should be
connecting to proc B's channel, not creating a channel and
connecting to it.
the nd, pid, chid being passed to the connectattach, refer to the
owner of the channel.
so in your call
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
should really be
In Proc A
ProcBpid = query for proc B pid
ProcBChid = proc B's channel
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,ProcBPid,ProcBChid,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:23:57 EDT 2008
--> According to Tim Gessner <--
Yes there is a server and a client and they are both daemons. Proc A
gets an event and querys for Proc B's PID. Proc A then calls
ChannelCreate and ConnectAttach to connect to Proc B. Proc A then sends
a message to Proc B. The code snippet I just sent was from Proc A, the
process which is trying to connect. The code to create the daemons is
identical other than the printf messages they display, "Server
starting... " "Client Starting..." and the class that is created CServer
CClient, etc.
Does that make sense? Essentially I have two daemons which both access
shared memory. They communicate to each other (when necessary) through
messages.
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:14 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
So I guess there is a server and a client.
shouldnt the server be the one doing the ChannelCreate, and the
client the one just doing the connectattach?
Unless I am reading this wrong, should the ChannelCreate be done
in the process whose pid you are fishing out in the QueryProcess
function (i.e. the process that is becoming the daemon) and the
connectattach in the client that is connecting? Or maybe I am
confused about what is being done here
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:12:47 EDT 2008
--> According to Tim Gessner <--
Later in the program I search /proc and look for the process
name. I
use the PID returned to connect. I have stepped through the
debugger
and can see that the PID is correct (at least it matches what ps
-A
shows me).
So when a particular event occurs later in the program I query
for the
PID, call ChannelCreate() and then call ConnectAttach. The PID
is
correct and ChannelCreate returns successfully. Those two
parameters
are then passed into ConnectAttach(). Here is the code.
if ( ! m_MsgService.isConnected() )
{
pid_t pid = -1;
__QueryProcess("cadred",pid);
if ( pid != -1 )
m_MsgService.Connect(pid);
}
int CMsgSender::Connect(pid_t tPID)
{
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID =
::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
if ( nCoID != -1 )
{
m_nChID = nChID;
m_nCoID = nCoID;
return 0;
}
::ChannelDestroy(nChID);
}
return -1;
}
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:03 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
procmgr_daemon(0,0) ends up
doing the following according to the docs
PROCMGR_DAEMON_NOCHDIR -- unless this flag is set,
procmgr_daemon() changes the current working directory to the
root "/".
PROCMGR_DAEMON_NOCLOSE -- unless this flag is set,
procmgr_daemon() closes all file descriptors other than standard
input, standard output and standard error....
View Full Message
|
|
|
Tim Gessner
|
RE: ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 5:36 PM
post13123
|
RE: ConnectAttach fails connecting to a daemon
Interesting, that is not how I read the documentation. Since I can't
know the channel of Proc B in Proc A - it is a FD created by the call to
ChannelCreate in Proc B, there is no way to connect from Proc A if the
ChId is created in Proc B. As I understood the documentation Proc B
calls ChannelCreate and Proc A calls ChannelCreate. The ChId passed
into ConnectAttach in Proc A is the channel created by Proc A.
Am I still misunderstanding this?
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:25 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
So if process A is looking for proc B's pid, it should be
connecting to proc B's channel, not creating a channel and
connecting to it.
the nd, pid, chid being passed to the connectattach, refer to the
owner of the channel.
so in your call
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
should really be
In Proc A
ProcBpid = query for proc B pid
ProcBChid = proc B's channel
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,ProcBPid,ProcBChid,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:23:57 EDT 2008
--> According to Tim Gessner <--
Yes there is a server and a client and they are both daemons.
Proc A
gets an event and querys for Proc B's PID. Proc A then calls
ChannelCreate and ConnectAttach to connect to Proc B. Proc A
then sends
a message to Proc B. The code snippet I just sent was from Proc
A, the
process which is trying to connect. The code to create the
daemons is
identical other than the printf messages they display, "Server
starting... " "Client Starting..." and the class that is created
CServer
CClient, etc.
Does that make sense? Essentially I have two daemons which both
access
shared memory. They communicate to each other (when necessary)
through
messages.
Thanx
Tim
-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:14 PM
To: ostech-core_os
Subject: Re: ConnectAttach fails connecting to a daemon
So I guess there is a server and a client.
shouldnt the server be the one doing the ChannelCreate, and the
client the one just doing the connectattach?
Unless I am reading this wrong, should the ChannelCreate be done
in the process whose pid you are fishing out in the QueryProcess
function (i.e. the process that is becoming the daemon) and the
connectattach in the client that is connecting? Or maybe I am
confused about what is being done here
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
shiv
Tue Sep 9 17:12:47 EDT 2008
--> According to Tim Gessner <--
Later in the program I search /proc and look for the
process
name. I
use the PID returned to connect. I have stepped through
the
debugger
and can see that the PID is correct (at least it matches
what ps
-A
shows me).
So when a particular event occurs later in the program I
query
for the
PID, call ChannelCreate() and then call ConnectAttach.
The PID
is
correct and ChannelCreate returns successfully. Those
two
parameters
are then passed into ConnectAttach(). Here is the code.
if ( ! m_MsgService.isConnected() )
{
pid_t pid = -1;
__QueryProcess("cadred",pid);
if ( pid != -1 )
m_MsgService.Connect(pid);
}
int CMsgSender::Connect(pid_t tPID)
{
int nChID = ::ChannelCreate(_NTO_CHF_UNBLOCK);
if ( nChID != -1 )
{
int nCoID =
::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
_NTO_SIDE_CHANNEL,0);
if ( nCoID != -1 )
{
m_nChID = nChID;
m_nCoID = nCoID;
return...
View Full Message
|
|
|
David Sarrazin
|
RE: ConnectAttach fails connecting to a daemon
|
David Sarrazin
09/09/2008 5:50 PM
post13125
|
RE: ConnectAttach fails connecting to a daemon
Only the owner of a channel (ie, the process who called ChannelCreate())
can receive messages/pulses on it. A channel is not needed to send,
only to receive. Yes, Process A will have to know the PID and CHID of
process B, in order to send it a message. Process A only needs to call
ChannelCreate() if it wants to receive messages itself. FYI process A
and Process B need to send messages one direction, not both (ie. A->B
OR B->A, don't have A<->B), as you can get a deadlock if they send to
each other.
As for how to get the chid out of process B? There are several methods:
a shared memory region; printing the chid on the console, and passing it
as a cmd-line arg to process A; resmgr_attach() and it's associated
functions (note this is a more involved method, but great if you plan
for your processes to register pathnames, and respond to all the
"normal" POSIX operations).
David
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: September 9, 2008 5:36 PM
> To: ostech-core_os
> Subject: RE: ConnectAttach fails connecting to a daemon
>
> Interesting, that is not how I read the documentation. Since
> I can't know the channel of Proc B in Proc A - it is a FD
> created by the call to ChannelCreate in Proc B, there is no
> way to connect from Proc A if the ChId is created in Proc B.
> As I understood the documentation Proc B calls ChannelCreate
> and Proc A calls ChannelCreate. The ChId passed into
> ConnectAttach in Proc A is the channel created by Proc A.
>
> Am I still misunderstanding this?
>
> Thanx
> Tim
>
>
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:25 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a daemon
>
> So if process A is looking for proc B's pid, it should be
> connecting to proc B's channel, not creating a channel and
> connecting to it.
>
> the nd, pid, chid being passed to the connectattach, refer to
> the owner of the channel.
>
> so in your call
>
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
> _NTO_SIDE_CHANNEL,0);
>
> should really be
>
> In Proc A
>
> ProcBpid = query for proc B pid
> ProcBChid = proc B's channel
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,ProcBPid,ProcBChid,0 |
> _NTO_SIDE_CHANNEL,0);
>
> shiv
> Tue Sep 9 17:23:57 EDT 2008
>
> --> According to Tim Gessner <--
> Yes there is a server and a client and they are both daemons.
> Proc A
> gets an event and querys for Proc B's PID. Proc A then calls
> ChannelCreate and ConnectAttach to connect to Proc B.
> Proc A then sends
> a message to Proc B. The code snippet I just sent was
> from Proc A, the
> process which is trying to connect. The code to create
> the daemons is
> identical other than the printf messages they display, "Server
> starting... " "Client Starting..." and the class that
> is created CServer
> CClient, etc.
>
> Does that make sense? Essentially I have two daemons
> which both access
> shared memory. They communicate to each other (when
> necessary) through
> messages.
>
> Thanx
> Tim
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:14 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a daemon
>
> So I guess there is a server and a client.
>
> shouldnt the server be the one doing the ChannelCreate, and the
> client the one just doing the connectattach?
>
> Unless I am reading this wrong, should...
View Full Message
|
|
|
Tim Gessner
|
RE: ConnectAttach fails connecting to a daemon
|
Tim Gessner
09/09/2008 6:17 PM
post13126
|
RE: ConnectAttach fails connecting to a daemon
Ok, Thanx. I'll make the changes.
-----Original Message-----
From: David Sarrazin [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 09, 2008 2:51 PM
To: ostech-core_os
Subject: RE: ConnectAttach fails connecting to a daemon
Only the owner of a channel (ie, the process who called ChannelCreate())
can receive messages/pulses on it. A channel is not needed to send,
only to receive. Yes, Process A will have to know the PID and CHID of
process B, in order to send it a message. Process A only needs to call
ChannelCreate() if it wants to receive messages itself. FYI process A
and Process B need to send messages one direction, not both (ie. A->B
OR B->A, don't have A<->B), as you can get a deadlock if they send to
each other.
As for how to get the chid out of process B? There are several methods:
a shared memory region; printing the chid on the console, and passing it
as a cmd-line arg to process A; resmgr_attach() and it's associated
functions (note this is a more involved method, but great if you plan
for your processes to register pathnames, and respond to all the
"normal" POSIX operations).
David
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: September 9, 2008 5:36 PM
> To: ostech-core_os
> Subject: RE: ConnectAttach fails connecting to a daemon
>
> Interesting, that is not how I read the documentation. Since
> I can't know the channel of Proc B in Proc A - it is a FD
> created by the call to ChannelCreate in Proc B, there is no
> way to connect from Proc A if the ChId is created in Proc B.
> As I understood the documentation Proc B calls ChannelCreate
> and Proc A calls ChannelCreate. The ChId passed into
> ConnectAttach in Proc A is the channel created by Proc A.
>
> Am I still misunderstanding this?
>
> Thanx
> Tim
>
>
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:25 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a daemon
>
> So if process A is looking for proc B's pid, it should be
> connecting to proc B's channel, not creating a channel and
> connecting to it.
>
> the nd, pid, chid being passed to the connectattach, refer to
> the owner of the channel.
>
> so in your call
>
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
> _NTO_SIDE_CHANNEL,0);
>
> should really be
>
> In Proc A
>
> ProcBpid = query for proc B pid
> ProcBChid = proc B's channel
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,ProcBPid,ProcBChid,0 |
> _NTO_SIDE_CHANNEL,0);
>
> shiv
> Tue Sep 9 17:23:57 EDT 2008
>
> --> According to Tim Gessner <--
> Yes there is a server and a client and they are both daemons.
> Proc A
> gets an event and querys for Proc B's PID. Proc A then calls
> ChannelCreate and ConnectAttach to connect to Proc B.
> Proc A then sends
> a message to Proc B. The code snippet I just sent was
> from Proc A, the
> process which is trying to connect. The code to create
> the daemons is
> identical other than the printf messages they display, "Server
> starting... " "Client Starting..." and the class that
> is created CServer
> CClient, etc.
>
> Does that make sense? Essentially I have two daemons
> which both access
> shared memory. They communicate to each other (when
> necessary) through
> messages.
>
> Thanx
> Tim
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:14 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a...
View Full Message
|
|
|
Shiv Nagarajan(deleted)
|
Re: ConnectAttach fails connecting to a daemon
|
Shiv Nagarajan(deleted)
09/09/2008 6:22 PM
post13127
|
Re: ConnectAttach fails connecting to a daemon
thanks dave.. couldn't have described it any better :)
shiv
Tue Sep 9 18:21:53 EDT 2008
--> According to David Sarrazin <--
Only the owner of a channel (ie, the process who called ChannelCreate())
can receive messages/pulses on it. A channel is not needed to send,
only to receive. Yes, Process A will have to know the PID and CHID of
process B, in order to send it a message. Process A only needs to call
ChannelCreate() if it wants to receive messages itself. FYI process A
and Process B need to send messages one direction, not both (ie. A->B
OR B->A, don't have A<->B), as you can get a deadlock if they send to
each other.
As for how to get the chid out of process B? There are several methods:
a shared memory region; printing the chid on the console, and passing it
as a cmd-line arg to process A; resmgr_attach() and it's associated
functions (note this is a more involved method, but great if you plan
for your processes to register pathnames, and respond to all the
"normal" POSIX operations).
David
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: September 9, 2008 5:36 PM
> To: ostech-core_os
> Subject: RE: ConnectAttach fails connecting to a daemon
>
> Interesting, that is not how I read the documentation. Since
> I can't know the channel of Proc B in Proc A - it is a FD
> created by the call to ChannelCreate in Proc B, there is no
> way to connect from Proc A if the ChId is created in Proc B.
> As I understood the documentation Proc B calls ChannelCreate
> and Proc A calls ChannelCreate. The ChId passed into
> ConnectAttach in Proc A is the channel created by Proc A.
>
> Am I still misunderstanding this?
>
> Thanx
> Tim
>
>
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:25 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a daemon
>
> So if process A is looking for proc B's pid, it should be
> connecting to proc B's channel, not creating a channel and
> connecting to it.
>
> the nd, pid, chid being passed to the connectattach, refer to
> the owner of the channel.
>
> so in your call
>
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,tPID,nChID,0 |
> _NTO_SIDE_CHANNEL,0);
>
> should really be
>
> In Proc A
>
> ProcBpid = query for proc B pid
> ProcBChid = proc B's channel
>
> int nCoID = ::ConnectAttach(ND_LOCAL_NODE,ProcBPid,ProcBChid,0 |
> _NTO_SIDE_CHANNEL,0);
>
> shiv
> Tue Sep 9 17:23:57 EDT 2008
>
> --> According to Tim Gessner <--
> Yes there is a server and a client and they are both daemons.
> Proc A
> gets an event and querys for Proc B's PID. Proc A then calls
> ChannelCreate and ConnectAttach to connect to Proc B.
> Proc A then sends
> a message to Proc B. The code snippet I just sent was
> from Proc A, the
> process which is trying to connect. The code to create
> the daemons is
> identical other than the printf messages they display, "Server
> starting... " "Client Starting..." and the class that
> is created CServer
> CClient, etc.
>
> Does that make sense? Essentially I have two daemons
> which both access
> shared memory. They communicate to each other (when
> necessary) through
> messages.
>
> Thanx
> Tim
>
> -----Original Message-----
> From: Shiv Nagarajan [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 09, 2008 2:14 PM
> To: ostech-core_os
> Subject: Re: ConnectAttach fails connecting to a...
View Full Message
|
|
|
|