* libamu/xutil.c: make xlog_level static, and initialize it to
authorErez Zadok <ezk@cs.sunysb.edu>
Mon, 15 Aug 2005 01:17:42 +0000 (01:17 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Mon, 15 Aug 2005 01:17:42 +0000 (01:17 +0000)
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.

13 files changed:
ChangeLog
NEWS
amd/amd.8
amd/conf.c
amd/get_args.c
amd/mapc.c
amq/amq.8
doc/am-utils.texi
hlfsd/hlfsd.c
include/am_utils.h
libamu/xutil.c
scripts/amd.conf.5
wire-test/wire-test.c

index 03b09706db35058e1d6fc9af98858ce2a3be8b57..c5f5a131c2042721c3b9800a3a0744d26e176eea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,37 @@
 2005-08-14  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * 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 98f8b7be1cbd411d84e45897e823d97b5a574719..19485110a2cce8e987614807845ed6562fff3d5d 100644 (file)
--- 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
index 765a8bb8c42db4fe1d4ad490436a7ee922bdfa65..dd5f6b96e841be01504ce8c69e17496089848409 100644 (file)
--- 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"
index 514375e06fceee005789046c32932db932efc853..4b52aa91634e25f2b2bcd535713da3b537867083 100644 (file)
@@ -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;
index c4747df932ffeaa4321a7f08e68bed169cb4a689..63af73c029d522ab8ab92bb55d94a8c24ad53631 100644 (file)
@@ -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 */
index 00b6d313f3bcf0c5b808b8c4ed372020154279b3..578a2926031649914f173247dd030748e042ecd2 100644 (file)
@@ -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);
 
index e296e0f464e11675f4917c1c0ffa0ea687f5e1b1..84fee9a1c812795de7487031beb18e1d24abd12a 100644 (file)
--- 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"
index 07978ae9602334a2406b9e109e78304200f7800d..b2428b356d3657018f3a5f4788307924a15d0545 100644 (file)
@@ -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
index cff4e5423d96ebcf91de5f4c7053afdccdde460f..8a164ba2966e6a3acb88031d4a9298092047ae28 100644 (file)
@@ -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
index f11e08871e9dab0b28b4fdf32d139fe9e50f42a7..a5bab285b4073615557b895a4889998f3a658095 100644 (file)
 #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);
index bd87a6b81580742754e95bab240f2c9f3473e29e..4cd39ddc6e185bb96a26a7a088069607c717b74d 100644 (file)
@@ -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.
index feca1ee58efa5d7c0514c252ed2183310170d30a..8b1bfc6a1c766c359534fb16012dc1008caaa24f 100644 (file)
@@ -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
index 0158f5967f987ed5a785d1459c21d2be7797ff60..4f5490e5fc9e301d637327ce54b9bd39f92de4cc 100644 (file)
@@ -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) {