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