]>
Commit | Line | Data |
---|---|---|
726f6388 JA |
1 | #! /bin/sh |
2 | # | |
3 | # psize.sh -- determine this system's pipe size, and write a define to | |
4 | # pipesize.h so ulimit.c can use it. | |
5 | ||
bb70624e | 6 | : ${TMPDIR:=/tmp} |
f73dda09 JA |
7 | # try to use mktemp(1) if the system supports it |
8 | { TMPFILE="`mktemp $TMPDIR/pipsize.XXXXXX 2>/dev/null`"; } 2>/dev/null | |
9 | used_mktemp=true | |
cce855bc | 10 | |
f73dda09 JA |
11 | if [ -z "$TMPFILE" ]; then |
12 | TMPNAME=pipsize.$$ | |
13 | TMPFILE=$TMPDIR/$TMPNAME | |
14 | used_mktemp=false | |
15 | fi | |
16 | ||
17 | trap 'rm -f "$TMPFILE" ; exit 1' 1 2 3 6 15 | |
18 | trap 'rm -f "$TMPFILE"' 0 | |
cce855bc | 19 | |
726f6388 JA |
20 | echo "/*" |
21 | echo " * pipesize.h" | |
22 | echo " *" | |
23 | echo " * This file is automatically generated by psize.sh" | |
24 | echo " * Do not edit!" | |
25 | echo " */" | |
26 | echo "" | |
27 | ||
cce855bc JA |
28 | # |
29 | # Try to avoid tempfile races. We can't really check for the file's | |
ac50fbac | 30 | # existence before we run psize.aux, because `test -e' is not portable, |
cce855bc | 31 | # `test -h' (test for symlinks) is not portable, and `test -f' only |
f73dda09 JA |
32 | # checks for regular files. If we used mktemp(1), we're ahead of the |
33 | # game. | |
cce855bc | 34 | # |
f73dda09 | 35 | $used_mktemp || rm -f "$TMPFILE" |
cce855bc | 36 | |
f73dda09 | 37 | ./psize.aux 2>"$TMPFILE" | sleep 3 |
726f6388 | 38 | |
f73dda09 JA |
39 | if [ -s "$TMPFILE" ]; then |
40 | echo "#define PIPESIZE `cat "$TMPFILE"`" | |
726f6388 JA |
41 | else |
42 | echo "#define PIPESIZE 512" | |
43 | fi | |
44 | ||
726f6388 | 45 | exit 0 |