Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit b6abe30

Browse files
committed
Handle missing getconf command
Previous behavior is to crash, this is more forgiving Fixes #318
1 parent 8ca16c1 commit b6abe30

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/vm_memory_monitor.erl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,35 @@ get_vm_limit(_OsType) ->
443443
%% Internal Helpers
444444
%%----------------------------------------------------------------------------
445445
cmd(Command) ->
446+
cmd(Command, true).
447+
448+
cmd(Command, ThrowIfMissing) ->
446449
Exec = hd(string:tokens(Command, " ")),
447-
case os:find_executable(Exec) of
448-
false -> throw({command_not_found, Exec});
449-
_ -> os:cmd(Command)
450+
case {ThrowIfMissing, os:find_executable(Exec)} of
451+
{true, false} ->
452+
throw({command_not_found, Exec});
453+
{false, false} ->
454+
{error, command_not_found};
455+
{_, _Filename} ->
456+
os:cmd(Command)
450457
end.
451458

459+
default_linux_pagesize(CmdOutput) ->
460+
rabbit_log:warning(
461+
"Failed to get memory page size, using 4096. Reason: ~s",
462+
[CmdOutput]),
463+
4096.
464+
452465
get_linux_pagesize() ->
453-
CmdOutput = cmd("getconf PAGESIZE"),
454-
case re:run(CmdOutput, "^[0-9]+", [{capture, first, list}]) of
455-
{match, [Match]} -> list_to_integer(Match);
456-
_ ->
457-
rabbit_log:warning(
458-
"Failed to get memory page size, using 4096:~n~p~n",
459-
[CmdOutput]),
460-
4096
466+
case cmd("getconf PAGESIZE", false) of
467+
{error, command_not_found} ->
468+
default_linux_pagesize("getconf not found in PATH");
469+
CmdOutput ->
470+
case re:run(CmdOutput, "^[0-9]+", [{capture, first, list}]) of
471+
{match, [Match]} -> list_to_integer(Match);
472+
_ ->
473+
default_linux_pagesize(CmdOutput)
474+
end
461475
end.
462476

463477
%% get_total_memory(OS) -> Total

0 commit comments

Comments
 (0)