Blame log-history-to-syslog.patch

430b2d
diff --git a/CMakeLists.txt b/CMakeLists.txt
430b2d
index 2e90030..4394696 100644
430b2d
--- a/CMakeLists.txt
430b2d
+++ b/CMakeLists.txt
430b2d
@@ -115,6 +115,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
diff --git a/src/reader.cpp b/src/reader.cpp
430b2d
index 785f680..16f55e2 100644
430b2d
--- a/src/reader.cpp
430b2d
+++ b/src/reader.cpp
430b2d
@@ -74,6 +74,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"
430b2d
 #include "wildcard.h"
430b2d
@@ -3479,6 +3480,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
430b2d
                     break;
430b2d
                 }
430b2d
 
430b2d
+                fish_syslog_history(text);
430b2d
+
430b2d
                 // Historical behavior is to trim trailing spaces.
430b2d
                 // However, escaped spaces ('\ ') should not be trimmed (#7661)
430b2d
                 // This can be done by counting pre-trailing '\'
430b2d
diff --git a/src/syslog.cpp b/src/syslog.cpp
430b2d
new file mode 100644
430b2d
index 0000000..c22c47b
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
diff --git a/src/syslog.h b/src/syslog.h
430b2d
new file mode 100644
430b2d
index 0000000..ce0ce25
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