From 430b2db117b43f8875a721933ae12f411c9e7c1d Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Sep 06 2022 09:35:01 +0000 Subject: Add Facebook internal patch to log history to syslog --- diff --git a/fish.spec b/fish.spec index 5d9ec98..c03a910 100644 --- a/fish.spec +++ b/fish.spec @@ -40,6 +40,10 @@ Source0: https://github.com/fish-shell/fish-shell/archive/%{githash}/%{na # Disable sphinx logic that's incompatible with the version in el8 Patch1: disable-broken-doc-code.patch %endif +%if 0%{?facebook} +# Log history to syslog +Patch2: log-history-to-syslog.patch +%endif BuildRequires: cmake >= 3.5 BuildRequires: ninja-build @@ -155,6 +159,9 @@ fi %changelog * Tue Sep 06 2022 Davide Cavalca 3.5.1-2 +- Add Facebook internal patch to log history to syslog + +* Tue Sep 06 2022 Davide Cavalca 3.5.1-2 - Make it build on el8 * Mon Aug 15 2022 Siteshwar Vashisht 3.5.1-1 diff --git a/log-history-to-syslog.patch b/log-history-to-syslog.patch new file mode 100644 index 0000000..ff9fd65 --- /dev/null +++ b/log-history-to-syslog.patch @@ -0,0 +1,86 @@ +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 ++#include ++ ++#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 ++ ++#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