From: Erez Zadok Date: Mon, 15 Aug 2005 01:17:42 +0000 (+0000) Subject: * libamu/xutil.c: make xlog_level static, and initialize it to X-Git-Tag: before-clocktime-fixes~29 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=17d304ae691f66146ffce4380a61b3b75e70bf3d;p=am-utils-6.0.git * libamu/xutil.c: make xlog_level static, and initialize it to XLOG_DEFAULT. (cmdoption): take unsigned int as flags argument, and print any errors as XLOG_ERROR (which cannot be turned off). (switch_option): remove old code which disallowed you from turning off flags that were set when Amd started up. Now, you can turn any log option on/off at start time or later on (via amq -x), other than the two mandatory options (fatal+error). * include/am_utils.h (XLOG_*): remove unused XLOG_DEFSTR. Define XLOG_MASK to mask out unused flag bits. Define XLOG_DEFAULT to be what it was before (fatal + error + user + warning + info), but use the new mask. Remove extern's for xlog_level and xlog_level_init. Change extern for cmdoption() to take an unsigned flags argument. * doc/am-utils.texi, amq/amq.8, scripts/amd.conf.5, amd/amd.8: document mandatory log options (fatal+error) which cannot be turned off and are always on by default. They must be on so that Amd can report crucial errors, including those related to setting flags on/off. * hlfsd/hlfsd.c (main): remove hack to initialize log_options. * wire-test/wire-test.c: remove reference to unused xlog_level. * amd/mapc.c (mapc_create): 'alloc' flags variable should be unsigned. * amd/get_args.c (get_args): no need for hack using xlog_level_init. --- diff --git a/ChangeLog b/ChangeLog index 03b0970..c5f5a13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,37 @@ 2005-08-14 Erez Zadok + * libamu/xutil.c: make xlog_level static, and initialize it to + XLOG_DEFAULT. + (cmdoption): take unsigned int as flags argument, and print any + errors as XLOG_ERROR (which cannot be turned off). + (switch_option): remove old code which disallowed you from turning + off flags that were set when Amd started up. Now, you can turn + any log option on/off at start time or later on (via amq -x), + other than the two mandatory options (fatal+error). + + * include/am_utils.h (XLOG_*): remove unused XLOG_DEFSTR. Define + XLOG_MASK to mask out unused flag bits. Define XLOG_DEFAULT to be + what it was before (fatal + error + user + warning + info), but + use the new mask. Remove extern's for xlog_level and + xlog_level_init. Change extern for cmdoption() to take an + unsigned flags argument. + + * doc/am-utils.texi, amq/amq.8, scripts/amd.conf.5, amd/amd.8: + document mandatory log options + (fatal+error) which cannot be turned off and are always on by + default. They must be on so that Amd can report crucial errors, + including those related to setting flags on/off. + + * hlfsd/hlfsd.c (main): remove hack to initialize log_options. + + * wire-test/wire-test.c: remove reference to unused xlog_level. + + * amd/mapc.c (mapc_create): 'alloc' flags variable should be + unsigned. + + * amd/get_args.c (get_args): no need for hack using + xlog_level_init. + * amd/Makefile.am: separate sources common to amd and sun2amd into a special, locally-built only, static library called libaminfo.a. diff --git a/NEWS b/NEWS index 98f8b7b..1948511 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,17 @@ XXX: Dan, document sun_map_syntax flag in more detail in am-utils.texi and (more briefly) in amd.conf.5. And in this NEWS file, also briefly. +Changed slightly how Amd behaves when you try to change log_options after +Amd started (options can be turned on/off via "amq -x ARG"). It used to be +that Amd won't let you turn off options which were on when Amd started. +That limited users' ability to reduce Amd's logging levels to a minimum. +Now, Amd will allow you to turn on/off any option, other than the two +options "fatal" and "error." Both are on by default and considered +mandatory. These two don't produce a lot of log messages, so your logs will +remain small, but they are important to keep on, so Amd can report serious +problems (including errors relating to incorrectly setting other log +options). + *** Notes specific to am-utils version 6.1.1 New amd.conf global parameter: forced_unmounts (default to "no"). If set to diff --git a/amd/amd.8 b/amd/amd.8 index 765a8bb..dd5f6b9 100644 --- a/amd/amd.8 +++ b/amd/amd.8 @@ -237,6 +237,7 @@ The default is 2 minutes. .BI \-x " options" Specify run-time logging options. The options are a comma separated list chosen from: fatal, error, user, warn, info, map, stats, all. +Note that "fatal" and "error" are mandatory and cannot be turned off. .TP .BI \-y " domain" diff --git a/amd/conf.c b/amd/conf.c index 514375e..4b52aa9 100644 --- a/amd/conf.c +++ b/amd/conf.c @@ -1400,7 +1400,7 @@ find_cf_map(const char *name) return NULL; while (tmp_map) { - if (STREQ(tmp_map->cfm_dir,name)) { + if (STREQ(tmp_map->cfm_dir, name)) { return tmp_map; } tmp_map = tmp_map->cfm_next; diff --git a/amd/get_args.c b/amd/get_args.c index c4747df..63af73c 100644 --- a/amd/get_args.c +++ b/amd/get_args.c @@ -337,10 +337,6 @@ get_args(int argc, char *argv[]) exit(1); } - /* make sure there are some default options defined */ - if (xlog_level_init == ~0) { - switch_option(""); - } #ifdef DEBUG usage += switch_option("debug"); #endif /* DEBUG */ diff --git a/amd/mapc.c b/amd/mapc.c index 00b6d31..578a292 100644 --- a/amd/mapc.c +++ b/amd/mapc.c @@ -600,7 +600,7 @@ mapc_create(char *map, char *opt, const char *type) mnt_map *m = ALLOC(struct mnt_map); map_type *mt; time_t modify; - int alloc = 0; + u_int alloc = 0; cmdoption(opt, mapc_opt, &alloc); diff --git a/amq/amq.8 b/amq/amq.8 index e296e0f..84fee9a 100644 --- a/amq/amq.8 +++ b/amq/amq.8 @@ -151,7 +151,8 @@ is running. .BI \-x " log_options" Ask the automounter to use the logging options specified in .I log_options -from now on. +from now on. Note that the "fatal" and "error" options cannot be turned +off. .TP .BI \-D " log_options" diff --git a/doc/am-utils.texi b/doc/am-utils.texi index 07978ae..b2428b3 100644 --- a/doc/am-utils.texi +++ b/doc/am-utils.texi @@ -2812,9 +2812,9 @@ a comma separated list selected from the following options: @table @code @item fatal -Fatal errors +Fatal errors (cannot be turned off) @item error -Non-fatal errors +Non-fatal errors (cannot be turned off) @item user Non-fatal user errors @item warn @@ -4653,7 +4653,7 @@ is generally a bad idea to use those reserved for other services such as @subsection @t{log_options} Parameter @cindex log_options Parameter -(type=string, default no logging options). Same as the @code{-x} +(type=string, default fatal+error+user+warning+info). Same as the @code{-x} option to @i{Amd}. Specify any logging options for @i{Amd}. Options are comma delimited, and can be preceded by the string @samp{no} to negate their meaning. The @samp{debug} logging option is only available @@ -4667,9 +4667,9 @@ all messages @item debug debug messages @item error -non-fatal system errors +non-fatal system errors (cannot be turned off) @item fatal -fatal errors +fatal errors (cannot be turned off) @item info information @item map @@ -5605,11 +5605,10 @@ as a whole, rather than any particular filesystem. The @code{-x} and @code{-D} options have exactly the same effect as @i{Amd}'s corresponding command line options. -When @i{Amd} receives a @code{-x} flag it limits the log options being -modified to those which were not enabled at startup. This prevents a -user turning @emph{off} any logging option which was specified at -startup, though any which have been turned on since then can still be -turned off. The @code{-D} option has a similar behavior. +When @i{Amd} receives the @code{-x} flag, it disallows turning off the +@samp{fatal} or @samp{error} flags. Both are on by default. They are +mandatory so that @i{Amd} could report important errors, including +errors relating to turning flags on/off. @c ################################################################ @node FSinfo, Hlfsd, Run-time Administration, Top diff --git a/hlfsd/hlfsd.c b/hlfsd/hlfsd.c index cff4e54..8a164ba 100644 --- a/hlfsd/hlfsd.c +++ b/hlfsd/hlfsd.c @@ -249,9 +249,6 @@ main(int argc, char *argv[]) opterrs++; } - /* set some default debugging options */ - if (xlog_level_init == ~0) - switch_option(""); /* need my pid before any dlog/plog */ am_set_mypid(); #ifdef DEBUG diff --git a/include/am_utils.h b/include/am_utils.h index f11e088..a5bab28 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -109,8 +109,13 @@ #define XLOG_DEBUG 0x0020 #define XLOG_MAP 0x0040 #define XLOG_STATS 0x0080 -#define XLOG_DEFSTR "all,nomap,nostats" /* Default log options */ +#define XLOG_MASK 0x00ff /* mask for all flags */ +#define XLOG_MANDATORY (XLOG_FATAL|XLOG_ERROR) /* cannot turn these off */ #define XLOG_ALL (XLOG_FATAL|XLOG_ERROR|XLOG_USER|XLOG_WARNING|XLOG_INFO|XLOG_MAP|XLOG_STATS) +/* default: fatal + error + user + warning + info */ +#define XLOG_DEFAULT (XLOG_MASK & (XLOG_ALL & ~XLOG_MAP & ~XLOG_STATS)) + + /* default: no logging options */ #define clocktime() (clock_valid ? clock_valid : time(&clock_valid)) @@ -262,8 +267,6 @@ extern pid_t am_mypid; extern int foreground; /* Foreground process */ extern int orig_umask; /* umask() on startup */ -extern int xlog_level; /* Logging level */ -extern int xlog_level_init; extern serv_state amd_state; /* Should we go now */ extern struct in_addr myipaddr; /* (An) IP address of this host */ extern struct opt_tab xlog_opt[]; @@ -288,7 +291,7 @@ extern char *strip_selectors(char *, char *); extern char *strnsave(const char *, int); extern int amu_close(int fd); extern int bind_resv_port(int, u_short *); -extern int cmdoption(char *, struct opt_tab *, int *); +extern int cmdoption(char *, struct opt_tab *, u_int *); extern int compute_automounter_mount_flags(mntent_t *); extern int compute_mount_flags(mntent_t *); extern int get_amd_program_number(void); diff --git a/libamu/xutil.c b/libamu/xutil.c index bd87a6b..4cd39dd 100644 --- a/libamu/xutil.c +++ b/libamu/xutil.c @@ -64,8 +64,7 @@ int debug_flags = 0; #ifdef HAVE_SYSLOG int syslogging; #endif /* HAVE_SYSLOG */ -int xlog_level = XLOG_ALL & ~XLOG_MAP & ~XLOG_STATS; -int xlog_level_init = ~0; +static u_int xlog_level = XLOG_DEFAULT; static int amd_program_number = AMQ_PROGRAM; time_t clock_valid = 0; @@ -568,7 +567,7 @@ show_opts(int ch, struct opt_tab *opts) int -cmdoption(char *s, struct opt_tab *optb, int *flags) +cmdoption(char *s, struct opt_tab *optb, u_int *flags) { char *p = s; int errs = 0; @@ -619,7 +618,7 @@ cmdoption(char *s, struct opt_tab *optb, int *flags) * This will log to stderr when parsing the command line * since any -l option will not yet have taken effect. */ - plog(XLOG_USER, "option \"%s\" not recognized", s); + plog(XLOG_ERROR, "option \"%s\" not recognized", s); errs++; } @@ -640,25 +639,26 @@ cmdoption(char *s, struct opt_tab *optb, int *flags) int switch_option(char *opt) { - int xl = xlog_level; + u_int xl = xlog_level; int rc = cmdoption(opt, xlog_opt, &xl); - if (rc) { - rc = EINVAL; - } else { - /* - * Keep track of initial log level, and - * don't allow options to be turned off. - */ - if (xlog_level_init == ~0) - xlog_level_init = xl; - else - xl |= xlog_level_init; - xlog_level = xl; + if (rc) /* if got any error, don't update flags */ + return EINVAL; + + /* + * Don't allow "mandatory" flags to be turned off, because + * we must always be able to report on flag re/setting errors. + */ + if ((xl & XLOG_MANDATORY) != XLOG_MANDATORY) { + plog(XLOG_ERROR, "cannot turn of mandatory logging options"); + xl |= XLOG_MANDATORY; } + if (xlog_level != xl) + xlog_level = xl; /* set new flags */ return rc; } + #ifdef LOG_DAEMON /* * get syslog facility to use. diff --git a/scripts/amd.conf.5 b/scripts/amd.conf.5 index feca1ee..8b1bfc6 100644 --- a/scripts/amd.conf.5 +++ b/scripts/amd.conf.5 @@ -409,7 +409,7 @@ then Amd will log messages via using the LOG_LOCAL7 facility (if it exists on the system). .TP -.BR log_options " (string, default no logging options)" +.BR log_options " (string, default=fatal+error+user+warning+info)" Same as the .B \-x option to Amd. Specify any logging options for Amd. Options are comma @@ -424,8 +424,8 @@ Possible values are: .nf \fBall\fR all messages \fBdebug\fR debug messages -\fBerror\fR non-fatal system errors -\fBfatal\fR fatal errors +\fBerror\fR non-fatal system errors (cannot be turned off) +\fBfatal\fR fatal errors (cannot be turned off) \fBinfo\fR information \fBmap\fR map errors \fBstats\fR additional statistical information diff --git a/wire-test/wire-test.c b/wire-test/wire-test.c index 0158f59..4f5490e 100644 --- a/wire-test/wire-test.c +++ b/wire-test/wire-test.c @@ -101,7 +101,6 @@ main(int argc, char **argv) memmove((voidp) &ip->sin_addr, (voidp) hp->h_addr, sizeof(ip->sin_addr)); ip->sin_port = htons(NFS_PORT); - xlog_level = 0; /* turn off debugging */ fprintf(stderr, "NFS Version and protocol tests to host \"%s\"...\n", testhost); proto = "udp"; for (nv=2; nv<=3; ++nv) {