Annotation of libaitio/example/test_exec.c, revision 1.1.2.10
1.1.2.1 misho 1: #include <stdio.h>
1.1.2.7 misho 2: #include <unistd.h>
3: #include <string.h>
4: #include <errno.h>
1.1.2.1 misho 5: #include <aitio.h>
1.1.2.3 misho 6: #include <sys/wait.h>
1.1.2.1 misho 7:
8:
9: int
10: main(int argc, char **argv)
11: {
1.1.2.2 misho 12: prog_t *p;
1.1.2.8 misho 13: int f;
1.1.2.4 misho 14: int ret = 0;
1.1.2.7 misho 15: char str[BUFSIZ];
1.1.2.2 misho 16:
1.1.2.1 misho 17: if (argc < 2)
18: return 1;
19:
1.1.2.2 misho 20: p = io_progInit(argv[1], 3, 10);
21: if (!p) {
22: ELIBERR(io);
23: return 2;
1.1.2.4 misho 24: } else if ((ret = io_progCheck(p))) {
25: printf("0.exited procs=%d\n", ret);
26: goto end;
1.1.2.2 misho 27: } else {
28: printf("wait for keystroke %p ", p);
29: getchar();
30: }
31:
1.1.2.4 misho 32: ret = io_progCheck(p);
33: if (ret) {
34: printf("1.exited procs=%d\n", ret);
35: goto end;
36: }
1.1.2.3 misho 37:
1.1.2.5 misho 38: printf("last=%d\n", array_Last(p->prog_fds));
39:
1.1.2.6 misho 40: ret = io_progGrow(p, 8);
41: printf("+grow_progs=%d\n", ret);
42:
43: printf("wait for keystroke %p ", p);
44: getchar();
45:
46: ret = io_progVacuum(p, 5);
47: printf("+vacuum_progs=%d\n", ret);
1.1.2.5 misho 48:
49: printf("wait for keystroke %p ", p);
50: getchar();
1.1.2.7 misho 51:
52: again:
53: f = io_progAttach(p);
1.1.2.8 misho 54: printf("f=%d\n", f);
1.1.2.10! misho 55: write(f, "\n", 1);
! 56: memset(str, 0, sizeof str);
1.1.2.8 misho 57: while (read(f, str, sizeof str) > 0) {
1.1.2.7 misho 58: printf(">>> %s", str);
1.1.2.10! misho 59: memset(str, 0, sizeof str);
1.1.2.8 misho 60: read(0, str, sizeof str);
1.1.2.7 misho 61: if (*str == '.')
62: break;
1.1.2.8 misho 63: write(f, str, strlen(str));
1.1.2.7 misho 64: }
65: io_progDetach(p, f);
66:
1.1.2.10! misho 67: printf("(r) wait for keystroke %p ", p);
1.1.2.7 misho 68: if (getchar() == 'a')
69: goto again;
1.1.2.4 misho 70: end:
1.1.2.2 misho 71: io_progDestroy(&p);
1.1.2.4 misho 72: return ret;
1.1.2.1 misho 73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>