Blame log-history-to-syslog.patch

430b2d
--- a/CMakeLists.txt
430b2d
+++ b/CMakeLists.txt
Michel Lind ef745b
@@ -121,6 +121,7 @@ set(FISH_SRCS
430b2d
     src/tokenizer.cpp src/topic_monitor.cpp src/trace.cpp src/utf8.cpp src/util.cpp
430b2d
     src/wait_handle.cpp src/wcstringutil.cpp src/wgetopt.cpp src/wildcard.cpp 
430b2d
     src/wutil.cpp src/fds.cpp
430b2d
+    src/syslog.cpp
430b2d
 )
430b2d
 
430b2d
 # Header files are just globbed.
430b2d
--- a/src/reader.cpp
430b2d
+++ b/src/reader.cpp
Michel Lind ef745b
@@ -76,6 +76,7 @@
430b2d
 #include "reader.h"
430b2d
 #include "screen.h"
430b2d
 #include "signal.h"
430b2d
+#include "syslog.h"
430b2d
 #include "termsize.h"
430b2d
 #include "tokenizer.h"
Michel Lind ef745b
 #include "wcstringutil.h"
Michel Lind ef745b
@@ -4355,6 +4356,7 @@ void reader_data_t::add_to_history() con
Michel Lind ef745b
         } else {
Michel Lind ef745b
             mode = history_persistence_mode_t::disk;
Michel Lind ef745b
         }
Michel Lind ef745b
+        fish_syslog_history(text);
Michel Lind ef745b
         history_t::add_pending_with_file_detection(history, text, this->vars().snapshot(), mode);
Michel Lind ef745b
     }
Michel Lind ef745b
 }
430b2d
--- /dev/null
430b2d
+++ b/src/syslog.cpp
430b2d
@@ -0,0 +1,24 @@
430b2d
+// Syslogging utilities.
430b2d
+#include <stdlib.h>
430b2d
+#include <unistd.h>
430b2d
+
430b2d
+#include "syslog.h"
430b2d
+#include "wcstringutil.h"
430b2d
+
430b2d
+void fish_syslog_history(const wcstring &str) {
430b2d
+    char cmd[SYSLOG_MAXLEN+1];
430b2d
+    static int first = 1;
430b2d
+
430b2d
+    if (first) {
430b2d
+        openlog(SYSLOG_SHELLNAME, OPENLOG_OPTS, SYSLOG_FACILITY);
430b2d
+        first = 0;
430b2d
+    }
430b2d
+
430b2d
+    int rc = wcstombs(cmd, str.c_str(), SYSLOG_MAXLEN);
430b2d
+
430b2d
+    if (rc < SYSLOG_MAXLEN) {
430b2d
+        syslog(SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s", getpid(), getuid(), cmd);
430b2d
+    } else {
430b2d
+        syslog(SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d %s", getpid(), getuid(), cmd);
430b2d
+    }
430b2d
+}
430b2d
--- /dev/null
430b2d
+++ b/src/syslog.h
430b2d
@@ -0,0 +1,17 @@
430b2d
+// Syslogging utilities.
430b2d
+#ifndef FISH_SYSLOG_H
430b2d
+#define FISH_SYSLOG_H
430b2d
+
430b2d
+#include <syslog.h>
430b2d
+
430b2d
+#include "common.h"
430b2d
+
430b2d
+#define SYSLOG_SHELLNAME "fish"
430b2d
+#define SYSLOG_MAXLEN 600
430b2d
+#define SYSLOG_FACILITY LOG_AUTHPRIV
430b2d
+#define SYSLOG_LEVEL LOG_INFO
430b2d
+#define OPENLOG_OPTS LOG_PID
430b2d
+
430b2d
+void fish_syslog_history(const wcstring &str);
430b2d
+
430b2d
+#endif