#include "am.h"
#include <syslog.h>
#include <sys/stat.h>
#include <unistd.h>
#if defined(DEBUG) && defined(PARANOID)
char **gargv;
#endif
int restart_existing_mounts;
int print_pid;
int normalize_hosts;
char *karch;
char *cluster;
char *domain;
int afs_timeo = -1;
int afs_retrans = -1;
int am_timeo = AM_TTL;
int am_timeo_w = AM_TTL_W;
#ifdef DEBUG
static struct opt_tab dbg_opt[] = {
{ "all", D_ALL },
{ "amq", D_AMQ },
{ "daemon", D_DAEMON },
{ "full", D_FULL },
{ "mem", D_MEM },
{ "mtab", D_MTAB },
{ "str", D_STR },
{ "test", D_TEST },
{ "trace", D_TRACE },
{ 0, 0 }
};
int debug_flags = D_AMQ
|D_DAEMON
;
int
debug_option(char *opt)
{
return cmdoption(opt, dbg_opt, &debug_flags);
}
#endif
void
get_args(int c, char *v[])
{
int opt_ch;
int usage = 0;
char *logfile = "syslog";
char *sub_domain = 0;
while ((opt_ch = getopt(c, v, "mnprva:c:d:h:k:l:t:w:x:y:C:D:")) != -1)
switch (opt_ch) {
case 'a':
if (*optarg != '/') {
fprintf(stderr, "%s: -a option must begin with a '/'\n",
__progname);
exit(1);
}
auto_dir = optarg;
break;
case 'c':
am_timeo = atoi(optarg);
if (am_timeo <= 0)
am_timeo = AM_TTL;
break;
case 'd':
sub_domain = optarg;
break;
case 'h':
#if defined(HAS_HOST) && defined(HOST_EXEC)
host_helper = optarg;
#else
plog(XLOG_USER, "-h: option ignored. HOST_EXEC is not enabled.");
break;
#endif
case 'k':
karch = optarg;
break;
case 'l':
logfile = optarg;
break;
case 'm':
plog(XLOG_USER, "The -m option is no longer supported.");
plog(XLOG_USER, "... Use `ypcat -k am.master` on the command line instead");
break;
case 'n':
normalize_hosts = 1;
break;
case 'p':
print_pid = 1;
break;
case 'r':
restart_existing_mounts = 1;
break;
case 't':
{ char *dot = strchr(optarg, '.');
if (dot) *dot = '\0';
if (*optarg) {
afs_timeo = atoi(optarg);
}
if (dot) {
afs_retrans = atoi(dot+1);
*dot = '.';
}
}
break;
case 'v':
fputs("Map support for: ", stderr);
mapc_showtypes(stderr);
fputs(".\nFS: ", stderr);
ops_showfstypes(stderr);
fputs(".\n", stderr);
fprintf(stderr, "Primary network is %s.\n", wire);
exit(0);
break;
case 'w':
am_timeo_w = atoi(optarg);
if (am_timeo_w <= 0)
am_timeo_w = AM_TTL_W;
break;
case 'x':
usage += switch_option(optarg);
break;
case 'y':
domain = optarg;
break;
case 'C':
cluster = optarg;
break;
case 'D':
#ifdef DEBUG
usage += debug_option(optarg);
#else
fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n",
__progname);
#endif
break;
default:
usage = 1;
break;
}
if (xlog_level_init == ~0) {
(void) switch_option("");
#ifdef DEBUG
usage += switch_option("debug");
#endif
} else {
#ifdef DEBUG
usage += switch_option("debug");
#endif
}
if (usage)
goto show_usage;
while (optind <= c-2) {
char *dir = v[optind++];
char *map = v[optind++];
char *opts = "";
if (v[optind] && *v[optind] == '-')
opts = &v[optind++][1];
root_newmap(dir, opts, map);
}
if (optind == c) {
if (sub_domain)
hostdomain = sub_domain;
if (*hostdomain == '.')
hostdomain++;
strlcat(hostd, ".", 2 * (HOST_NAME_MAX+1));
strlcat(hostd, hostdomain, 2 * (HOST_NAME_MAX+1));
#ifdef DEBUG
{ if (debug_flags & D_MTAB) {
dlog("-D mtab option ignored");
} }
#endif
if (switch_to_logfile(logfile) != 0)
plog(XLOG_USER, "Cannot switch logfile");
if (karch == 0)
karch = arch;
if (cluster == 0)
cluster = hostdomain;
if (afs_timeo <= 0)
afs_timeo = AFS_TIMEO;
if (afs_retrans <= 0)
afs_retrans = AFS_RETRANS;
if (afs_retrans <= 0)
afs_retrans = 3;
return;
}
show_usage:
fprintf(stderr,
"usage: %s [-nprv] [-a mount_point] [-C cluster] "
"[-c duration] [-D option]\n"
"\t[-d domain] [-k kernel-arch] [-l logfile] "
"[-t interval.interval]\n"
"\t[-w interval]", __progname);
#if defined(HAS_HOST) && defined(HOST_EXEC)
fputs(" [-h host_helper]\n", stderr);
#endif
fputs(" [-y YP-domain]\n", stderr);
show_opts('x', xlog_opt);
#ifdef DEBUG
show_opts('D', dbg_opt);
#endif
fprintf(stderr, "\t[directory mapname [-map-options]] ...\n");
exit(1);
}