File pee.c changed (mode: 100644) (index a8565c0..9243f4e) |
1 |
1 |
#include <stdlib.h> |
#include <stdlib.h> |
2 |
2 |
#include <stdio.h> |
#include <stdio.h> |
|
3 |
|
#include <string.h> |
3 |
4 |
#include <sys/types.h> |
#include <sys/types.h> |
4 |
5 |
#include <sys/wait.h> |
#include <sys/wait.h> |
5 |
6 |
|
|
|
... |
... |
close_pipes(FILE **p, size_t i) |
28 |
29 |
|
|
29 |
30 |
int |
int |
30 |
31 |
main(int argc, char **argv) { |
main(int argc, char **argv) { |
|
32 |
|
int ignore_write_error = 1; |
|
33 |
|
int ignore_sigpipe = 1; |
31 |
34 |
size_t i, r; |
size_t i, r; |
32 |
35 |
FILE **pipes; |
FILE **pipes; |
|
36 |
|
int *inactive_pipe; |
|
37 |
|
int inactive_pipes = 0; |
33 |
38 |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
34 |
39 |
|
|
|
40 |
|
while(argc > 1) { |
|
41 |
|
if (!strcmp(argv[1], "--no-ignore-sigpipe")) { |
|
42 |
|
argc--, argv++; |
|
43 |
|
ignore_sigpipe = 0; |
|
44 |
|
continue; |
|
45 |
|
} else if (!strcmp(argv[1], "--ignore-sigpipe")) { |
|
46 |
|
argc--, argv++; |
|
47 |
|
ignore_sigpipe = 1; |
|
48 |
|
continue; |
|
49 |
|
} else if (!strcmp(argv[1], "--no-ignore-write-errors")) { |
|
50 |
|
argc--, argv++; |
|
51 |
|
ignore_write_error = 0; |
|
52 |
|
continue; |
|
53 |
|
} else if (!strcmp(argv[1], "--ignore-write-errors")) { |
|
54 |
|
argc--, argv++; |
|
55 |
|
ignore_write_error = 1; |
|
56 |
|
continue; |
|
57 |
|
} |
|
58 |
|
break; |
|
59 |
|
} |
|
60 |
|
|
|
61 |
|
if (ignore_sigpipe && (signal(SIGPIPE, SIG_IGN) == SIG_ERR)) { |
|
62 |
|
fprintf(stderr, "Unable to ignore SIGPIPE\n"); |
|
63 |
|
exit(EXIT_FAILURE); |
|
64 |
|
} |
|
65 |
|
|
35 |
66 |
pipes = malloc(((argc - 1) * sizeof *pipes)); |
pipes = malloc(((argc - 1) * sizeof *pipes)); |
36 |
|
if (!pipes) |
|
|
67 |
|
inactive_pipe = calloc((argc - 1), (sizeof *inactive_pipe)); |
|
68 |
|
if (!pipes || !inactive_pipe) |
37 |
69 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
38 |
70 |
|
|
39 |
71 |
for (i = 1; i < argc; i++) { |
for (i = 1; i < argc; i++) { |
|
... |
... |
main(int argc, char **argv) { |
46 |
78 |
} |
} |
47 |
79 |
} |
} |
48 |
80 |
argc--; |
argc--; |
49 |
|
|
|
|
81 |
|
|
50 |
82 |
while(!feof(stdin) && (!ferror(stdin))) { |
while(!feof(stdin) && (!ferror(stdin))) { |
51 |
83 |
r = fread(buf, sizeof(char), BUFSIZ, stdin); |
r = fread(buf, sizeof(char), BUFSIZ, stdin); |
52 |
84 |
for(i = 0; i < argc; i++) { |
for(i = 0; i < argc; i++) { |
53 |
|
if (fwrite(buf, sizeof(char), r, pipes[i]) != r) { |
|
54 |
|
fprintf(stderr, "Write error to `%s\'\n", argv[i + 1]); |
|
|
85 |
|
if (inactive_pipe[i]) |
|
86 |
|
continue; |
|
87 |
|
|
|
88 |
|
if (fwrite(buf, sizeof(char), r, pipes[i]) == r) |
|
89 |
|
continue; |
|
90 |
|
|
|
91 |
|
inactive_pipes++; |
|
92 |
|
|
|
93 |
|
if (!ignore_write_error) |
|
94 |
|
fprintf(stderr, "Write error to `%s\'\n", |
|
95 |
|
argv[i + 1]); |
|
96 |
|
|
|
97 |
|
if (!ignore_write_error || (inactive_pipes == argc)) { |
55 |
98 |
close_pipes(pipes, argc); |
close_pipes(pipes, argc); |
56 |
99 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
57 |
100 |
} |
} |
|
101 |
|
|
|
102 |
|
inactive_pipe[i] = 1; |
58 |
103 |
} |
} |
59 |
104 |
} |
} |
60 |
105 |
exit(close_pipes(pipes, argc)); |
exit(close_pipes(pipes, argc)); |
File pee.docbook changed (mode: 100644) (index f554ad0..4030629) |
... |
... |
with this program; if not, write to the Free Software Foundation, Inc., |
33 |
33 |
<firstname>Joey</firstname> |
<firstname>Joey</firstname> |
34 |
34 |
<surname>Hess</surname> |
<surname>Hess</surname> |
35 |
35 |
</author> |
</author> |
36 |
|
<date>2006-03-14</date> |
|
|
36 |
|
<date>2016-12-20</date> |
37 |
37 |
</refentryinfo> |
</refentryinfo> |
38 |
38 |
|
|
39 |
39 |
<refmeta> |
<refmeta> |
|
... |
... |
with this program; if not, write to the Free Software Foundation, Inc., |
51 |
51 |
<refsynopsisdiv> |
<refsynopsisdiv> |
52 |
52 |
<cmdsynopsis> |
<cmdsynopsis> |
53 |
53 |
<command>pee</command> |
<command>pee</command> |
|
54 |
|
<arg>--[no-]ignore-sigpipe</arg> |
|
55 |
|
<arg>--[no-]ignore-write-errors</arg> |
54 |
56 |
<group choice="opt"> |
<group choice="opt"> |
55 |
57 |
<arg rep="repeat"><replaceable>"command"</replaceable></arg> |
<arg rep="repeat"><replaceable>"command"</replaceable></arg> |
56 |
58 |
</group> |
</group> |
|
... |
... |
with this program; if not, write to the Free Software Foundation, Inc., |
70 |
72 |
to stdout, like tee does. If that is desired, use |
to stdout, like tee does. If that is desired, use |
71 |
73 |
<command>pee cat ...</command></para> |
<command>pee cat ...</command></para> |
72 |
74 |
</refsect1> |
</refsect1> |
|
75 |
|
|
|
76 |
|
<refsect1> |
|
77 |
|
<title>OPTIONS</title> |
|
78 |
|
|
|
79 |
|
<variablelist> |
|
80 |
|
<varlistentry> |
|
81 |
|
<term><option>--ignore-sigpipe</option></term> |
|
82 |
|
<term><option>--no-ignore-sigpipe</option></term> |
|
83 |
|
<listitem> |
|
84 |
|
<para>Do (not) ignore SIGPIPE. Any command started |
|
85 |
|
by <command>pee</command> might cause a SIGPIPE |
|
86 |
|
when it exists. If you ignore SIGPIPE, you |
|
87 |
|
probably also want to ignore write errors (see |
|
88 |
|
below). Ignoring SIGPIPE is the default |
|
89 |
|
behaviour.</para> |
|
90 |
|
</listitem> |
|
91 |
|
</varlistentry> |
|
92 |
|
|
|
93 |
|
<varlistentry> |
|
94 |
|
<term><option>--ignore-write-errors</option></term> |
|
95 |
|
<term><option>--no-ignore-write-errors</option></term> |
|
96 |
|
<listitem> |
|
97 |
|
<para>Do (not) ignore write errors. When a command |
|
98 |
|
started by <command>pee</command> is no more |
|
99 |
|
accepting data via the pipe between itself and |
|
100 |
|
<command>pee</command>, a write error occurs in |
|
101 |
|
<command>pee</command>. If this error is not |
|
102 |
|
ignored, <command>pee</command> is going to |
|
103 |
|
terminate all child processes and exists. Ignoring |
|
104 |
|
write errors is the default behaviour.</para> |
|
105 |
|
</listitem> |
|
106 |
|
</varlistentry> |
|
107 |
|
|
|
108 |
|
</variablelist> |
|
109 |
|
</refsect1> |
73 |
110 |
|
|
74 |
111 |
<refsect1> |
<refsect1> |
75 |
112 |
<title>SEE ALSO</title> |
<title>SEE ALSO</title> |
|
... |
... |
with this program; if not, write to the Free Software Foundation, Inc., |
77 |
114 |
<para> |
<para> |
78 |
115 |
<citerefentry> |
<citerefentry> |
79 |
116 |
<refentrytitle>tee</refentrytitle><manvolnum>1</manvolnum> |
<refentrytitle>tee</refentrytitle><manvolnum>1</manvolnum> |
|
117 |
|
</citerefentry>, |
|
118 |
|
<citerefentry> |
|
119 |
|
<refentrytitle>pipe</refentrytitle><manvolnum>7</manvolnum> |
80 |
120 |
</citerefentry> |
</citerefentry> |
81 |
121 |
</para> |
</para> |
82 |
122 |
|
|