DoesntMatter wrote:
>
> Willem , Mark ,
>
> Mark Kromski wrote:
>
> <huge resetting snip> :-)
>
> So reading a lot between the lines , suddenly realizing that NT does not
> stand for the Microsoft operating system and so on ... :
>
> You have some kind of multiprocess application on one and the same Linux
> system , so I literally mean on the same physical system , right ?
correct
>
> There is some toplevel process 'asim' that spawns two other processes,
> the one called "ipc" the other called "nt" , right ?
correct
>
> The communication between "asim" and "ipc" is working as expected , I
> understand ? How is it setup exactly ? A few snippets of code please ...
> dgramsocket::dgramsocket (fdType & pfd,
domainType pdomain,
modeType pmode,
NameType& pname)
throw (CannotCreateSocket)
{
sname=pname;
sdomain=pdomain;
stype=SOCK_DGRAM;
smode=pmode;
int tmpfd;
char tmpfile[64]="/tmp/lsXXXXXX";
char ldevName[64];
char buf [2]="s";
int s;
int wxfer;
#ifdef IPC_DEBUG
printf ("creating socket mode %i %s\n",smode,sname.GetName());
#endif
if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
{
perror ("socket call ");
}
memset (&saun,0,sizeof(saun));
saun.sun_family = AF_UNIX;
// strcpy (saun.sun_path, tmpnam(NULL));
mkstemp(saun.sun_path);
if (smode == SERVER)
{
unlink (sname.GetName());
strcpy (saun.sun_path, sname.GetName());
if (bind(s, (struct sockaddr *) &saun, sizeof(struct sockaddr)) <
0)
{
perror ("SERVER : bind");
throw CannotCreateSocket();
}
#ifdef IPC_DEBUG
printf ("started SERVER %s\n",sname.GetName());
#endif
}
else
{
#ifdef IPC_DEBUG
printf ("staring CLIENT %s\n",sname.GetName());
#endif
if (!sname.isSocket ())
{
printf ("Socket ERROR not a socket name \n");
}
#ifdef IPC_DEBUG
printf ("binding CLIENT %s\n",sname.GetName());
#endif
unlink (saun.sun_path);
if((tmpfd=mkstemp(tmpfile))<0)
{
perror("mkstemp failed:");
}
sprintf(ldevName,"%ss", tmpfile);
strcpy (saun.sun_path, ldevName);
if (bind(s, (struct sockaddr *) &saun, sizeof(struct sockaddr)) <
0)
{
perror ("Binding Client : ");
throw CannotCreateSocket();
}
strcpy (saun.sun_path, sname.GetName());
#ifdef IPC_DEBUG
printf ("connecting CLIENT %s\n",sname.GetName());
#endif
if (connect (s, (struct sockaddr *) &saun, sizeof (struct
sockaddr)))
{
perror ("connect Client : ");
}
// Send the dummy wake up call allowing the server to set up the
// connection address.
wxfer=write (s, buf, InitmsgLength);
#ifdef IPC_DEBUG
printf ("started CLIENT %s\n",sname.GetName());
#endif
}
fd.Setfd (s);
pfd=fd;
}
> The communication between "nt" and "ipc" isn't working as expected. You
> did set up some socket in the unix domain , I understand. Is that right
> ?
Correct, at the ipc-side, it is the same codeas between the asim and ipc
> Can you give a few lines of code ? YOu are sure communicating over a
> socket and not over a pair of filedescriptors of pipe ?
For sure we use sockets:
At nt-side we use similar code:
unsigned long
LdgsockIfc::init (const char* devname,
unsigned long flags)
{
int tmpfd;
char tmpfile[64] = "/tmp/lsXXXXXX";
/* ldevname is either the name of the client socket, */
/* or otherwise the name of the server socket. The */
/* server socket is created in the /tmp directory also */
/* because a socket node cannot be created in a clear- */
/* case directory */
char ldevname[64];
struct sockaddr_un unix_addr;
struct stat statbuf;
static int init=0;
// init for trace and debug
if(init==0)
{
init++;
trc_register("lsock",TRC_INFO,&trc_lsock);
dbg_link("lsock",lsockHelp,lsockCommand);
}
/* prepase the temp name */
if ((tmpfd = mkstemp(tmpfile)) < 0)
{
perror ("mkstemp failed");
goto err_ret;
}
sprintf (ldevname, "%ss", tmpfile);
/* Create socket... */
if ((fd = socket (AF_UNIX,SOCK_DGRAM,0)) < 0)
{
perror ("socket creation failed");
goto err_close_tmpfd;
}
/* Bind to it... */
memset (&unix_addr,0,sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy (unix_addr.sun_path,ldevname);
if (bind(fd,(struct sockaddr *)&unix_addr,sizeof(struct sockaddr)) <
0)
{
perror ("bind failed");
goto err_close;
}
/* Initialise state: no server, no client */
state_m = dgs_invalid_e;
/* Try to be a client... */
do
{
char dummybuf[2] = " ";
/* Is there an lsock server with that name ? */
if (stat(devname,&statbuf)!=0 || ! S_ISSOCK(statbuf.st_mode))
{
break;
}
/* Try to connect... */
// strcpy (unix_addr.sun_path,devname);
//
if (connect(fd,(struct sockaddr *)&unix_addr,sizeof(struct
sockaddr)) < 0) <-- here it is failing, the connect fails
{ and we go to the break
break;
}
/* Successfully connected: dummy write to let the server know our
address */
write (fd, dummybuf, 1);
state_m = dgs_connected_e;
}
while (0);
/* If we're not connected as client, become a server */
if (state_m != dgs_connected_e)
{
unlink (devname);
symlink (ldevname, devname);
state_m = dgs_single_e;
}
#ifdef __SVR4
// non blocking
if (fcntl (fd, F_SETFL, O_NDELAY | fcntl (fd, F_GETFL, 0)) < 0)
{
perror ("fcntl failed");
goto err_close;
}
// Want SIGIO / SIGPOLL
if (ioctl (fd, I_SETSIG, S_RDNORM /*| S_WRNORM -> always writable */
))
{
perror ("ioctl I_SETSIG failed");
goto err_close;
}
#else
/* tell fd which process to signal */
if (fcntl (fd, F_SETOWN, getpid ()) < 0)
{
perror ("fcntl failed");
goto err_close;
}
/* Set NONBLOCKING & ASYNC mode */
# ifdef linux
if (fcntl (fd, F_SETFL, FASYNC | O_NONBLOCK | fcntl (fd, F_GETFL, 0))
< 0)
# else
if (fcntl (fd, F_SETFL, FASYNC | FNBIO | fcntl (fd, F_GETFL, 0)) < 0)
# endif
{
perror ("fcntl failed");
goto err_close;
}
#endif
/* cleanup the temporary things */
close(tmpfd);
unlink (tmpfile);
return ERR_NO_ERROR;
err_close:
close (fd);
fd = -1;
err_close_tmpfd:
close (tmpfd);
unlink (tmpfile);
err_ret:
return LSOCK_ERR_UNSPEC;
}
>
> So bottom line : can you give me some concrete and clear explanation of
> what you are doing. I would be _extremely_ surprised if it was a RedHat
> problem in this area. You'll find out with a Red Head :-p
Explanation:
We have a "Overall Managing-tool" called asim. This one forks the ipc
process which is a router for communication.
We are now in the first step, that we have ported our "target Sw" to
Linux. This first board is the nt. Besides this we also have lt's. The
communication between these boards is managed by the ipc-process. This
works on Solaris.
Now, we want to try the communication between the nt and the ipc. It
fails on the connect, see above. This happens when
we fork (and execvp) the process in the asim-tool. If we start it up
manually (nt), the connect does not fail.
fork code:
switch(childpid=fork())
{
case 0 : // I'm alive ...
if(!window)
{
// close(0);
// close(1);
// close(2);
}
for(i=3;i<255;i++) close(i);
execvp (argv[0], argv);
perror("exec failed");
fprintf(stderr,"Plugin : exec call failed for
%s\n",filename);
// exit(-1);
break;
case -1 :
perror("fork failed");
fprintf(stderr,"Plugin : fork call failed for
%s\n",filename);
return;
break;
default :
boardArray[slot].setChildPid(childpid);
if(asam.getVerbose()>=5)
printf("The child process is forked\n");
chdir(workDir);
break;
}
Best Regards,
Willem
>
> Ready to help further ...
--
ALCATEL TELECOM
Willem Wijnant
JA23
tel.: 03/240.7647
email:
(E-Mail Removed)