From 4dc3a694a6932fd1d6506a0d3b225ab908771e3a Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Tue, 26 Jul 2005 01:48:12 +0000 Subject: [PATCH] * 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. --- ChangeLog | 20 ++++++++++++++++++++ NEWS | 6 ++++++ amd/amd.h | 6 ++++-- amd/amq_subr.c | 4 ++-- amd/conf.c | 20 +++++++++++++++++++- amd/get_args.c | 5 +++-- doc/am-utils.texi | 19 ++++++++++++++++--- hlfsd/hlfsd.c | 6 +++--- include/am_utils.h | 4 ++-- libamu/xutil.c | 8 +++++--- scripts/amd.conf-sample | 2 ++ scripts/amd.conf.5 | 7 ++++++- 12 files changed, 88 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index c182432..9b13be9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 2005-07-25 Erez Zadok + * 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 0f1b260..50c523b 100644 --- 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 diff --git a/amd/amd.h b/amd/amd.h index e5b1ab6..1316d40 100644 --- 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) diff --git a/amd/amq_subr.c b/amd/amq_subr.c index 8b6776a..5855b0b 100644 --- a/amd/amq_subr.c +++ b/amd/amq_subr.c @@ -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; diff --git a/amd/conf.c b/amd/conf.c index be7be77..11117be 100644 --- a/amd/conf.c +++ b/amd/conf.c @@ -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) { diff --git a/amd/get_args.c b/amd/get_args.c index 8639c8e..ae7eb9c 100644 --- a/amd/get_args.c +++ b/amd/get_args.c @@ -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; diff --git a/doc/am-utils.texi b/doc/am-utils.texi index 05a3ae4..28c5004 100644 --- a/doc/am-utils.texi +++ b/doc/am-utils.texi @@ -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 diff --git a/hlfsd/hlfsd.c b/hlfsd/hlfsd.c index 6803ae9..d1f4e49 100644 --- a/hlfsd/hlfsd.c +++ b/hlfsd/hlfsd.c @@ -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 and Alexander Dupuy @@ -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 diff --git a/include/am_utils.h b/include/am_utils.h index 33c0891..e895bc1 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -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); diff --git a/libamu/xutil.c b/libamu/xutil.c index 7d68aa6..a56e107 100644 --- a/libamu/xutil.c +++ b/libamu/xutil.c @@ -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); } diff --git a/scripts/amd.conf-sample b/scripts/amd.conf-sample index cc43fa0..bee8b35 100644 --- a/scripts/amd.conf-sample +++ b/scripts/amd.conf-sample @@ -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) diff --git a/scripts/amd.conf.5 b/scripts/amd.conf.5 index 141c5a0..f613d14 100644 --- a/scripts/amd.conf.5 +++ b/scripts/amd.conf.5 @@ -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 -- 2.43.0