P
PC
Is it possible to create pipe()s (stdin/stdout) for a child process
and forking a shell with execl() and controlling the shell's
stdin/stdout from the parent with select()?
Heres a little snippet of code. it doesnt actually work.. but it is
how I envisioned it::
if((n=accept(s,(struct sockaddr *)&remote,&sz))==-1)
{printf("accept\n"); exit(0);}
close(0); close(1); close(2);
pipe(&i[0]);
dup2(0,i[0]);
dup2(1,i[1]);
dup2(n,i[0]);
dup2(n,i[1]);
if(!fork()) {
execl("/bin/sh","sh",0); close(n); exit(0); }
FD_ZERO(&rd); FD_ZERO(&wr);
FD_SET(0,&rd); FD_SET(1,&wr);
select(i[1]+1,&rd,&wr,0,0);
while(1) {
if(FD_ISSET(0,&rd)) { read(0,wb,1); }
if(FD_ISSET(1,&wr)) { read(1,wb,1); }
}}
I want the client's interaction (connecting via telnet) to work via
select. This is because, later I will add blowfish encryption routines
within FD_ISSET() Which will be encrypting/decrypting stdin/stdout of
the child process.
Am I headed in the right direction by using the functions I have?
Thanks in advance
PC
and forking a shell with execl() and controlling the shell's
stdin/stdout from the parent with select()?
Heres a little snippet of code. it doesnt actually work.. but it is
how I envisioned it::
if((n=accept(s,(struct sockaddr *)&remote,&sz))==-1)
{printf("accept\n"); exit(0);}
close(0); close(1); close(2);
pipe(&i[0]);
dup2(0,i[0]);
dup2(1,i[1]);
dup2(n,i[0]);
dup2(n,i[1]);
if(!fork()) {
execl("/bin/sh","sh",0); close(n); exit(0); }
FD_ZERO(&rd); FD_ZERO(&wr);
FD_SET(0,&rd); FD_SET(1,&wr);
select(i[1]+1,&rd,&wr,0,0);
while(1) {
if(FD_ISSET(0,&rd)) { read(0,wb,1); }
if(FD_ISSET(1,&wr)) { read(1,wb,1); }
}}
I want the client's interaction (connecting via telnet) to work via
select. This is because, later I will add blowfish encryption routines
within FD_ISSET() Which will be encrypting/decrypting stdin/stdout of
the child process.
Am I headed in the right direction by using the functions I have?
Thanks in advance
PC