* libamu/xutil.c (switch_to_logfile): truncate a regular-file log
authorErez Zadok <ezk@cs.sunysb.edu>
Tue, 26 Jul 2005 01:48:12 +0000 (01:48 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 26 Jul 2005 01:48:12 +0000 (01:48 +0000)
file if user passed non-zero "truncate_log" flag.

* include/am_utils.h: switch_to_logfile() now takes a 3rd arg.

* amd/get_args.c (get_args): pass "truncate_log" flag as per
amd.conf global settings.

* amd/conf.c (gopt_truncate_log): store global value of
truncate_log flag.

* amd/amq_subr.c (amqproc_setopt_1_svc), hlfsd/hlfsd.c (main,
reload): don't truncate log file when calling switch_to_logfile().

* amd/amd.h (CFM_TRUNCATE_LOG): new flag.  Fix comment typo.

* NEWS, doc/am-utils.texi (truncate_log Parameter),
scripts/amd.conf.5, scripts/amd.conf-sample (log_file): document
new truncate_log amd.conf parameter.

12 files changed:
ChangeLog
NEWS
amd/amd.h
amd/amq_subr.c
amd/conf.c
amd/get_args.c
doc/am-utils.texi
hlfsd/hlfsd.c
include/am_utils.h
libamu/xutil.c
scripts/amd.conf-sample
scripts/amd.conf.5

index c18243284c0063ea8046998923b1e86ff2d77b2f..9b13be9e00d7a171e2190d617565651ae513d390 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2005-07-25  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * libamu/xutil.c (switch_to_logfile): truncate a regular-file log
+       file if user passed non-zero "truncate_log" flag.
+
+       * include/am_utils.h: switch_to_logfile() now takes a 3rd arg.
+
+       * amd/get_args.c (get_args): pass "truncate_log" flag as per
+       amd.conf global settings.
+
+       * amd/conf.c (gopt_truncate_log): store global value of
+       truncate_log flag.
+
+       * amd/amq_subr.c (amqproc_setopt_1_svc), hlfsd/hlfsd.c (main,
+       reload): don't truncate log file when calling switch_to_logfile().
+
+       * amd/amd.h (CFM_TRUNCATE_LOG): new flag.  Fix comment typo.
+
+       * NEWS, doc/am-utils.texi (truncate_log Parameter),
+       scripts/amd.conf.5, scripts/amd.conf-sample (log_file): document
+       new truncate_log amd.conf parameter.
+
        * amd/conf.c (gopt_forced_unmounts): check Linux kernel version
        and alert if your version may be too old for MNT_FORCE to work
        (before 2.4.0) or for MNT_DETACH to work (before 2.6.0).
diff --git a/NEWS b/NEWS
index 0f1b2603afd5e4f64ad7a0fc9dcba7410c45b120..50c523b792a0029bb28d5d5f23588074ed96f91b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,12 @@ shutdown cleanly, even if some processes (i.e., user shells) have their CWD
 on Amd's own mount point.  This functionality is available for Linux, BSD44
 systems, Solaris, OSF/1, and partially for AIX.
 
+New amd.conf global parameter: truncate_log (default to "no").  If set to
+"yes", then Amd will truncate the log file (if it's a regular file) on
+startup.  This could be useful when conducting extensive testing on Amd maps
+(or Amd itself) and you don't want to see log data from a previous run in
+the same file.
+
 - minor new ports:
        i386-pc-linux-fc4
        i386-pc-linux-suse9.3
index e5b1ab6178d049cae0df979e55b7200326d6ff58..1316d40d8af539e6b2fa2880066c1bb5b6e4fedd 100644 (file)
--- a/amd/amd.h
+++ b/amd/amd.h
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: amd.h,v 1.67 2005/07/20 03:32:30 ezk Exp $
+ * $Id: amd.h,v 1.68 2005/07/26 01:48:13 ezk Exp $
  *
  */
 
@@ -74,7 +74,9 @@
 #define CFM_NFS_INSECURE_PORT          0x00002000
 #define CFM_DOMAIN_STRIP               0x00004000
 #define CFM_NORMALIZE_SLASHES          0x00008000 /* normalize slashes? */
-#define CFM_FORCED_UNMOUNTS            0x00010000 /* normalize slashes? */
+#define CFM_FORCED_UNMOUNTS            0x00010000 /* forced unmounts? */
+#define CFM_TRUNCATE_LOG               0x00020000 /* truncate log file? */
+
 /* defaults global flags: plock, tcpwrappers, and autofs/lofs */
 #define CFM_DEFAULT_FLAGS      (CFM_PROCESS_LOCK|CFM_USE_TCPWRAPPERS|CFM_AUTOFS_USE_LOFS|CFM_DOMAIN_STRIP|CFM_NORMALIZE_SLASHES)
 
index 8b6776af81c0970911f6b37e2fe1778262b5905a..5855b0baed919eba378b819e8f782ec97b17d2a3 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: amq_subr.c,v 1.19 2005/01/03 20:56:45 ezk Exp $
+ * $Id: amq_subr.c,v 1.20 2005/07/26 01:48:13 ezk Exp $
  *
  */
 /*
@@ -138,7 +138,7 @@ amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp)
   case AMOPT_LOGFILE:
     if (gopt.logfile && opt->as_str
        && STREQ(gopt.logfile, opt->as_str)) {
-      if (switch_to_logfile(opt->as_str, orig_umask))
+      if (switch_to_logfile(opt->as_str, orig_umask, 0))
        rc = EINVAL;
     } else {
       rc = EACCES;
index be7be77ff9e062164412579255cfb1ab86902b4d..11117beaca7eaccb1028ad1b645f8d782f4b916f 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: conf.c,v 1.34 2005/07/25 23:49:41 ezk Exp $
+ * $Id: conf.c,v 1.35 2005/07/26 01:48:13 ezk Exp $
  *
  */
 
@@ -129,6 +129,7 @@ static int gopt_restart_mounts(const char *val);
 static int gopt_search_path(const char *val);
 static int gopt_selectors_in_defaults(const char *val);
 static int gopt_show_statfs_entries(const char *val);
+static int gopt_truncate_log(const char *val);
 static int gopt_unmount_on_exit(const char *val);
 static int gopt_use_tcpwrappers(const char *val);
 static int gopt_vendor(const char *val);
@@ -208,6 +209,7 @@ static struct _func_map glob_functable[] = {
   {"selectors_on_default",     gopt_selectors_in_defaults},
   {"selectors_in_defaults",    gopt_selectors_in_defaults},
   {"show_statfs_entries",      gopt_show_statfs_entries},
+  {"truncate_log",             gopt_truncate_log},
   {"unmount_on_exit",          gopt_unmount_on_exit},
   {"use_tcpwrappers",          gopt_use_tcpwrappers},
   {"vendor",                   gopt_vendor},
@@ -1081,6 +1083,22 @@ gopt_show_statfs_entries(const char *val)
 }
 
 
+static int
+gopt_truncate_log(const char *val)
+{
+  if (STREQ(val, "yes")) {
+    gopt.flags |= CFM_TRUNCATE_LOG;
+    return 0;
+  } else if (STREQ(val, "no")) {
+    gopt.flags &= ~CFM_TRUNCATE_LOG;
+    return 0;
+  }
+
+  fprintf(stderr, "conf: unknown value to truncate_log \"%s\"\n", val);
+  return 1;                    /* unknown value */
+}
+
+
 static int
 gopt_unmount_on_exit(const char *val)
 {
index 8639c8e8adc03a121b09c8d123097e9aeb2f2232..ae7eb9c5f701a1720cb0bce411283106c915ea70 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: get_args.c,v 1.33 2005/07/07 23:34:23 ezk Exp $
+ * $Id: get_args.c,v 1.34 2005/07/26 01:48:13 ezk Exp $
  *
  */
 
@@ -428,7 +428,8 @@ get_args(int argc, char *argv[])
     exit(0);
   }
 
-  if (switch_to_logfile(gopt.logfile, orig_umask) != 0)
+  if (switch_to_logfile(gopt.logfile, orig_umask,
+                       (gopt.flags & CFM_TRUNCATE_LOG)) != 0)
     plog(XLOG_USER, "Cannot switch logfile");
 
   return;
index 05a3ae4dc7ac43c0775cb27b1ee916cee002381d..28c50046bd4fb3b128710d4b7d9e72e23fc50758 100644 (file)
@@ -38,7 +38,7 @@
 @c
 @c      %W% (Berkeley) %G%
 @c
-@c $Id: am-utils.texi,v 1.105 2005/07/21 05:22:47 ezk Exp $
+@c $Id: am-utils.texi,v 1.106 2005/07/26 01:48:13 ezk Exp $
 @c
 @setfilename am-utils.info
 
@@ -4315,6 +4315,7 @@ The following parameters are applicable to the @samp{[global]} section only.
 * restart_mounts Parameter::
 * selectors_in_defaults Parameter::
 * show_statfs_entries Parameter::
+* truncate_log Parameter::
 * unmount_on_exit Parameter::
 * use_tcpwrappers Parameter::
 * vendor Parameter::
@@ -4962,7 +4963,7 @@ follows:
 Deprecated form: selectors_on_default.
 
 @c ----------------------------------------------------------------
-@node show_statfs_entries Parameter, unmount_on_exit Parameter, selectors_in_defaults Parameter, Global Parameters
+@node show_statfs_entries Parameter, truncate_log Parameter, selectors_in_defaults Parameter, Global Parameters
 @comment  node-name,  next,  previous,  up
 @subsection @t{show_statfs_entries} Parameter
 @cindex show_statfs_entries Parameter
@@ -4973,7 +4974,19 @@ browsable will also show the number of entries (keys) they have when
 the @b{statfs}(2) system call).
 
 @c ----------------------------------------------------------------
-@node unmount_on_exit Parameter, use_tcpwrappers Parameter, show_statfs_entries Parameter, Global Parameters
+@node truncate_log Parameter, unmount_on_exit Parameter, show_statfs_entries Parameter, Global Parameters
+@comment  node-name,  next,  previous,  up
+@subsection @t{truncate_log} Parameter
+@cindex truncate_log Parameter
+
+(type=boolean), default=@samp{no}).  If @samp{yes}, then @i{Amd} will
+truncate the log file (if it's a regular file) on startup.  This could
+be useful when conducting extensive testing on @i{Amd} maps (or
+@i{Amd} itself) and you don't want to see log data from a previous run
+in the same file.
+
+@c ----------------------------------------------------------------
+@node unmount_on_exit Parameter, use_tcpwrappers Parameter, truncate_log Parameter, Global Parameters
 @comment  node-name,  next,  previous,  up
 @subsection @t{unmount_on_exit} Parameter
 @cindex unmount_on_exit Parameter
index 6803ae97796a1e64115f1a00b13ba8803313b223..d1f4e495bbfbbaf577403954743529f8e0500d0e 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: hlfsd.c,v 1.32 2005/02/27 23:53:22 ezk Exp $
+ * $Id: hlfsd.c,v 1.33 2005/07/26 01:48:13 ezk Exp $
  *
  * HLFSD was written at Columbia University Computer Science Department, by
  * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu>
@@ -307,7 +307,7 @@ main(int argc, char *argv[])
     *dot = '\0';
   orig_umask = umask(0);
   if (logfile)
-    switch_to_logfile(logfile, orig_umask);
+    switch_to_logfile(logfile, orig_umask, 0);
 
 #ifndef MOUNT_TABLE_ON_FILE
   if (amuDebug(D_MTAB))
@@ -790,7 +790,7 @@ reload(int signum)
    * can be rotated)
    */
   if (signum == SIGHUP && logfile)
-    switch_to_logfile(logfile, orig_umask);
+    switch_to_logfile(logfile, orig_umask, 0);
 
   /*
    * parent performs the reload, while the child continues to serve
index 33c08911ebb1df77ae63cb800332d18e70da50e0..e895bc11b9553143e20ae9c2c8a5b11d604f41ae 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: am_utils.h,v 1.68 2005/07/21 05:22:47 ezk Exp $
+ * $Id: am_utils.h,v 1.69 2005/07/26 01:48:13 ezk Exp $
  *
  */
 
@@ -304,7 +304,7 @@ extern int mount_fs(mntent_t *, int, caddr_t, int, MTYPE_TYPE, u_long, const cha
 extern void nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp);
 extern int pickup_rpc_reply(voidp, int, voidp, XDRPROC_T_TYPE);
 extern int switch_option(char *);
-extern int switch_to_logfile(char *logfile, int orig_umask);
+extern int switch_to_logfile(char *logfile, int orig_umask, int truncate_log);
 extern mntlist *read_mtab(char *, const char *);
 #ifndef HAVE_TRANSPORT_TYPE_TLI
 extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt);
index 7d68aa69c78724abb80b08a8f47b7812fe8b3928..a56e107f575d835faf3b95e1bc54526920993b8f 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: xutil.c,v 1.38 2005/07/07 23:34:23 ezk Exp $
+ * $Id: xutil.c,v 1.39 2005/07/26 01:48:13 ezk Exp $
  *
  */
 
@@ -774,7 +774,7 @@ get_syslog_facility(const char *logfile)
  * Change current logfile
  */
 int
-switch_to_logfile(char *logfile, int old_umask)
+switch_to_logfile(char *logfile, int old_umask, int truncate_log)
 {
   FILE *new_logfp = stderr;
 
@@ -806,8 +806,10 @@ switch_to_logfile(char *logfile, int old_umask)
       plog(XLOG_WARNING, "syslog option not supported, logging unchanged");
 #endif /* not HAVE_SYSLOG */
 
-    } else {
+    } else {                   /* regular log file */
       (void) umask(old_umask);
+      if (truncate_log)
+       truncate(logfile, 0);
       new_logfp = fopen(logfile, "a");
       umask(0);
     }
index cc43fa0f81f2a3f5d1ad2dbf31ac6621378319ea..bee8b35e4b7ac5ac82579d4de9847cd1402bad3a 100644 (file)
@@ -38,6 +38,8 @@ vendor =                      redhat
 print_version =                        no | yes
 # (amd -l)
 log_file =                     /dev/stderr | /var/log/amd | syslog[:facility]
+# should we truncate the log file on startup?
+truncate_log =                 no | yes
 # NFS (RPC) retry interval/counter, in tenths of secs (amd -t interval.counter)
 nfs_retry_interval =           8
 nfs_retransmit_counter =       11 (eleven retransmission attempts)
index 141c5a062cff06af7ea92aaa4c4ee8b9b4e9101b..f613d1480721073f6725fc789f73b51678420c76 100644 (file)
@@ -38,7 +38,7 @@
 .\"
 .\"    %W% (Berkeley) %G%
 .\"
-.\" $Id: amd.conf.5,v 1.38 2005/07/20 03:32:31 ezk Exp $
+.\" $Id: amd.conf.5,v 1.39 2005/07/26 01:48:13 ezk Exp $
 .\"
 .TH AMD.CONF 5 "7 August 1997"
 .SH NAME
@@ -647,6 +647,11 @@ If "yes," then all maps which are browsable will also show the number of
 entries (keys) they have when "df" runs. (This is accomplished by returning
 non-zero values to the statfs(2) system call).
 
+.TP
+.BR truncate_log " (boolean), default=no)"
+If "yes," then the log file (if it is a regular file), will be truncated
+upon startup.
+
 .TP
 .BR unmount_on_exit " (boolean), default=no)"
 If "yes," then amd will attempt to unmount all file systems which it knows