Commit | Line | Data |
---|---|---|
d8875586 MBT |
1 | ?RCS: $Id: d_eofpipe.U 1 2006-08-24 12:32:52Z rmanfredi $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 4.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: d_eofpipe.U,v $ | |
12 | ?RCS: Revision 3.0.1.1 1994/10/29 16:12:40 ram | |
13 | ?RCS: patch36: call ./bsd explicitly instead of relying on PATH | |
14 | ?RCS: | |
15 | ?RCS: Revision 3.0 1993/08/18 12:05:57 ram | |
16 | ?RCS: Baseline for dist 3.0 netwide release. | |
17 | ?RCS: | |
18 | ?MAKE:d_eofpipe: cat +cc +ccflags +libs rm Oldconfig Guess echo n c | |
19 | ?MAKE: -pick add $@ %< | |
20 | ?S:d_eofpipe: | |
21 | ?S: This variable conditionally defines the EOFPIPE symbol, which | |
22 | ?S: indicates to the C program that select will correctly detect the EOF | |
23 | ?S: condition when pipe is closed from the other end. | |
24 | ?S:. | |
25 | ?C:EOFPIPE: | |
26 | ?C: This symbol, if defined, indicates that EOF condition will be detected | |
27 | ?C: by the reader of the pipe when it is closed by the writing process. | |
28 | ?C: That is, a select() call on that file descriptor will not block when | |
29 | ?C: only an EOF remains (typical behaviour for BSD systems). | |
30 | ?C:. | |
31 | ?H:#$d_eofpipe EOFPIPE /**/ | |
32 | ?H:. | |
33 | ?F:!mpipe | |
34 | : see if pipe correctly gives the EOF condition | |
35 | echo " " | |
36 | case "$d_eofpipe" in | |
37 | '') | |
38 | echo "Let's see if your pipes return EOF to select() upon closing..." >&4 | |
39 | $cat >pipe.c <<'EOP' | |
40 | int main() | |
41 | { | |
42 | int pd[2]; | |
43 | int mask; | |
44 | ||
45 | pipe(pd); | |
46 | if (0 == fork()) { | |
47 | close(pd[0]); | |
48 | close(pd[1]); | |
49 | exit(0); | |
50 | } | |
51 | ||
52 | close(pd[1]); | |
53 | mask = 1 << pd[0]; | |
54 | alarm(2); | |
55 | select(32, &mask, (int *) 0, (int *) 0, (char *) 0); | |
56 | if (0 == read(pd[0], &mask, 1)) | |
57 | exit(0); | |
58 | ||
59 | exit(1); | |
60 | } | |
61 | EOP | |
62 | if $cc $ccflags -o pipe pipe.c $libs >/dev/null 2>&1; then | |
63 | ?X: Use a script to avoid the possible 'alarm call' message | |
64 | echo "./pipe || exit 1" > mpipe | |
65 | chmod +x mpipe | |
66 | ./mpipe >/dev/null 2>&1 | |
67 | case $? in | |
68 | 0) d_eofpipe="$define";; | |
69 | *) d_eofpipe="$undef";; | |
70 | esac | |
71 | else | |
72 | echo "(The test program did not compile correctly -- Guessing.)" | |
73 | if ./bsd; then | |
74 | d_eofpipe="$define" | |
75 | else | |
76 | d_eofpipe="$undef" | |
77 | fi | |
78 | fi | |
79 | case "$d_eofpipe" in | |
80 | "$define") echo "Yes, they do.";; | |
81 | *) echo "No, they don't! (sigh)";; | |
82 | esac | |
83 | ;; | |
84 | *) | |
85 | $echo $n "Your pipes $c" | |
86 | case "$d_eofpipe" in | |
87 | "$define") echo "allow select() to see EOF upon closing.";; | |
88 | *) echo "won't let select() see EOF on closing.";; | |
89 | esac | |
90 | ;; | |
91 | esac | |
92 | $rm -f *pipe* core | |
93 |