From e42881fa380ee2f299dc00bfbc38356f7919b0d2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 1 Jan 2017 13:10:08 +0000 Subject: [PATCH] Fix remaining uses of hardcoded /tmp to get the socket paths Fixes #1097 --- src/file.cc | 9 +++++++++ src/file.hh | 2 ++ src/main.cc | 9 ++++++--- src/remote.cc | 9 --------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/file.cc b/src/file.cc index 0867fa60..68ac6d12 100644 --- a/src/file.cc +++ b/src/file.cc @@ -133,6 +133,15 @@ String compact_path(StringView filename) return filename.str(); } +StringView tmpdir() +{ + StringView tmpdir = getenv("TMPDIR"); + if (not tmpdir.empty()) + return tmpdir.back() == '/' ? tmpdir.substr(0_byte, tmpdir.length()-1) + : tmpdir; + return "/tmp"; +} + bool fd_readable(int fd) { fd_set rfds; diff --git a/src/file.hh b/src/file.hh index 006d0cfd..a103d61f 100644 --- a/src/file.hh +++ b/src/file.hh @@ -24,6 +24,8 @@ String parse_filename(StringView filename); String real_path(StringView filename); String compact_path(StringView filename); +StringView tmpdir(); + // returns pair { directory, filename } std::pair split_path(StringView path); diff --git a/src/main.cc b/src/main.cc index 88646230..a6e81f30 100644 --- a/src/main.cc +++ b/src/main.cc @@ -761,8 +761,10 @@ int main(int argc, char* argv[]) const bool clear_sessions = (bool)parser.get_switch("clear"); if (list_sessions or clear_sessions) { - StringView username = getpwuid(geteuid())->pw_name; - for (auto& session : list_files(format("/tmp/kakoune/{}/", username))) + const StringView username = getpwuid(geteuid())->pw_name; + const StringView tmp_dir = tmpdir(); + for (auto& session : list_files(format("{}/kakoune/{}/", tmp_dir, + username))) { const bool valid = check_session(session); if (list_sessions) @@ -770,7 +772,8 @@ int main(int argc, char* argv[]) if (not valid and clear_sessions) { char socket_file[128]; - format_to(socket_file, "/tmp/kakoune/{}/{}", username, session); + format_to(socket_file, "{}/kakoune/{}/{}", tmp_dir, + username, session); unlink(socket_file); } } diff --git a/src/remote.cc b/src/remote.cc index 946c14e4..06259b67 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -480,15 +480,6 @@ void RemoteUI::set_ui_options(const Options& options) m_socket_watcher.events() |= FdEvents::Write; } -static StringView tmpdir() -{ - StringView tmpdir = getenv("TMPDIR"); - if (not tmpdir.empty()) - return tmpdir.back() == '/' ? tmpdir.substr(0_byte, tmpdir.length()-1) - : tmpdir; - return "/tmp"; -} - static sockaddr_un session_addr(StringView session) { sockaddr_un addr;