Skip to content

Commit

Permalink
squash w/ [7229] Redesign startup/shutdown process. Improve _POSIX_PA…
Browse files Browse the repository at this point in the history
…TH_MAX cases (better solution will be provided in separate PR).
  • Loading branch information
korydraughn committed Dec 2, 2024
1 parent 1b87b33 commit 8095ece
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions server/core/src/irods_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <boost/stacktrace/safe_dump_to.hpp>

#include <array>
#include <climits> // For _POSIX_PATH_MAX
#include <csignal>
#include <cstdio>
#include <cstdlib>
Expand All @@ -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<char, _POSIX_PATH_MAX> g_stacktrace_dir;
constexpr auto g_max_path_size = 1024;

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::array<char, g_max_path_size> g_stacktrace_dir;
} // anonymous namespace

extern "C"
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/main_server/src/agent_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace
using log_af = irods::experimental::log::agent_factory;
using log_agent = irods::experimental::log::agent;

std::array<char, _POSIX_PATH_MAX> g_proc_directory; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
std::array<char, 1024> 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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8095ece

Please sign in to comment.