bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add shopt to enable writing history to syslog at runtime


From: Luca Boccassi
Subject: [PATCH] Add shopt to enable writing history to syslog at runtime
Date: Fri, 18 May 2018 10:34:42 +0100

Currently writing history to syslog can be enabled at compile time by
editing config-top.h and rebuilding.
To allow more flexibility, and to allow users of distributions to
enable this feature at runtime without having to rebuild bash, add a
"syslog" shopt.
To maintain backward compatibility keep using SYSLOG_HISTORY as before
to enable logging to syslog unconditionally.

Signed-off-by: Luca Boccassi <bluca@debian.org>
---
 bashhist.c         | 27 +++++++++++++++++++++++----
 builtins/shopt.def | 11 +++++++++++
 doc/bash.0         |  3 +++
 doc/bash.1         |  5 +++++
 doc/bash.html      |  6 ++++++
 doc/bash.info      |  5 +++++
 doc/bashref.html   |  6 ++++++
 doc/bashref.info   |  5 +++++
 doc/builtins.0     |  3 +++
 9 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/bashhist.c b/bashhist.c
index 4cf0e4f9..2a5cf35a 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -38,7 +38,7 @@
 
 #include "bashintl.h"
 
-#if defined (SYSLOG_HISTORY)
+#if defined (HAVE_SYSLOG)
 #  include <syslog.h>
 #endif
 
@@ -773,12 +773,27 @@ check_add_history (line, force)
   return 0;
 }
 
-#if defined (SYSLOG_HISTORY)
+#if defined (HAVE_SYSLOG)
 #define SYSLOG_MAXLEN 600
 
 #ifndef OPENLOG_OPTS
+/* Backward compatibility: leave _OPTS to 0 if not defined in config-tops.h
+   with SYSLOG_HISTORY. */
+#ifdef SYSLOG_HISTORY
 #define OPENLOG_OPTS 0
+#else
+#define OPENLOG_OPTS LOG_PID
 #endif
+#endif
+
+#ifndef SYSLOG_FACILITY
+#define SYSLOG_FACILITY LOG_USER
+#endif
+#ifndef SYSLOG_LEVEL
+#define SYSLOG_LEVEL LOG_INFO
+#endif
+
+int syslog_history_enabled = 0;
 
 void
 bash_syslog_history (line)
@@ -882,8 +897,12 @@ bash_add_history (line)
   if (add_it)
     really_add_history (line);
 
-#if defined (SYSLOG_HISTORY)
-  bash_syslog_history (line);
+#if defined (HAVE_SYSLOG)
+/* Backward compatibility: SYSLOG_HISTORY always enables syslog. */
+#if !defined (SYSLOG_HISTORY)
+  if (syslog_history_enabled)
+#endif
+    bash_syslog_history (line);
 #endif
 
   using_history ();
diff --git a/builtins/shopt.def b/builtins/shopt.def
index 467dc534..8340353a 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -121,6 +121,10 @@ extern int assoc_expand_once;
 extern int array_expand_once;
 #endif
 
+#if defined (HAVE_SYSLOG)
+extern int syslog_history_enabled;
+#endif
+
 static void shopt_error __P((char *));
 
 static int set_shellopts_after_change __P((char *, int));
@@ -236,6 +240,9 @@ static struct {
   { "shift_verbose", &print_shift_error, (shopt_set_func_t *)NULL },
   { "sourcepath", &source_uses_path, (shopt_set_func_t *)NULL },
   { "xpg_echo", &xpg_echo, (shopt_set_func_t *)NULL },
+#if defined (HAVE_SYSLOG)
+  { "syslog", &syslog_history_enabled, (shopt_set_func_t *)NULL },
+#endif
   { (char *)0, (int *)0, (shopt_set_func_t *)NULL }
 };
 
@@ -381,6 +388,10 @@ reset_shopt_options ()
   xpg_echo = 0;
 #endif /* DEFAULT_ECHO_TO_XPG */
 
+#if defined (HAVE_SYSLOG)
+  syslog_history_enabled = 0;
+#endif
+
   shopt_login_shell = login_shell;
 }
 
diff --git a/doc/bash.0 b/doc/bash.0
index bb2f7429..afceb443 100644
--- a/doc/bash.0
+++ b/doc/bash.0
@@ -5741,6 +5741,9 @@ SSHHEELLLL BBUUIILLTTIINN 
CCOOMMMMAANNDDSS
                       If set, the ssoouurrccee (..) builtin uses the 
value of PPAATTHH to
                       find  the  directory  containing the file supplied as an
                       argument.  This option is enabled by default.
+              ssyysslloogg  If set, the history will be sent to syslog 
with facility
+                      LLOOGG__UUSSEERR and level 
LLOOGG__IINNFFOO.  This option is disabled by
+                      default.
               xxppgg__eecchhoo
                       If  set,  the  eecchhoo  builtin  expands   
backslash-escape
                       sequences by default.
diff --git a/doc/bash.1 b/doc/bash.1
index cf712fe3..f19432ff 100644
--- a/doc/bash.1
+++ b/doc/bash.1
@@ -10152,6 +10152,11 @@ If set, the
 to find the directory containing the file supplied as an argument.
 This option is enabled by default.
 .TP 8
+.B syslog
+If set, the history will be sent to syslog with facility
+\fBLOG_USER\fP and level \fBLOG_INFO\fP.
+This option is disabled by default.
+.TP 8
 .B xpg_echo
 If set, the \fBecho\fP builtin expands backslash-escape sequences
 by default.
diff --git a/doc/bash.html b/doc/bash.html
index 54b42fec..574db317 100644
--- a/doc/bash.html
+++ b/doc/bash.html
@@ -12869,6 +12869,12 @@ If set, the
 </FONT>
 to find the directory containing the file supplied as an argument.
 This option is enabled by default.
+<DT><B>syslog</B>
+
+<DD>
+If set, the history will be sent to syslog with facility
+<B>LOG_USER</B> and level <B>LOG_INFO</B>.
+This option is disabled by default.
 <DT><B>xpg_echo</B>
 
 <DD>
diff --git a/doc/bash.info b/doc/bash.info
index 9a4edb08..1cef4bfd 100644
--- a/doc/bash.info
+++ b/doc/bash.info
@@ -4667,6 +4667,11 @@ This builtin allows you to change additional shell 
optional behavior.
           the directory containing the file supplied as an argument.
           This option is enabled by default.
 
+     'syslog'
+          If set, the history will be sent to syslog with facility
+          LOG_USER and level LOG_INFO.
+          This option is disabled by default.
+
      'xpg_echo'
           If set, the 'echo' builtin expands backslash-escape sequences
           by default.
diff --git a/doc/bashref.html b/doc/bashref.html
index f494f344..f64fbf21 100644
--- a/doc/bashref.html
+++ b/doc/bashref.html
@@ -6333,6 +6333,12 @@ to find the directory containing the file supplied as an 
argument.
 This option is enabled by default.
 </p>
 </dd>
+<dt><code>syslog</code></dt>
+<dd><p>If set, the history will be sent to syslog with facility 
<code>LOG_USER</code>
+and level <code>LOG_INFO</code>.
+This option is disabled by default.
+</p>
+</dd>
 <dt><code>xpg_echo</code></dt>
 <dd><p>If set, the <code>echo</code> builtin expands backslash-escape sequences
 by default.
diff --git a/doc/bashref.info b/doc/bashref.info
index 29dd0eff..c2ccaa58 100644
--- a/doc/bashref.info
+++ b/doc/bashref.info
@@ -4667,6 +4667,11 @@ This builtin allows you to change additional shell 
optional behavior.
           the directory containing the file supplied as an argument.
           This option is enabled by default.
 
+     'syslog'
+          If set, the history will be sent to syslog with facility
+          LOG_USER and level LOG_INFO.
+          This option is disabled by default.
+
      'xpg_echo'
           If set, the 'echo' builtin expands backslash-escape sequences
           by default.
diff --git a/doc/builtins.0 b/doc/builtins.0
index 4614dc50..98a3737f 100644
--- a/doc/builtins.0
+++ b/doc/builtins.0
@@ -1572,6 +1572,9 @@ BBAASSHH BBUUIILLTTIINN 
CCOOMMMMAANNDDSS
                       If set, the ssoouurrccee (..) builtin uses the 
value of PPAATTHH to
                       find the directory containing the file  supplied  as  an
                       argument.  This option is enabled by default.
+              ssyysslloogg  If set, the history will be sent to syslog 
with facility
+                      LLOOGG__UUSSEERR and level 
LLOOGG__IINNFFOO.  This option is disabled by
+                      default.
               xxppgg__eecchhoo
                       If   set,  the  eecchhoo  builtin  expands  
backslash-escape
                       sequences by default.
-- 
2.14.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]