1 |
|
|
/* |
2 |
|
|
* Copyright (c) 1990 Jan-Simon Pendry |
3 |
|
|
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine |
4 |
|
|
* Copyright (c) 1990, 1993 |
5 |
|
|
* The Regents of the University of California. All rights reserved. |
6 |
|
|
* |
7 |
|
|
* This code is derived from software contributed to Berkeley by |
8 |
|
|
* Jan-Simon Pendry at Imperial College, London. |
9 |
|
|
* |
10 |
|
|
* Redistribution and use in source and binary forms, with or without |
11 |
|
|
* modification, are permitted provided that the following conditions |
12 |
|
|
* are met: |
13 |
|
|
* 1. Redistributions of source code must retain the above copyright |
14 |
|
|
* notice, this list of conditions and the following disclaimer. |
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
16 |
|
|
* notice, this list of conditions and the following disclaimer in the |
17 |
|
|
* documentation and/or other materials provided with the distribution. |
18 |
|
|
* 3. Neither the name of the University nor the names of its contributors |
19 |
|
|
* may be used to endorse or promote products derived from this software |
20 |
|
|
* without specific prior written permission. |
21 |
|
|
* |
22 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 |
|
|
* SUCH DAMAGE. |
33 |
|
|
* |
34 |
|
|
* from: @(#)get_args.c 8.1 (Berkeley) 6/6/93 |
35 |
|
|
* $Id: get_args.c,v 1.14 2014/10/20 02:33:42 guenther Exp $ |
36 |
|
|
*/ |
37 |
|
|
|
38 |
|
|
/* |
39 |
|
|
* Argument decode |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#include "am.h" |
43 |
|
|
#include <syslog.h> |
44 |
|
|
#include <sys/stat.h> |
45 |
|
|
#include <unistd.h> |
46 |
|
|
|
47 |
|
|
extern int optind; |
48 |
|
|
extern char *optarg; |
49 |
|
|
|
50 |
|
|
#if defined(DEBUG) && defined(PARANOID) |
51 |
|
|
char **gargv; |
52 |
|
|
#endif /* defined(DEBUG) && defined(PARANOID) */ |
53 |
|
|
int restart_existing_mounts; |
54 |
|
|
int print_pid; |
55 |
|
|
int normalize_hosts; |
56 |
|
|
char *karch; /* Kernel architecture */ |
57 |
|
|
char *cluster; /* Cluster name */ |
58 |
|
|
char *domain; /* YP domain */ |
59 |
|
|
int afs_timeo = -1; |
60 |
|
|
int afs_retrans = -1; |
61 |
|
|
int am_timeo = AM_TTL; |
62 |
|
|
int am_timeo_w = AM_TTL_W; |
63 |
|
|
|
64 |
|
|
#ifdef DEBUG |
65 |
|
|
/* |
66 |
|
|
* List of debug options. |
67 |
|
|
*/ |
68 |
|
|
static struct opt_tab dbg_opt[] = { |
69 |
|
|
{ "all", D_ALL }, /* All */ |
70 |
|
|
{ "amq", D_AMQ }, /* Register for AMQ program */ |
71 |
|
|
{ "daemon", D_DAEMON }, /* Enter daemon mode */ |
72 |
|
|
{ "full", D_FULL }, /* Program trace */ |
73 |
|
|
{ "mem", D_MEM }, /* Trace memory allocations */ |
74 |
|
|
{ "mtab", D_MTAB }, /* Use local mtab file */ |
75 |
|
|
{ "str", D_STR }, /* Debug string munging */ |
76 |
|
|
{ "test", D_TEST }, /* Full debug - but no daemon */ |
77 |
|
|
{ "trace", D_TRACE }, /* Protocol trace */ |
78 |
|
|
{ 0, 0 } |
79 |
|
|
}; |
80 |
|
|
|
81 |
|
|
int debug_flags = D_AMQ /* Register AMQ */ |
82 |
|
|
|D_DAEMON /* Enter daemon mode */ |
83 |
|
|
; |
84 |
|
|
|
85 |
|
|
/* |
86 |
|
|
* Switch on/off debug options |
87 |
|
|
*/ |
88 |
|
|
int |
89 |
|
|
debug_option(char *opt) |
90 |
|
|
{ |
91 |
|
|
return cmdoption(opt, dbg_opt, &debug_flags); |
92 |
|
|
} |
93 |
|
|
#endif /* DEBUG */ |
94 |
|
|
|
95 |
|
|
void |
96 |
|
|
get_args(int c, char *v[]) |
97 |
|
|
{ |
98 |
|
|
int opt_ch; |
99 |
|
|
int usage = 0; |
100 |
|
|
char *logfile = "syslog"; |
101 |
|
|
char *sub_domain = 0; |
102 |
|
|
|
103 |
|
|
while ((opt_ch = getopt(c, v, "mnprva:c:d:h:k:l:t:w:x:y:C:D:")) != -1) |
104 |
|
|
switch (opt_ch) { |
105 |
|
|
case 'a': |
106 |
|
|
if (*optarg != '/') { |
107 |
|
|
fprintf(stderr, "%s: -a option must begin with a '/'\n", |
108 |
|
|
__progname); |
109 |
|
|
exit(1); |
110 |
|
|
} |
111 |
|
|
auto_dir = optarg; |
112 |
|
|
break; |
113 |
|
|
|
114 |
|
|
case 'c': |
115 |
|
|
am_timeo = atoi(optarg); |
116 |
|
|
if (am_timeo <= 0) |
117 |
|
|
am_timeo = AM_TTL; |
118 |
|
|
break; |
119 |
|
|
|
120 |
|
|
case 'd': |
121 |
|
|
sub_domain = optarg; |
122 |
|
|
break; |
123 |
|
|
|
124 |
|
|
case 'h': |
125 |
|
|
#if defined(HAS_HOST) && defined(HOST_EXEC) |
126 |
|
|
host_helper = optarg; |
127 |
|
|
#else |
128 |
|
|
plog(XLOG_USER, "-h: option ignored. HOST_EXEC is not enabled."); |
129 |
|
|
break; |
130 |
|
|
#endif /* defined(HAS_HOST) && defined(HOST_EXEC) */ |
131 |
|
|
|
132 |
|
|
case 'k': |
133 |
|
|
karch = optarg; |
134 |
|
|
break; |
135 |
|
|
|
136 |
|
|
case 'l': |
137 |
|
|
logfile = optarg; |
138 |
|
|
break; |
139 |
|
|
|
140 |
|
|
case 'm': |
141 |
|
|
plog(XLOG_USER, "The -m option is no longer supported."); |
142 |
|
|
plog(XLOG_USER, "... Use `ypcat -k am.master` on the command line instead"); |
143 |
|
|
break; |
144 |
|
|
|
145 |
|
|
case 'n': |
146 |
|
|
normalize_hosts = 1; |
147 |
|
|
break; |
148 |
|
|
|
149 |
|
|
case 'p': |
150 |
|
|
print_pid = 1; |
151 |
|
|
break; |
152 |
|
|
|
153 |
|
|
case 'r': |
154 |
|
|
restart_existing_mounts = 1; |
155 |
|
|
break; |
156 |
|
|
|
157 |
|
|
case 't': |
158 |
|
|
/* timeo.retrans */ |
159 |
|
|
{ char *dot = strchr(optarg, '.'); |
160 |
|
|
if (dot) *dot = '\0'; |
161 |
|
|
if (*optarg) { |
162 |
|
|
afs_timeo = atoi(optarg); |
163 |
|
|
} |
164 |
|
|
if (dot) { |
165 |
|
|
afs_retrans = atoi(dot+1); |
166 |
|
|
*dot = '.'; |
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
break; |
170 |
|
|
|
171 |
|
|
case 'v': |
172 |
|
|
fputs("Map support for: ", stderr); |
173 |
|
|
mapc_showtypes(stderr); |
174 |
|
|
fputs(".\nFS: ", stderr); |
175 |
|
|
ops_showfstypes(stderr); |
176 |
|
|
fputs(".\n", stderr); |
177 |
|
|
fprintf(stderr, "Primary network is %s.\n", wire); |
178 |
|
|
exit(0); |
179 |
|
|
break; |
180 |
|
|
|
181 |
|
|
case 'w': |
182 |
|
|
am_timeo_w = atoi(optarg); |
183 |
|
|
if (am_timeo_w <= 0) |
184 |
|
|
am_timeo_w = AM_TTL_W; |
185 |
|
|
break; |
186 |
|
|
|
187 |
|
|
case 'x': |
188 |
|
|
usage += switch_option(optarg); |
189 |
|
|
break; |
190 |
|
|
|
191 |
|
|
case 'y': |
192 |
|
|
domain = optarg; |
193 |
|
|
break; |
194 |
|
|
|
195 |
|
|
case 'C': |
196 |
|
|
cluster = optarg; |
197 |
|
|
break; |
198 |
|
|
|
199 |
|
|
case 'D': |
200 |
|
|
#ifdef DEBUG |
201 |
|
|
usage += debug_option(optarg); |
202 |
|
|
#else |
203 |
|
|
fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n", |
204 |
|
|
__progname); |
205 |
|
|
#endif /* DEBUG */ |
206 |
|
|
break; |
207 |
|
|
|
208 |
|
|
default: |
209 |
|
|
usage = 1; |
210 |
|
|
break; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
if (xlog_level_init == ~0) { |
214 |
|
|
(void) switch_option(""); |
215 |
|
|
#ifdef DEBUG |
216 |
|
|
usage += switch_option("debug"); |
217 |
|
|
#endif /* DEBUG */ |
218 |
|
|
} else { |
219 |
|
|
#ifdef DEBUG |
220 |
|
|
usage += switch_option("debug"); |
221 |
|
|
#endif /* DEBUG */ |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
if (usage) |
225 |
|
|
goto show_usage; |
226 |
|
|
|
227 |
|
|
while (optind <= c-2) { |
228 |
|
|
char *dir = v[optind++]; |
229 |
|
|
char *map = v[optind++]; |
230 |
|
|
char *opts = ""; |
231 |
|
|
if (v[optind] && *v[optind] == '-') |
232 |
|
|
opts = &v[optind++][1]; |
233 |
|
|
|
234 |
|
|
root_newmap(dir, opts, map); |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
if (optind == c) { |
238 |
|
|
|
239 |
|
|
/* |
240 |
|
|
* Append domain name to hostname. |
241 |
|
|
* sub_domain overrides hostdomain |
242 |
|
|
* if given. |
243 |
|
|
*/ |
244 |
|
|
if (sub_domain) |
245 |
|
|
hostdomain = sub_domain; |
246 |
|
|
if (*hostdomain == '.') |
247 |
|
|
hostdomain++; |
248 |
|
|
strlcat(hostd, ".", 2 * MAXHOSTNAMELEN); |
249 |
|
|
strlcat(hostd, hostdomain, 2 * MAXHOSTNAMELEN); |
250 |
|
|
|
251 |
|
|
#ifdef DEBUG |
252 |
|
|
{ if (debug_flags & D_MTAB) { |
253 |
|
|
dlog("-D mtab option ignored"); |
254 |
|
|
} } |
255 |
|
|
#endif /* DEBUG */ |
256 |
|
|
|
257 |
|
|
if (switch_to_logfile(logfile) != 0) |
258 |
|
|
plog(XLOG_USER, "Cannot switch logfile"); |
259 |
|
|
|
260 |
|
|
/* |
261 |
|
|
* If the kernel architecture was not specified |
262 |
|
|
* then use the machine architecture. |
263 |
|
|
*/ |
264 |
|
|
if (karch == 0) |
265 |
|
|
karch = arch; |
266 |
|
|
|
267 |
|
|
if (cluster == 0) |
268 |
|
|
cluster = hostdomain; |
269 |
|
|
|
270 |
|
|
if (afs_timeo <= 0) |
271 |
|
|
afs_timeo = AFS_TIMEO; |
272 |
|
|
if (afs_retrans <= 0) |
273 |
|
|
afs_retrans = AFS_RETRANS; |
274 |
|
|
if (afs_retrans <= 0) |
275 |
|
|
afs_retrans = 3; /* XXX */ |
276 |
|
|
return; |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
show_usage: |
280 |
|
|
fprintf(stderr, |
281 |
|
|
"usage: %s [-nprv] [-a mount_point] [-C cluster] " |
282 |
|
|
"[-c duration] [-D option]\n" |
283 |
|
|
"\t[-d domain] [-k kernel-arch] [-l logfile] " |
284 |
|
|
"[-t interval.interval]\n" |
285 |
|
|
"\t[-w interval]", __progname); |
286 |
|
|
|
287 |
|
|
#if defined(HAS_HOST) && defined(HOST_EXEC) |
288 |
|
|
fputs(" [-h host_helper]\n", stderr); |
289 |
|
|
#endif /* defined(HAS_HOST) && defined(HOST_EXEC) */ |
290 |
|
|
|
291 |
|
|
fputs(" [-y YP-domain]\n", stderr); |
292 |
|
|
|
293 |
|
|
show_opts('x', xlog_opt); |
294 |
|
|
#ifdef DEBUG |
295 |
|
|
show_opts('D', dbg_opt); |
296 |
|
|
#endif /* DEBUG */ |
297 |
|
|
fprintf(stderr, "\t[directory mapname [-map-options]] ...\n"); |
298 |
|
|
exit(1); |
299 |
|
|
} |