Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: d_gethname.U,v 3.0.1.1 1994/10/29 16:13:00 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, 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 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: d_gethname.U,v $ | |
12 | ?RCS: Revision 3.0.1.1 1994/10/29 16:13:00 ram | |
13 | ?RCS: patch36: call ./xenix explicitely instead of relying on PATH | |
14 | ?RCS: | |
15 | ?RCS: Revision 3.0 1993/08/18 12:06:11 ram | |
16 | ?RCS: Baseline for dist 3.0 netwide release. | |
17 | ?RCS: | |
18 | ?MAKE:d_gethname d_uname d_phostname aphostname: phostname cat \ | |
19 | myhostname package d_portable Loc libc echo n c +i_whoami +usrinc \ | |
20 | Myread Guess Oldconfig Csym | |
21 | ?MAKE: -pick add $@ %< | |
22 | ?S:d_gethname: | |
23 | ?S: This variable conditionally defines the HAS_GETHOSTNAME symbol, which | |
24 | ?S: indicates to the C program that the gethostname() routine may be | |
25 | ?S: used to derive the host name. | |
26 | ?S:. | |
27 | ?S:d_uname: | |
28 | ?S: This variable conditionally defines the HAS_UNAME symbol, which | |
29 | ?S: indicates to the C program that the uname() routine may be | |
30 | ?S: used to derive the host name. | |
31 | ?S:. | |
32 | ?S:d_phostname: | |
33 | ?S: This variable conditionally defines the HAS_PHOSTNAME symbol, which | |
34 | ?S: contains the shell command which, when fed to popen(), may be | |
35 | ?S: used to derive the host name. | |
36 | ?S:. | |
37 | ?S:aphostname: | |
38 | ?S: This variable contains the command which can be used to compute the | |
39 | ?S: host name. The command is fully qualified by its absolute path, to make | |
40 | ?S: it safe when used by a process with super-user privileges. | |
41 | ?S:. | |
42 | ?C:HAS_GETHOSTNAME (GETHOSTNAME): | |
43 | ?C: This symbol, if defined, indicates that the C program may use the | |
44 | ?C: gethostname() routine to derive the host name. See also HAS_UNAME | |
45 | ?C: and PHOSTNAME. | |
46 | ?C:. | |
47 | ?C:HAS_UNAME (UNAME): | |
48 | ?C: This symbol, if defined, indicates that the C program may use the | |
49 | ?C: uname() routine to derive the host name. See also HAS_GETHOSTNAME | |
50 | ?C: and PHOSTNAME. | |
51 | ?C:. | |
52 | ?C:PHOSTNAME: | |
53 | ?C: This symbol, if defined, indicates the command to feed to the | |
54 | ?C: popen() routine to derive the host name. See also HAS_GETHOSTNAME | |
55 | ?C: and HAS_UNAME. Note that the command uses a fully qualified path, | |
56 | ?C: so that it is safe even if used by a process with super-user | |
57 | ?C: privileges. | |
58 | ?C:. | |
59 | ?C:HAS_PHOSTNAME: | |
60 | ?C: This symbol, if defined, indicates that the C program may use the | |
61 | ?C: contents of PHOSTNAME as a command to feed to the popen() routine | |
62 | ?C: to derive the host name. | |
63 | ?C:. | |
64 | ?H:?%<:#$d_gethname HAS_GETHOSTNAME /**/ | |
65 | ?H:?%<:#$d_uname HAS_UNAME /**/ | |
d088635c | 66 | ?H:?%<:#$d_phostname HAS_PHOSTNAME /**/ |
959f3c4c JH |
67 | ?H:?%<:#ifdef HAS_PHOSTNAME |
68 | ?H:?%<:#define PHOSTNAME "$aphostname" /* How to get the host name */ | |
69 | ?H:?%<:#endif | |
70 | ?H:. | |
71 | ?T:file val call | |
72 | ?LINT:change i_whoami | |
73 | ?LINT:change PHOSTNAME | |
74 | : see how we will look up host name | |
75 | echo " " | |
76 | call='' | |
77 | @if HAS_GETHOSTNAME | |
78 | if set gethostname val -f d_gethname; eval $csym; $val; then | |
79 | echo 'gethostname() found.' >&4 | |
80 | d_gethname="$define" | |
81 | call=gethostname | |
82 | fi | |
83 | @end | |
84 | @if HAS_UNAME | |
85 | if set uname val -f d_uname; eval $csym; $val; then | |
86 | if ./xenix; then | |
87 | $cat <<'EOM' | |
88 | uname() was found, but you're running xenix, and older versions of xenix | |
89 | have a broken uname(). If you don't really know whether your xenix is old | |
90 | enough to have a broken system call, use the default answer. | |
91 | ||
92 | EOM | |
93 | dflt=y | |
94 | case "$d_uname" in | |
95 | "$define") dflt=n;; | |
96 | esac | |
97 | rp='Is your uname() broken?' | |
98 | . ./myread | |
99 | case "$ans" in | |
100 | n*) d_uname="$define"; call=uname;; | |
101 | esac | |
102 | else | |
103 | echo 'uname() found.' >&4 | |
104 | d_uname="$define" | |
105 | case "$call" in | |
106 | '') call=uname ;; | |
107 | esac | |
108 | fi | |
109 | fi | |
110 | @end | |
111 | case "$d_gethname" in | |
112 | '') d_gethname="$undef";; | |
113 | esac | |
114 | case "$d_uname" in | |
115 | '') d_uname="$undef";; | |
116 | esac | |
117 | @if PHOSTNAME || MYHOSTNAME | |
118 | case "$d_uname$d_gethname" in | |
119 | *define*) | |
120 | dflt=n | |
121 | cat <<EOM | |
122 | ||
123 | Every now and then someone has a $call() that lies about the hostname | |
124 | but can't be fixed for political or economic reasons. If you wish, I can | |
125 | @if MYHOSTNAME && PHOSTNAME | |
126 | pretend $call() isn't there and maybe compile in the hostname or | |
127 | compute it from the '$phostname' command at run-time. | |
128 | @elsif MYHOSTNAME | |
129 | pretend $call() isn't there and maybe compile in the hostname. | |
130 | @elsif PHOSTNAME | |
131 | pretend $call() isn't there and maybe compute hostname at run-time | |
132 | thanks to the '$phostname' command. | |
133 | @elsif WHOAMI | |
134 | get the hostname from whomai.h (provided you have one). | |
135 | @else | |
136 | simply ignore your host name and use someting like "noname" instead. | |
137 | @end | |
138 | ||
139 | EOM | |
140 | rp="Shall I ignore $call() from now on?" | |
141 | . ./myread | |
142 | case "$ans" in | |
143 | y*) d_uname="$undef" d_gethname="$undef"; $echo $n "Okay...$c";; | |
144 | esac;; | |
145 | esac | |
146 | @end | |
147 | @if PHOSTNAME || aphostname | |
148 | ?X: Compute the full path name for the command | |
149 | case "$phostname" in | |
150 | '') aphostname='';; | |
151 | *) case "$aphostname" in | |
152 | /*) ;; | |
153 | *) set X $phostname | |
154 | shift | |
155 | file=$1 | |
156 | shift | |
157 | file=`./loc $file $file $pth` | |
158 | aphostname=`echo $file $*` | |
159 | ;; | |
160 | esac | |
161 | ;; | |
162 | esac | |
163 | @end | |
164 | @if PHOSTNAME && MYHOSTNAME | |
165 | case "$d_uname$d_gethname" in | |
166 | *define*) ;; | |
167 | *) | |
168 | case "$phostname" in | |
169 | '') ;; | |
170 | *) | |
171 | $cat <<EOT | |
172 | ||
173 | There is no gethostname() or uname() on this system. You have two | |
174 | possibilities at this point: | |
175 | ||
176 | 1) You can have your host name ($myhostname) compiled into $package, which | |
177 | lets $package start up faster, but makes your binaries non-portable, or | |
178 | 2) you can have $package use a | |
179 | ||
180 | popen("$aphostname","r") | |
181 | ||
182 | which will start slower but be more portable. | |
183 | ||
184 | @ if WHOAMI | |
185 | Option 1 will give you the option of using whoami.h if you have one. | |
186 | @ end | |
187 | If you want option 2 but with a different command, you can edit config.sh at | |
188 | the end of this shell script. | |
189 | ||
190 | EOT | |
191 | case "$d_phostname" in | |
192 | "$define") dflt=n;; | |
193 | "$undef") dflt=y;; | |
194 | '') | |
195 | case "$d_portable" in | |
196 | "$define") dflt=n ;; | |
197 | *) dflt=y ;; | |
198 | esac;; | |
199 | esac | |
200 | rp="Do you want your host name compiled in?" | |
201 | . ./myread | |
202 | case "$ans" in | |
203 | n*) d_phostname="$define" ;; | |
204 | *) aphostname=''; d_phostname="$undef";; | |
205 | esac;; | |
206 | esac | |
207 | case "$aphostname" in | |
208 | '') | |
209 | @ if WHOAMI | |
210 | case "$i_whoami" in | |
211 | "$define") | |
212 | dflt=y | |
213 | $cat <<EOM | |
214 | ||
215 | No hostname function--you can either use the whoami.h file, which has this line: | |
216 | ||
217 | `grep sysname $usrinc/whoami.h` | |
218 | ||
219 | or you can have the name we came up with earlier ($myhostname) hardwired in. | |
220 | EOM | |
221 | rp="Use whoami.h to get hostname?" | |
222 | . ./myread | |
223 | case "$ans" in | |
224 | n*) i_whoami="$undef";; | |
225 | esac | |
226 | ;; | |
227 | "$undef") | |
228 | $cat <<EOM | |
229 | No hostname function and no whoami.h -- hardwiring "$myhostname". | |
230 | EOM | |
231 | ;; | |
232 | esac;; | |
233 | @ else | |
234 | echo 'No hostname function -- hardwiring "'$myhostname'".' >&4;; | |
235 | @ end | |
236 | esac;; | |
237 | esac | |
238 | @elsif PHOSTNAME | |
239 | case "$d_uname$d_gethname" in | |
240 | *define*) ;; | |
241 | *) | |
242 | case "$phostname" in | |
243 | '') | |
244 | @ if WHOAMI | |
245 | case "$i_whoami" in | |
246 | "$define") | |
247 | $cat <<EOM | |
248 | ||
249 | No hostname function--we'll use the whoami.h file, which has this line: | |
250 | ||
251 | `grep sysname $usrinc/whoami.h` | |
252 | ||
253 | EOM | |
254 | ;; | |
255 | *) echo "There will be no way for $package to get your hostname." >&4;; | |
256 | esac;; | |
257 | @ else | |
258 | echo "There will be no way for $package to get your hostname." >&4;; | |
259 | @ end | |
260 | *) | |
261 | echo "I'll use 'popen("'"'$aphostname'", "r")'"' to get your hostname." >&4 | |
262 | ;; | |
263 | esac;; | |
264 | esac | |
265 | @elsif MYHOSTNAME | |
266 | case "$d_uname$d_gethname" in | |
267 | *define*) ;; | |
268 | *) | |
269 | @ if WHOAMI | |
270 | case "$i_whoami" in | |
271 | "$define") | |
272 | dflt=y | |
273 | $cat <<EOM | |
274 | ||
275 | No hostname function--you can either use the whoami.h file, which has this line: | |
276 | ||
277 | `grep sysname $usrinc/whoami.h` | |
278 | ||
279 | or you can have the name we came up with earlier ($myhostname) hardwired in. | |
280 | EOM | |
281 | rp="Use whoami.h to get hostname?" | |
282 | . ./myread | |
283 | case "$ans" in | |
284 | n*) i_whoami="$undef";; | |
285 | esac | |
286 | ;; | |
287 | "$undef") | |
288 | echo 'No whoami.h--hardwiring "'$myhostname'".' >&4;; | |
289 | esac;; | |
290 | @ else | |
291 | echo 'Hardwiring "'$myhostname'".' >&4;; | |
292 | @ end | |
293 | esac | |
294 | @end | |
295 | case "$d_phostname" in | |
296 | '') d_phostname="$undef";; | |
297 | esac | |
298 |