From 8095ecec066703c942243ad2f8538eadd5b6c51b Mon Sep 17 00:00:00 2001 From: Kory Draughn Date: Sun, 1 Dec 2024 19:40:50 -0500 Subject: [PATCH] squash w/ [7229] Redesign startup/shutdown process. Improve _POSIX_PATH_MAX cases (better solution will be provided in separate PR). --- server/core/src/irods_signal.cpp | 17 ++++++++++------- server/main_server/src/agent_main.cpp | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/core/src/irods_signal.cpp b/server/core/src/irods_signal.cpp index 8243158903..906989940e 100644 --- a/server/core/src/irods_signal.cpp +++ b/server/core/src/irods_signal.cpp @@ -8,7 +8,6 @@ #include #include -#include // For _POSIX_PATH_MAX #include #include #include @@ -22,8 +21,14 @@ namespace { + // This value represents the maximum size of a path for stacktrace handling. By picking a + // value, we are opting to "try" writing the stacktrace to a file first, rather than checking + // the OS limits and adapting to them. // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - std::array g_stacktrace_dir; + constexpr auto g_max_path_size = 1024; + + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + std::array g_stacktrace_dir; } // anonymous namespace extern "C" @@ -34,10 +39,8 @@ void stacktrace_signal_handler(int _signal) _exit(_signal); } - // "_POSIX_PATH_MAX" is guaranteed to be defined as 256. - // This value represents the minimum path length supported by POSIX operating systems. - char file_path_unprocessed[_POSIX_PATH_MAX]; - std::strncpy(file_path_unprocessed, g_stacktrace_dir.data(), _POSIX_PATH_MAX); + char file_path_unprocessed[g_max_path_size]; + std::strncpy(file_path_unprocessed, g_stacktrace_dir.data(), g_max_path_size); std::strcat(file_path_unprocessed, "/"); // At this point, "file_path_unprocessed" should have the following path: @@ -68,7 +71,7 @@ void stacktrace_signal_handler(int _signal) // This keeps the files sorted by timestamp and by pid. *pid_end = 0; - char file_path[_POSIX_PATH_MAX]; + char file_path[g_max_path_size]; std::strcpy(file_path, file_path_unprocessed); // An indicator to the thread handling the logging of these files that this file diff --git a/server/main_server/src/agent_main.cpp b/server/main_server/src/agent_main.cpp index 5044082a3b..ada690cf3a 100644 --- a/server/main_server/src/agent_main.cpp +++ b/server/main_server/src/agent_main.cpp @@ -99,7 +99,7 @@ namespace using log_af = irods::experimental::log::agent_factory; using log_agent = irods::experimental::log::agent; - std::array g_proc_directory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + std::array g_proc_directory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) std::time_t g_graceful_shutdown_timeout{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) auto init_logger(pid_t _pid, bool _write_to_stdout, bool _enable_test_mode) -> void; @@ -1118,7 +1118,7 @@ namespace pid_t pid; int status; char agent_pid[16]; - char agent_pid_file_path[1024]; // TODO _POSIX_PATH_MAX? + char agent_pid_file_path[1024]; const auto unlink_agent_pid_file = [&](const pid_t _pid) { auto [p, ec] = std::to_chars(agent_pid, agent_pid + sizeof(agent_pid), _pid);