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