i m creating a program to process some data remote. So i use something like
cat file ./client - “Actionneip” -p “port” -c “command”
i can use the command as "base64 -d | tar -zvt" if i want to get the list inside my tar file. I have those objects;
Sock.. is an object that implements the C socket. RCVBUFSIZE = 2000 and the size i use to send and get data pid to know if i m the child or the parent process
To do that i i m using the pipe and fork. the basic structure is:
int fd[2];
pipe(fd);
if((pid=fork()) == -1) exit(-1);
if(pid == 0)
{
while((recvMsgSize = sock->recv(echoBuffer, RCVBUFSIZE)){
write(fd[1], echoBuffer, recvMsgSize);
}
}
else pipeback(fd,sock)
So i can get the data and send from the parent to the child. The client read from the stdin and send through the socket and the server read through the socket
问题在于管道。
void pipeback(int *fdRef, TCPSocket *sock){
char *buffer = new char[2000];
int size;
close(fdRef[1]);
dup2(fdRef[0], 0);
close(fdrEf[0]);
pipe(fout)
if((pid = fork()) == -1)exit(-1);
if(pid ==0){
close(fout[0]);
dup2(fout[1], 1);
close(fout[1]);
execlp("bash", "bash", "-c", "base64", NULL);
}
else{
close(fout[1]);
while((size = read(fout[0], buffer, 2000)) > 0){
sock->send(buffer, size);
write(fileno(stdout), buffer, size);
}
}
}
the problem is the line "execlp("bash", "bash", "-c", "base64", NULL);" if i use the cat on the fourth argument it works, if i use one ls -lahtr is shows me the files on the folder, so, works like a charm. BUT, when i use base64 or uuencode... probably other commands it stops on the read line, and stops, dies, i used strace and the gdb to see what is happening. I don t know what i need to do to debug this process. So i created an separate program, only to read from the stdin and use the pipe to process on base64 or uuencode using the bash. It works, i thing it is something with the socket or the time, but i dont have any ideas. Sorry, but my English is not that gooood... XD. Thanks for everything
注:
我使用了race子,在使用基底64时,我注意到了 stop,然后试图从粉刷中读(已经停止)。
Someone know how i can solve that?