libowfat/test/fdpassing.c

41 lines
668 B
C
Raw Normal View History

2004-02-27 14:47:31 +00:00
#include <unistd.h>
#include "io.h"
#include "buffer.h"
2004-11-25 21:52:35 +00:00
#include <stdlib.h>
2004-02-27 14:47:31 +00:00
void child(int64 fd) {
int64 x=io_receivefd(fd);
char buf[8192];
int i;
if (x==-1) {
buffer_putsflush(buffer_2,"fd passing failed!\n");
exit(1);
}
i=read(x,buf,sizeof(buf));
write(1,buf,i);
io_close(x);
}
void father(int64 fd) {
int64 x;
if (io_readfile(&x,"/etc/resolv.conf"))
io_passfd(fd,x);
}
2004-11-25 21:52:35 +00:00
int main() {
2004-02-27 14:47:31 +00:00
int64 sp[2];
if (io_socketpair(sp)==-1) return 1;
switch (fork()) {
case -1: return 1;
case 0: /* child */
io_close(sp[0]);
child(sp[1]);
break;
default:
io_close(sp[1]);
father(sp[0]);
break;
}
return 0;
}