diff options
| author | Matthew Sackman <matthew@lshift.net> | 2009-11-25 14:47:40 +0000 |
|---|---|---|
| committer | Matthew Sackman <matthew@lshift.net> | 2009-11-25 14:47:40 +0000 |
| commit | 69caa8ecfbae5710684ad32a1c1093e3e99791fe (patch) | |
| tree | 5d2956a380b56d5b872f3d1cd449185ff0181cb3 /src | |
| parent | 1af739636733cb31e690017398ce2cdad5ab4f6e (diff) | |
| download | rabbitmq-server-git-69caa8ecfbae5710684ad32a1c1093e3e99791fe.tar.gz | |
Stop using _misc:cmd and use os:cmd instead
Diffstat (limited to 'src')
| -rw-r--r-- | src/file_handle_cache.erl | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index d67fd3657a..a299fc1e54 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -623,26 +623,27 @@ maybe_reduce(State) -> %% suggests that BSDs (incl OS X), solaris and linux all agree that %% ulimit -n is file handles ulimit() -> - try - %% under Linux, Solaris and FreeBSD, ulimit is a shell - %% builtin, not a command. In OS X, it's a command, but it's - %% still safe to call it this way: - case rabbit_misc:cmd("sh -c \"ulimit -n\"") of - "unlimited" -> infinity; - String = [C|_] when $0 =< C andalso C =< $9 -> - Num = list_to_integer( - lists:takewhile(fun (D) -> $0 =< D andalso D =< $9 end, - String)) - ?RESERVED_FOR_OTHERS, - lists:max([1, Num]); - String -> - error_logger:warning_msg( - "Unexpected result of \"ulimit -n\": ~p~n", [String]), - throw({unexpected_result, String}) - end - catch _ -> case os:type() of - {win32, _OsName} -> - ?FILE_HANDLES_LIMIT_WINDOWS; - _ -> - ?FILE_HANDLES_LIMIT_OTHER - ?RESERVED_FOR_OTHERS - end + case os:type() of + {win32, _OsName} -> + ?FILE_HANDLES_LIMIT_WINDOWS; + {unix, _OsName} -> + %% Under Linux, Solaris and FreeBSD, ulimit is a shell + %% builtin, not a command. In OS X, it's a command. + %% Fortunately, os:cmd invokes the cmd in a shell env, so + %% we're safe in all cases. + case os:cmd("ulimit -n") of + "unlimited" -> infinity; + String = [C|_] when $0 =< C andalso C =< $9 -> + Num = list_to_integer( + lists:takewhile( + fun (D) -> $0 =< D andalso D =< $9 end, String)) - + ?RESERVED_FOR_OTHERS, + lists:max([1, Num]); + _ -> + %% probably a variant of + %% "/bin/sh: line 1: ulimit: command not found\n" + ?FILE_HANDLES_LIMIT_OTHER - ?RESERVED_FOR_OTHERS + end; + _ -> + ?FILE_HANDLES_LIMIT_OTHER - ?RESERVED_FOR_OTHERS end. |
