Skip to content

Commit

Permalink
Add error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Feb 12, 2024
1 parent 32266e2 commit ccbae16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/monitor/process_monitor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ namespace monitor
[[noreturn]] static void run_command(const std::vector<std::string>& command_and_args)
{
struct rlimit initial_rlimit = initial_rlimit_fd();
setrlimit(RLIMIT_NOFILE, &initial_rlimit);

if (initial_rlimit.rlim_cur == 0)
{
Log::warn() << "Could not reset file descriptor limit to initial limit, the program under "
"measurement might behave erratically!";
}
else
{
setrlimit(RLIMIT_NOFILE, &initial_rlimit);
}

/* kill yourself if the parent dies */
prctl(PR_SET_PDEATHSIG, SIGHUP);
Expand Down
30 changes: 27 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ struct rlimit initial_rlimit_fd()

if (current.rlim_cur == 0)
{
getrlimit(RLIMIT_NOFILE, &current);
auto ret = getrlimit(RLIMIT_NOFILE, &current);

if (ret == -1)
{
Log::warn() << "Could not read file descriptor resource limit!";
}
}

return current;
Expand All @@ -382,9 +387,28 @@ struct rlimit initial_rlimit_fd()
void bump_rlimit_fd()
{
struct rlimit highest;
getrlimit(RLIMIT_NOFILE, &highest);

auto ret = getrlimit(RLIMIT_NOFILE, &highest);

if (ret == -1)
{
Log::warn()
<< "Could not read file descriptor hard resource limit, lo2s might run out of file "
"descriptors!";
Log::warn()
<< "If you encounter issues, try to manually increase the file descriptor rlimit.";
return;
}

highest.rlim_cur = highest.rlim_max;
setrlimit(RLIMIT_NOFILE, &highest);
ret = setrlimit(RLIMIT_NOFILE, &highest);

if (ret == -1)
{
Log::warn() << "Could not increase file descriptor resource limit, lo2s might run out of "
"file descriptors!";
Log::warn() << "If you encounter issues, try to manually increase the file descriptor "
"resource limit.";
}
}
} // namespace lo2s

0 comments on commit ccbae16

Please sign in to comment.