summaryrefslogtreecommitdiff
path: root/mcon/U/d_NOFILE.U
blob: d602b51809a60be8dc5d2964b2cea00d0a146422 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: d_NOFILE.U,v $
?RCS: Revision 3.0.1.1  1994/10/29  16:08:38  ram
?RCS: patch36: added ?F: line for metalint file checking
?RCS:
?RCS: Revision 3.0  1993/08/18  12:05:39  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:nofile d_gettblsz tablesize: Myread Guess cat +cc +ccflags +libs \
	test rm Csym
?MAKE:	-pick add $@ %<
?S:nofile:
?S:	This variable contains the number of file descriptors available to the
?S:	process.
?S:.
?S:d_gettblsz:
?S:	This variable conditionally handles remapping of the getdtablesize()
?S:	subroutine to ulimit(4,0), or the NOFILE manifest constant.
?S:.
?S:tablesize:
?S:	This variable contains either the 'NOFILE' constant or 'ulimit(4, 0L)'
?S:	and is used as the remapped value for the getdtablesize() macro.
?S:.
?C:getdtablesize:
?C:	This catches use of the getdtablesize() subroutine, and remaps it
?C:	to either ulimit(4,0) or NOFILE, if getdtablesize() isn't available.
?C:.
?C:VAL_NOFILE:
?C:	This symbol contains the number of file descriptors available to the
?C:	process, as determined at configuration time. Unless a static constant
?C:	is needed, you should rely on getdtablesize() to obtain that number.
?C:.
?H:#$d_gettblsz getdtablesize() $tablesize	/**/
?H:#define VAL_NOFILE $nofile	/* Number of file descriptors */
?H:.
?F:!nofile
?T:d_ulimit4 val
: see if getdtablesize exists
echo " "
?X: Revert logical value (d_gettblsz is undef iff getdtablesize is present)
case "$d_gettblsz" in
$define) d_gettblsz="$undef";;
$undef) d_gettblsz="$define";;
esac
if set getdtablesize val -f d_gettblsz; eval $csym; $val; then
	echo 'getdtablesize() found.' >&4
	d_gettblsz="$undef"
	tablesize=''
@if VAL_NOFILE || nofile
	$cat >nofile.c <<'EOCP'
#include <stdio.h>
int main()
{
	printf("%d\n", getdtablesize());
}
EOCP
	nofile=''
	if $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1; then
		nofile=`./nofile 2>/dev/null`
	fi
	if $test "$nofile"; then
		echo "(You have $nofile file descriptors available per process.)"
	else
		nofile='20'
		if ./bsd; then
			nofile='64'
		fi
	echo "(Hmm... Let's say you have $nofile file descriptors available.)"
	fi
@end
else
	echo 'getdtablesize() NOT found...' >&4
	if set ulimit val -f; eval $csym; $val; then
		echo 'Maybe ulimit(4,0) will work...'
		$cat >nofile.c <<'EOCP'
#include <stdio.h>
#ifdef GETPARAM_H
#include <sys/param.h>
#endif
int main()
{
	printf("%d %d\n",
#ifdef NOFILE
		NOFILE,
#else
		0,
#endif
		ulimit(4,0));
		exit(0);
}
EOCP
		if $cc $ccflags -DGETPARAM_H -o nofile nofile.c $libs >/dev/null 2>&1 \
			|| $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1 ; then
			set `./nofile`
			d_gettblsz=$1
			d_ulimit4=$2
			if $test "$d_ulimit4" -lt 0; then
				echo "Your ulimit() call doesn't tell me what I want to know."
				echo "We'll just use NOFILE in this case."
				nofile=$d_gettblsz
				d_gettblsz="$define"
				tablesize='NOFILE'
			else
				if $test "$d_gettblsz" -gt 0; then
				echo "Your system defines NOFILE to be $d_gettblsz, and" >&4
				else
				echo "I had trouble getting NOFILE from your system, but" >&4
				fi
echo "ulimit returns $d_ulimit4 as the number of available file descriptors." >&4
				dflt='y';
				echo " "
	rp='Should I use ulimit to get the number of available file descriptors?'
				. ./myread
				case "$ans" in
				y*)
					nofile=$d_ulimit4
					d_gettblsz="$define"
					tablesize='ulimit(4, 0L)'
					echo "Using ulimit(4,0)."
					;;
				*)
					nofile=$d_gettblsz
					d_gettblsz="$define"
					tablesize='NOFILE'
					echo "Using NOFILE."
					;;
				esac
			fi
		else
			echo "Strange, I couldn't get my test program to compile."
			echo "We'll just use NOFILE in this case."
			d_gettblsz="$define"
			tablesize='NOFILE'
			nofile=''
		fi
	else
		echo 'Using NOFILE instead.'
		d_gettblsz="$define"
		tablesize='NOFILE'
		nofile=''
	fi
fi
@if VAL_NOFILE || nofile
case "$nofile" in
'')
	$cat >nofile.c <<'EOCP'
#include <stdio.h>
#ifdef GETPARAM_H
#include <sys/param.h>
#endif
int main()
{
	printf("%d\n",
#ifdef NOFILE
		NOFILE,
#else
		0,
#endif
		);
		exit(0);
}
EOCP
	if $cc $ccflags -DGETPARAM_H -o nofile nofile.c $libs >/dev/null 2>&1 \
		|| $cc $ccflags -o nofile nofile.c $libs >/dev/null 2>&1 ; then
		nofile=`./nofile 2>/dev/null`
	fi
	if $test "$nofile"; then
		echo "(You have $nofile file descriptors available per process.)"
	else
		nofile='20'
		if ./bsd; then
			nofile='64'
		fi
	echo "(Hmm... Let's say you have $nofile file descriptors available.)"
	fi
	;;
esac
@end
$rm -f nofile*