* libamu/xutil.c: debug_flags should be unsigned.
authorErez Zadok <ezk@cs.sunysb.edu>
Mon, 15 Aug 2005 08:05:29 +0000 (08:05 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Mon, 15 Aug 2005 08:05:29 +0000 (08:05 +0000)
(dbg_opt): fix comments for updated debug_flags, add "defaults".
(debug_option): Don't allow "immutable" (D_IMMUTABLE) flags to be
changed, because they could mess Amd's state and only make sense
to be set once when Amd starts.  Currently these immutable flags
are "daemon," "fork," "amq," and "mtab."  If Amd not compiled with
debugging, set default "control" options (daemon,fork,amq).
(unregister_amq): proper use of D_AMQ.

* include/am_utils.h: define new D_BASIC, D_CONTROL, D_DEFAULT,
D_IMMUTABLE, and D_MASK.  Updated definitions of D_ALL and D_TEST.
debug_flags extern should be unsigned.

* scripts/amd.conf-sample (debug_options): mention new "defaults"
option.

* scripts/amd.conf.5,doc/am-utils.texi: document new debug option
"defaults" and properly explain the corrected meanings of
"daemon," "fork," "amq," and their "no" inversions.  Better
explain "all" and "test" too.  Correct default debug_mtab file to
/tmp/mtab.

* hlfsd/stubs.c (nfsproc_readlink_2_svc): proper use of D_FORK.

* hlfsd/homedir.c (homedir): proper use of D_FORK.

* hlfsd/hlfsd.c (main, hlfsd_init, cleanup): proper use of
D_DAEMON.

* amd/nfs_start.c (mount_automounter): proper use of D_AMQ.

* amd/amd.h (DEBUG_MNTTAB_FILE): change default to /tmp/mtab,
which is more common on more systems (instead of /tmp/mnttab).

* amd/amd.c (main): properly use D_DAEMON.

13 files changed:
ChangeLog
NEWS
amd/amd.c
amd/amd.h
amd/nfs_start.c
doc/am-utils.texi
hlfsd/hlfsd.c
hlfsd/homedir.c
hlfsd/stubs.c
include/am_utils.h
libamu/xutil.c
scripts/amd.conf-sample
scripts/amd.conf.5

index 4065f1d0ea1042a0c9fd441e7698698a075be06c..f9137ae7a6d779dd13797e4cb8c7fd28e8d1fb79 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2005-08-15  Erez Zadok  <ezk@cs.sunysb.edu>
+
+       * libamu/xutil.c: debug_flags should be unsigned.
+       (dbg_opt): fix comments for updated debug_flags, add "defaults".
+       (debug_option): Don't allow "immutable" (D_IMMUTABLE) flags to be
+       changed, because they could mess Amd's state and only make sense
+       to be set once when Amd starts.  Currently these immutable flags
+       are "daemon," "fork," "amq," and "mtab."  If Amd not compiled with
+       debugging, set default "control" options (daemon,fork,amq).
+       (unregister_amq): proper use of D_AMQ.
+
+       * include/am_utils.h: define new D_BASIC, D_CONTROL, D_DEFAULT,
+       D_IMMUTABLE, and D_MASK.  Updated definitions of D_ALL and D_TEST.
+       debug_flags extern should be unsigned.
+
+       * scripts/amd.conf-sample (debug_options): mention new "defaults"
+       option.
+
+       * scripts/amd.conf.5,doc/am-utils.texi: document new debug option
+       "defaults" and properly explain the corrected meanings of
+       "daemon," "fork," "amq," and their "no" inversions.  Better
+       explain "all" and "test" too.  Correct default debug_mtab file to
+       /tmp/mtab.
+
+       * hlfsd/stubs.c (nfsproc_readlink_2_svc): proper use of D_FORK.
+
+       * hlfsd/homedir.c (homedir): proper use of D_FORK.
+
+       * hlfsd/hlfsd.c (main, hlfsd_init, cleanup): proper use of
+       D_DAEMON.
+
+       * amd/nfs_start.c (mount_automounter): proper use of D_AMQ.
+
+       * amd/amd.h (DEBUG_MNTTAB_FILE): change default to /tmp/mtab,
+       which is more common on more systems (instead of /tmp/mnttab).
+
+       * amd/amd.c (main): properly use D_DAEMON.
+
 2005-08-14  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * libamu/xutil.c (xlog_opt): define new pseudo log_option named
diff --git a/NEWS b/NEWS
index a02b2d9027527373369b0c95417116cdac7c625d..5ef533b26ba9c5da1d5ff1c9bc52b97e29d7326e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,18 @@
 *** Notes specific to am-utils version 6.2a1
 
+XXX: Ezk: does it compile and run w/o --with-debug, with all of the new
+"daemonize" stuff?
+
 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.
 
+Amd now understands a new log_option called "defaults" which is synonymous
+with "fatal,error,user,warning,info" (and is also what logging happens by
+default).
+
+Amd now understands a new debug_option called "defaults" which is synonymous
+with "all,nohrtime,nomtab,noxdrtrace".
+
 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.
@@ -14,9 +24,38 @@ remain small, but they are important to keep on, so Amd can report serious
 problems (including errors relating to incorrectly setting other log
 options).
 
-Amd now understands a new log_option called "defaults" which is synonymous
-with "fatal,error,user,warning,info" (and is also what logging happens by
-default).
+Changed the misleading inverted logic of certain debug_options:
+
+1. "xdrtrace" is included in "all" because "all" (as the name implies),
+   *all* options, not just a subset.  If you want the old behavior of "all"
+   then use "defaults" (all only adds "xdrtrace" which can be chatty only
+   some systems).
+
+2. Certain debug options are hereby declared immutable: they may not be
+   changed by "amq -D" after Amd starts, because it doesn't make much sense
+   to change them after Amd starts, and it could really mess up Amd.  These
+   immutable flags are currently "daemon," "fork," "amq," and "mtab."
+
+3. the debug option "daemon" *will* cause Amd to daemonize.  Before, it was
+   causing Amd NOT to daemonize.  This was greatly confusing, especially
+   since the code, documentation, and comments often conflicted with each
+   other.  If you don't want Amd to daemonize, which is useful for debugging
+   it, then use the debug option "nodaemon" -- it makes a lot more sense.
+
+4. Similarly, the "fork" option *will* cause Hlfsd to fork.  Use "nofork" if
+   you don't want Hlfsd to fork.  This option is only applicable to Hlfsd.
+
+5. Similarly, the "amq" option, which is now on by default, will cause Amd
+   to register itself with the RPC portmapper (for Amq), as is done
+   normally.  If you don't want Amd to register with the portmapper, use
+   "noamq" -- this naming convention makes more sense.  This was also
+   confusingly documented and coded in places.
+
+   Note: unfortunately, these changes to the "daemon," "fork," and "amq"
+   debug options may be incompatible with people's previous use of Amd.
+   Sorry, but we have to fix those old problems sooner or later.  However,
+   if you never set any debug_options, or you used to "all," then you won't
+   be affected by the change in meaning of these three flags.
 
 *** Notes specific to am-utils version 6.1.1
 
@@ -224,7 +263,7 @@ version (10.3.x) than uname(3) reports.
   Useful with firewalls and NAT'ed environments.
 
 - new amd.conf option "debug_mtab_file".  Allows user to define the mtab
-  file during debug-mtab mode.  The default path is "/tmp/mnttab".
+  file during debug-mtab mode.  The default path is "/tmp/mtab".
 
 - new function selector xhost(ARG) which will match ARG against the current
   host name.  This works even if ARG is a CNAME (unlike the host==ARG
index 0c2bdf9f12ab86deec9d184366813371c89ddff7..32314445f71eb13330e130c39a40255e0bbce080 100644 (file)
--- a/amd/amd.c
+++ b/amd/amd.c
@@ -542,7 +542,7 @@ main(int argc, char *argv[])
   }
 #endif /* HAVE_MAP_NIS */
 
-  if (!amuDebug(D_DAEMON))
+  if (amuDebug(D_DAEMON))
     ppid = daemon_mode();
 
   /*
index 790321f57e45d818ac81d5573bff58cf2c2110b0..f115fa0d2b986f60ecc508be01c9ee4fade51e40 100644 (file)
--- a/amd/amd.h
+++ b/amd/amd.h
@@ -54,7 +54,7 @@
  * that support mtab on file.
  */
 #ifdef MOUNT_TABLE_ON_FILE
-# define DEBUG_MNTTAB_FILE             "/tmp/mnttab"
+# define DEBUG_MNTTAB_FILE             "/tmp/mtab"
 #endif /* MOUNT_TABLE_ON_FILE */
 
 /* Max line length that info services can handle */
index 193bb7fc734905de2bf271e4e26668176f17c4b1..04b458fadb740d668f051cdd45f9aba421c6b6b8 100644 (file)
@@ -374,8 +374,8 @@ mount_automounter(int ppid)
   }
   sprintf(pid_fsname, "%s:(pid%ld,port%u)", am_get_hostname(), (long) am_mypid, nfs_port);
 
-  /* security: if user sets -D amq, don't even create listening socket */
-  if (!amuDebug(D_AMQ)) {
+  /* security: if user sets -D noamq, don't even create listening socket */
+  if (amuDebug(D_AMQ)) {
     ret = create_amq_service(&udp_soAMQ,
                             &udp_amqp,
                             &udp_amqncp,
@@ -418,11 +418,11 @@ mount_automounter(int ppid)
     return 0;
   }
 
-  if (!amuDebug(D_AMQ)) {
+  if (amuDebug(D_AMQ)) {
     /*
      * Complete registration of amq (first TCP service then UDP)
      */
-    unregister_amq();
+    unregister_amq();   /* unregister leftover Amd, if any, just in case */
 
     ret = amu_svc_register(tcp_amqp, get_amd_program_number(), AMQ_VERSION,
                           amq_program_1, IPPROTO_TCP, tcp_amqncp);
index 73e727703ec8fa06d0bbcab4335967090959c17b..2eb32aa0ad10ae945787a97303c0907eca145424 100644 (file)
@@ -2948,13 +2948,17 @@ can be prefixed with @samp{no} to turn it off.
 
 @table @code
 @item all
-all ``reasonable'' options (currently trace|str|full|mem|info|readdir)
+all options (excluding hrtime and mtab)
+@item defaults
+``sensible'' default options (all--excluding hrtime, mtab, and xdrtrace)
+@item test
+full debug options plus mtab,nodaemon,nofork,noamq
 @item amq
-do not register for amq
+register @i{Amd} with the RPC portmapper, for @i{Amq}
 @item daemon
-do not enter daemon mode
+enter daemon mode
 @item fork
-do not fork child worker (hlfsd only)
+fork child worker (hlfsd only)
 @item full
 program trace
 @item hrtime
@@ -2965,16 +2969,14 @@ print high resolution time stamps (only if @b{syslog}(3) is not used)
 info service specific debugging (hesiod, nis, etc.)  In the case of
 hesiod maps, turns on the hesiod RES_DEBUG internal debugging option.
 @item mem
-trace memory allocations. Needs to be explicitly enabled at compile
+trace memory allocations.  Needs to be explicitly enabled at compile
 time with --enable-debug=mem.
 @item mtab
-use local @file{./mtab} file
+use local mount-table file (defaults to @file{/tmp/mtab}, @pxref{debug_mtab_file Parameter})
 @item readdir
 show readdir progress
 @item str
 debug string munging
-@item test
-full debug but no daemon
 @item trace
 trace RPC protocol and NFS mount arguments
 @item xdrtrace
@@ -4410,14 +4412,14 @@ remain in the cache.
 (type=string, default no cluster).  Same as the @code{-C} option to
 @i{Amd}.  Specifies the alternate HP-UX cluster to use.
 
-@c ---------------------------------------------------------------- 
-@node debug_mtab_file Parameter, debug_options Parameter, cluster Parameter, Global Parameters 
-@comment  node-name,  next,  previous,  up 
-@subsection @t{debug_mtab_file} Parameter 
-@cindex debug_mtab_file Parameter 
+@c ----------------------------------------------------------------
+@node debug_mtab_file Parameter, debug_options Parameter, cluster Parameter, Global Parameters
+@comment  node-name,  next,  previous,  up
+@subsection @t{debug_mtab_file} Parameter
+@cindex debug_mtab_file Parameter
 
-(type=string, default="/tmp/mnttab").  Path to mtab file that is used 
-by @i{Amd} to store a list of mounted file systems during debug-mtab mode.  
+(type=string, default="/tmp/mtab").  Path to mtab file that is used
+by @i{Amd} to store a list of mounted file systems during debug-mtab mode.
 This option only applies to systems that store mtab information on disk.
 
 @c ----------------------------------------------------------------
@@ -5113,7 +5115,7 @@ restart_mounts =         yes
 auto_dir =               /n
 log_file =               /var/log/amd
 log_options =            all
-#debug_options =         all
+#debug_options =         defaults
 plock =                  no
 selectors_in_defaults =  yes
 # config.guess picks up "sunos5" and I don't want to edit my maps yet
index 8a164ba2966e6a3acb88031d4a9298092047ae28..eb510a28695ec4e88cbcd7984189258ae8e91067 100644 (file)
@@ -438,10 +438,10 @@ main(int argc, char *argv[])
 #endif /* not HAVE_SIGACTION */
 
   /*
-   * In the parent, if -D daemon, we don't need to
+   * In the parent, if -D nodaemon, we don't need to
    * set this signal handler.
    */
-  if (!amuDebug(D_DAEMON)) {
+  if (amuDebug(D_DAEMON)) {
     s = -99;
     while (stoplight != SIGUSR2) {
       plog(XLOG_INFO, "parent waits for child to setup (stoplight=%d)", stoplight);
@@ -615,10 +615,10 @@ main(int argc, char *argv[])
 
   plog(XLOG_INFO, "hlfsd ready to serve");
   /*
-   * If asked not to fork a daemon (-D daemon), then hlfsd_init()
+   * If asked not to fork a daemon (-D nodaemon), then hlfsd_init()
    * will not run svc_run.  We must start svc_run here.
    */
-  if (amuDebug(D_DAEMON)) {
+  if (!amuDebug(D_DAEMON)) {
     plog(XLOG_DEBUG, "starting no-daemon debugging svc_run");
     svc_run();
   }
@@ -645,9 +645,9 @@ hlfsd_init(void)
   hlfsd_init_filehandles();
 
   /*
-   * If not -D daemon then we must fork.
+   * If -D daemon then we must fork.
    */
-  if (!amuDebug(D_DAEMON))
+  if (amuDebug(D_DAEMON))
     child = fork();
 
   if (child < 0)
@@ -740,11 +740,11 @@ hlfsd_init(void)
   gettimeofday((struct timeval *) ((void *)&startup), (struct timezone *) NULL);
 
   /*
-   * If not -D daemon, then start serving here in the child,
-   * and the parent will exit.  But if -D daemon, then
+   * If -D daemon, then start serving here in the child,
+   * and the parent will exit.  But if -D nodaemon, then
    * skip this code and make sure svc_run is entered elsewhere.
    */
-  if (!amuDebug(D_DAEMON)) {
+  if (amuDebug(D_DAEMON)) {
     /*
      * Dissociate from the controlling terminal
      */
@@ -832,7 +832,7 @@ cleanup(int signum)
 
   clock_valid = 0;             /* invalidate logging clock */
 
-  if (!amuDebug(D_DAEMON)) {
+  if (amuDebug(D_DAEMON)) {
     if (getpid() != masterpid)
       return;
 
@@ -858,7 +858,7 @@ cleanup(int signum)
     break;
   }
 
-  if (!amuDebug(D_DAEMON)) {
+  if (amuDebug(D_DAEMON)) {
     plog(XLOG_INFO, "cleanup(): killing processes and terminating");
     kill(masterpid, SIGKILL);
     kill(serverpid, SIGKILL);
index 9a33e63ff946781c3f224ef1af340c387b6535b2..bef1d5a3d49a4c834dad88abd9d96274b517ab2d 100644 (file)
@@ -135,9 +135,10 @@ homedir(int userid, int groupid)
   }
 
   /*
-   * only run this forking code if did not ask for -D fork
+   * Only run this forking code if ask for -D fork (default).
+   * Disable forking using -D nofork.
    */
-  if (!amuDebug(D_FORK)) {
+  if (amuDebug(D_FORK)) {
     /* fork child to process request if none in progress */
     if (found->child && kill(found->child, 0))
       found->child = 0;
index 0f1894f72c8b5534a677a4dc43bf79c78ad73b90..28870a0117b7bf8ca6ffcf20482baf42f6bc7501 100644 (file)
@@ -375,14 +375,15 @@ nfsproc_readlink_2_svc(am_nfs_fh *argp, struct svc_req *rqstp)
     retval = 0;
 
   /*
-   * If asked for -D fork, then must return the value,
+   * If asked for -D nofork, then must return the value,
    * NOT exit, or else the main hlfsd server exits.
+   * If -D fork (default), then we do want to exit from the process.
    * Bug: where is that status information being collected?
    */
   if (amuDebug(D_FORK))
+    exit(retval);
+  else
     return &res;
-
-  exit(retval);
 }
 
 
index 6d06244e78d9e7ed147bdb9c9bafea443338ab13..badb9cd911b26f4369be4040e9bd816299f11d1e 100644 (file)
@@ -396,30 +396,32 @@ extern int unregister_autofs_service(char *autofs_conftype);
 
 #ifdef DEBUG
 
-# define       D_ALL           (~(D_MTAB|D_HRTIME|D_XDRTRACE|D_DAEMON|D_FORK|D_AMQ))
-# define       D_DAEMON        0x0001  /* Don't enter daemon mode */
+# define       D_DAEMON        0x0001  /* Enter daemon mode */
 # define       D_TRACE         0x0002  /* Do protocol trace */
 # define       D_FULL          0x0004  /* Do full trace */
 # define       D_MTAB          0x0008  /* Use local mtab */
-# define       D_AMQ           0x0010  /* Don't register amq program */
+# define       D_AMQ           0x0010  /* Register amq program */
 # define       D_STR           0x0020  /* Debug string munging */
 # ifdef DEBUG_MEM
 #  define      D_MEM           0x0040  /* Trace memory allocations */
 # else /* not DEBUG_MEM */
 #  define      D_MEM           0x0000  /* Dummy */
 # endif /* not DEBUG_MEM */
-# define       D_FORK          0x0080  /* Don't fork server */
-               /* info service specific debugging (hesiod, nis, etc) */
-# define       D_INFO          0x0100
+# define       D_FORK          0x0080  /* Fork server (hlfsd only) */
+# define       D_INFO          0x0100  /* info service specific debugging (hesiod, nis, etc) */
 # define       D_HRTIME        0x0200  /* Print high resolution time stamps */
 # define       D_XDRTRACE      0x0400  /* Trace xdr routines */
 # define       D_READDIR       0x0800  /* Show browsable_dir progress */
-
-/*
- * Test mode is test mode: don't daemonize, don't register amq, don't fork,
- * don't touch system mtab, etc.
- */
-# define       D_TEST  (~(D_MEM|D_STR|D_XDRTRACE))
+/* debug option compositions */
+# define       D_MASK          0x0fff  /* mask of known flags */
+# define       D_BASIC         (D_TRACE|D_FULL|D_STR|D_MEM|D_INFO|D_XDRTRACE|D_READDIR)
+# define       D_CONTROL       (D_DAEMON|D_AMQ|D_FORK)
+/* immutable flags: cannot be changed via "amq -D" */
+# define       D_IMMUTABLE     (D_MTAB  | D_CONTROL)
+# define       D_ALL           (D_BASIC | D_CONTROL)
+# define       D_DEFAULT       (D_MASK & D_ALL & ~D_XDRTRACE)
+/* test mode: nodaemon, noamq, nofork, (local) mtab */
+# define       D_TEST          (D_BASIC | D_MTAB)
 
 # define       amuDebug(x)     (debug_flags & (x))
 # define       dlog            if (amuDebug(D_FULL)) dplog
@@ -451,27 +453,40 @@ extern void dplog(const char *fmt, ...)
 
 #else /* not DEBUG */
 
+/* set dummy flags to zero */
+# define       D_DAEMON        0x0001  /* Enter daemon mode */
+# define       D_TRACE         0x0000  /* dummy: Do protocol trace */
+# define       D_FULL          0x0000  /* dummy: Do full trace */
+# define       D_MTAB          0x0000  /* dummy: Use local mtab */
+# define       D_AMQ           0x0010  /* Register amq program */
+# define       D_STR           0x0000  /* dummy: Debug string munging */
+# define       D_MEM           0x0000  /* dummy: Trace memory allocations */
+# define       D_FORK          0x0080  /* Fork server (hlfsd only) */
+# define       D_INFO          0x0000  /* dummy: info service debugging */
+# define       D_HRTIME        0x0000  /* dummy: hi-res time stamps */
+# define       D_XDRTRACE      0x0000  /* dummy: Trace xdr routines */
+# define       D_READDIR       0x0000  /* dummy: browsable_dir progress */
+# define       D_CONTROL       (D_DAEMON|D_AMQ|D_FORK)
+# define       amuDebug(x)     (debug_flags & (x))
 /*
  * If not debugging, then also reset the pointer.
  * It's safer -- and besides, free() should do that anyway.
  */
-#  define      XFREE(x) do { free((voidp)x); x = NULL;} while (0)
-
-#define                amuDebug(x)     (0)
+# define       XFREE(x) do { free((voidp)x); x = NULL;} while (0)
 
-#ifdef __GNUC__
-#define                dlog(fmt...)
-#else  /* not __GNUC__ */
+# ifdef __GNUC__
+#  define      dlog(fmt...)
+# else  /* not __GNUC__ */
 /* this define means that we CCP leaves code behind the (list,of,args)  */
-#define                dlog
-#endif /* not __GNUC__ */
+#  define      dlog
+# endif /* not __GNUC__ */
 
-#define                print_nfs_args(nap, nfs_version)
-#define                debug_option(x) (1)
+# define       print_nfs_args(nap, nfs_version)
+# define       debug_option(x) (1)
 
 #endif /* not DEBUG */
 
-extern int debug_flags;                /* Debug options */
+extern u_int debug_flags;      /* Debug options */
 extern struct opt_tab dbg_opt[];
 
 /**************************************************************************/
index f28d09e3c6329b96143ed849afe2efd6d0100dc3..68fa15374b37acb90c90e2f1a8bff69e816cbe29 100644 (file)
@@ -59,7 +59,11 @@ static char am_hostname[MAXHOSTNAMELEN] = "unknown"; /* Hostname */
 pid_t am_mypid = -1;           /* process ID */
 serv_state amd_state;          /* amd's state */
 int foreground = 1;            /* 1 == this is the top-level server */
-int debug_flags = 0;
+#ifdef DEBUG
+u_int debug_flags = 0;
+#else /* not DEBUG */
+u_int debug_flags = D_CONTROL; /* default when not compiled with debugging */
+#endif /* not DEBUG */
 
 #ifdef HAVE_SYSLOG
 int syslogging;
@@ -90,20 +94,20 @@ static void real_plog(int lvl, const char *fmt, va_list vargs)
 struct opt_tab dbg_opt[] =
 {
   {"all", D_ALL},              /* All non-disruptive options */
-  {"amq", D_AMQ},              /* Don't register for AMQ program */
-  {"daemon", D_DAEMON},                /* Don't enter daemon mode */
-  {"fork", D_FORK},            /* Don't fork server */
+  {"defaults", D_DEFAULT},     /* Default options */
+  {"test", D_TEST},            /* Full debug - no daemon, no fork, no amq, local mtab */
+  {"amq", D_AMQ},              /* Register for AMQ program */
+  {"daemon", D_DAEMON},                /* Enter daemon mode */
+  {"fork", D_FORK},            /* Fork server (hlfsd only) */
   {"full", D_FULL},            /* Program trace */
 #ifdef HAVE_CLOCK_GETTIME
   {"hrtime", D_HRTIME},                /* Print high resolution time stamps */
 #endif /* HAVE_CLOCK_GETTIME */
-  /* info service specific debugging (hesiod, nis, etc) */
-  {"info", D_INFO},
+  {"info", D_INFO},            /* info service specific debugging (hesiod, nis, etc) */
   {"mem", D_MEM},              /* Trace memory allocations */
   {"mtab", D_MTAB},            /* Use local mtab file */
   {"readdir", D_READDIR},      /* Check on browsable_dirs progress */
   {"str", D_STR},              /* Debug string munging */
-  {"test", D_TEST},            /* Full debug - no daemon, no amq, local mtab */
   {"trace", D_TRACE},          /* Protocol trace */
   {"xdrtrace", D_XDRTRACE},    /* Trace xdr routines */
   {NULL, 0}
@@ -387,7 +391,25 @@ show_time_host_and_name(int lvl)
 int
 debug_option(char *opt)
 {
-  return cmdoption(opt, dbg_opt, &debug_flags);
+  u_int dl = debug_flags;
+  int rc = cmdoption(opt, dbg_opt, &dl);
+
+  if (rc)                  /* if got any error, don't update debug flags */
+    return EINVAL;
+
+  /*
+   * Don't allow "immutable" flags to be changed, because they could mess
+   * Amd's state and only make sense to be set once when Amd starts.
+   */
+  if (debug_flags != 0 &&
+      (dl & D_IMMUTABLE) != (debug_flags & D_IMMUTABLE)) {
+    plog(XLOG_ERROR, "cannot change immutable debug flags");
+    /* undo any attempted change to an immutable flag */
+    dl = (dl & ~D_IMMUTABLE) | (debug_flags & D_IMMUTABLE);
+  }
+  debug_flags = dl;
+
+  return rc;
 }
 
 
@@ -651,7 +673,7 @@ switch_option(char *opt)
    * 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");
+    plog(XLOG_ERROR, "cannot turn off mandatory logging options");
     xl |= XLOG_MANDATORY;
   }
   if (xlog_level != xl)
@@ -832,7 +854,7 @@ switch_to_logfile(char *logfile, int old_umask, int truncate_log)
 void
 unregister_amq(void)
 {
-  if (!amuDebug(D_AMQ))
+  if (amuDebug(D_AMQ))
     /* find which instance of amd to unregister */
     pmap_unset(get_amd_program_number(), AMQ_VERSION);
 }
index a280694f175588f04dd25c99229970a9a975a97c..ae491c12677b788b55aa899ee172b00cb75f8e7c 100644 (file)
@@ -58,8 +58,8 @@ nis_domain =                  nisDom-CS.columbia.edu
 # (amd -x)
 log_options =                  fatal,error,user,warn,info,map,stats,all
 # (amd -D)
-debug_options =                        all,amq,daemon,fork,full,hrtime,info,mem,mtab,\
-                               str,readdir,test,trace,xdrtrace
+debug_options =                        all,defaults,test,amq,daemon,fork,\
+                               full,hrtime,info,mem,mtab,str,readdir,trace,xdrtrace
 # path for mtab file during mtab debug mode
 debug_mtab_file =               /tmp/mnttab
 # (amd -S)
index 53568ca6327e7fcba94ca9513f364f684ae9e09f..e5d517f5d8997243f264e84075d268a66c918d51 100644 (file)
@@ -256,7 +256,9 @@ meaning.  You can get the list of supported debugging options by running Amd
 \-H.  Possible values are:
 
 .nf
-\fBall\fR       all options
+\fBall\fR       all options (excludes hrtime and mtab)
+\fBdefaults\fR  "sensible" default options (all--excluding hrtime, mtab, and xdrtrace)
+\fBtest\fR      full debug options plus mtab,nodaemon,nofork,noamq
 \fBamq\fR       register for amq
 \fBdaemon\fR    enter daemon mode
 \fBfork\fR      fork server
@@ -264,10 +266,9 @@ meaning.  You can get the list of supported debugging options by running Amd
 \fBhrtime\fR    print high resolution time stamps (only if syslog(3) is not used)
 \fBinfo\fR      info service specific debugging (hesiod, nis, etc.)
 \fBmem\fR       trace memory allocations
-\fBmtab\fR      use local "./mtab" file
+\fBmtab\fR      use local "/tmp/mtab" file
 \fBreaddir\fR   show browsable_dirs progress
 \fBstr\fR       debug string munging
-\fBtest\fR      full debug but no daemon
 \fBtrace\fR     trace protocol and NFS mount arguments
 \fBxdrtrace\fR  trace XDR routines
 .fi