Annotation of embedaddon/lrzsz/beos-runpiped.c, revision 1.1.1.1
1.1 misho 1: #include <fcntl.h>
2: #include <unistd.h>
3: #include <be/kernel/OS.h>
4:
5: int main(int argc, char **argv)
6: {
7: int pid,fd1,fd2;
8: sem_id sem1,sem2;
9: sem1=create_sem(1,"piperun");
10: sem2=create_sem(1,"piperun");
11: if (sem1<B_NO_ERROR ||sem2<B_NO_ERROR) {
12: perror("create_sem");
13: exit(1);
14: }
15: acquire_sem(sem1);
16: acquire_sem(sem2);
17: pid=fork();
18: if (pid==0) {
19: fd1=open("/pipe/1",O_WRONLY|O_CREAT,0666);
20: if (fd1==-1) {
21: perror("writer: /pipe/1");
22: _exit(1);
23: }
24: release_sem(sem1);
25: /* wait for other side to open the pipe 1 */
26: acquire_sem(sem2);
27: /* wait for creation of pipe 2 */
28: acquire_sem(sem1);
29: fd2=open("/pipe/2",O_RDONLY);
30: if (fd2==-1) {
31: perror("/pipe/2");
32: _exit(1);
33: }
34: release_sem(sem2);
35: dup2(fd2,0);
36: dup2(fd1,1);
37: system(argv[2]);
38:
39: _exit(1);
40: }
41: acquire_sem(sem1);
42: fd1=open("/pipe/1",O_RDONLY);
43: release_sem(sem2);
44: if (fd1==-1) {
45: perror("/pipe/1");
46: exit(1);
47: }
48: fd2=open("/pipe/2",O_WRONLY|O_CREAT,0666);
49: if (fd2==-1) {
50: perror("writer: /pipe/2");
51: exit(1);
52: }
53: release_sem(sem1);
54: /* wait for child to open ... */
55: acquire_sem(sem2);
56: dup2(fd1,0);
57: dup2(fd2,1);
58: system(argv[1]);
59: exit(0);
60: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>