Blame rabbitmq-server-0003-Revert-Distinct-exit-codes-for-CLI-utilities.patch

Peter Lemenkov 6d093d
From: Peter Lemenkov <lemenkov@gmail.com>
Peter Lemenkov 6d093d
Date: Wed, 25 May 2016 22:24:44 +0300
Peter Lemenkov 6d093d
Subject: [PATCH] Revert "Distinct exit-codes for CLI utilities"
Peter Lemenkov 6d093d
Peter Lemenkov 6d093d
This reverts commit 7984540175d0b8852025165b6b6a0ac05d692c98.
Peter Lemenkov 6d093d
Peter Lemenkov 6d093d
diff --git a/include/rabbit_cli.hrl b/include/rabbit_cli.hrl
Peter Lemenkov 6d093d
index 7f5db60..01cb91c 100644
Peter Lemenkov 6d093d
--- a/include/rabbit_cli.hrl
Peter Lemenkov 6d093d
+++ b/include/rabbit_cli.hrl
Peter Lemenkov 6d093d
@@ -46,14 +46,3 @@
Peter Lemenkov 6d093d
 -define(RAM_DEF, {?RAM_OPT, flag}).
Peter Lemenkov 6d093d
 -define(OFFLINE_DEF, {?OFFLINE_OPT, flag}).
Peter Lemenkov 6d093d
 -define(ONLINE_DEF, {?ONLINE_OPT, flag}).
Peter Lemenkov 6d093d
-
Peter Lemenkov 6d093d
-%% Subset of standartized exit codes from sysexits.h, see
Peter Lemenkov 6d093d
-%% https://github.com/rabbitmq/rabbitmq-server/issues/396 for discussion.
Peter Lemenkov 6d093d
--define(EX_OK         ,  0).
Peter Lemenkov 6d093d
--define(EX_USAGE      , 64).  % Bad command-line arguments.
Peter Lemenkov 6d093d
--define(EX_DATAERR    , 65).  % Wrong data in command-line arguments.
Peter Lemenkov 6d093d
--define(EX_NOUSER     , 67).  % The user specified does not exist.
Peter Lemenkov 6d093d
--define(EX_UNAVAILABLE, 69).  % Could not connect to the target node.
Peter Lemenkov 6d093d
--define(EX_SOFTWARE   , 70).  % Failed to execute command.
Peter Lemenkov 6d093d
--define(EX_TEMPFAIL   , 75).  % Temporary error (e.g. something has timed out).
Peter Lemenkov 6d093d
--define(EX_CONFIG     , 78).  % Misconfiguration detected
Peter Lemenkov 6d093d
diff --git a/src/rabbit_cli.erl b/src/rabbit_cli.erl
4e8069
index 6b35482..dc490ad 100644
Peter Lemenkov 6d093d
--- a/src/rabbit_cli.erl
Peter Lemenkov 6d093d
+++ b/src/rabbit_cli.erl
4e8069
@@ -58,7 +58,7 @@ ensure_cli_distribution() ->
Peter Lemenkov 6d093d
         {error, Error} ->
Peter Lemenkov 6d093d
             print_error("Failed to initialize erlang distribution: ~p.",
Peter Lemenkov 6d093d
                         [Error]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_TEMPFAIL)
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2)
Peter Lemenkov 6d093d
     end.
Peter Lemenkov 6d093d
 
Peter Lemenkov 6d093d
 %%----------------------------------------------------------------------------
4e8069
@@ -84,10 +84,10 @@ main(ParseFun, DoFun, UsageMod) ->
Peter Lemenkov 6d093d
     %% thrown errors into normal return values
Peter Lemenkov 6d093d
     case catch DoFun(Command, Node, Args, Opts) of
Peter Lemenkov 6d093d
         ok ->
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_OK);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(0);
Peter Lemenkov 6d093d
         {ok, Result} ->
Peter Lemenkov 6d093d
             rabbit_control_misc:print_cmd_result(Command, Result),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_OK);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(0);
Peter Lemenkov 6d093d
         {'EXIT', {function_clause, [{?MODULE, action, _}    | _]}} -> %% < R15
Peter Lemenkov 6d093d
             PrintInvalidCommandError(),
Peter Lemenkov 6d093d
             usage(UsageMod);
4e8069
@@ -97,51 +97,51 @@ main(ParseFun, DoFun, UsageMod) ->
Peter Lemenkov 6d093d
         {error, {missing_dependencies, Missing, Blame}} ->
Peter Lemenkov 6d093d
             print_error("dependent plugins ~p not found; used by ~p.",
Peter Lemenkov 6d093d
                         [Missing, Blame]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_CONFIG);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         {'EXIT', {badarg, _}} ->
Peter Lemenkov 6d093d
             print_error("invalid parameter: ~p", [Args]),
Peter Lemenkov 6d093d
-            usage(UsageMod, ?EX_DATAERR);
Peter Lemenkov 6d093d
+            usage(UsageMod, 2);
Peter Lemenkov 6d093d
         {error, {Problem, Reason}} when is_atom(Problem), is_binary(Reason) ->
Peter Lemenkov 6d093d
             %% We handle this common case specially to avoid ~p since
Peter Lemenkov 6d093d
             %% that has i18n issues
Peter Lemenkov 6d093d
             print_error("~s: ~s", [Problem, Reason]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_SOFTWARE);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         {error, Reason} ->
Peter Lemenkov 6d093d
             print_error("~p", [Reason]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_SOFTWARE);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         {error_string, Reason} ->
Peter Lemenkov 6d093d
             print_error("~s", [Reason]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_SOFTWARE);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         {badrpc, {'EXIT', Reason}} ->
Peter Lemenkov 6d093d
             print_error("~p", [Reason]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_SOFTWARE);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         {badrpc, Reason} ->
Peter Lemenkov 6d093d
             case Reason of
Peter Lemenkov 6d093d
                 timeout ->
Peter Lemenkov 6d093d
                     print_error("operation ~w on node ~w timed out", [Command, Node]),
Peter Lemenkov 6d093d
-                    rabbit_misc:quit(?EX_TEMPFAIL);
Peter Lemenkov 6d093d
+                    rabbit_misc:quit(2);
Peter Lemenkov 6d093d
                 _ ->
Peter Lemenkov 6d093d
                     print_error("unable to connect to node ~w: ~w", [Node, Reason]),
Peter Lemenkov 6d093d
                     print_badrpc_diagnostics([Node]),
Peter Lemenkov 6d093d
                     case Command of
Peter Lemenkov 6d093d
-                        stop -> rabbit_misc:quit(?EX_OK);
Peter Lemenkov 6d093d
-                        _    -> rabbit_misc:quit(?EX_UNAVAILABLE)
Peter Lemenkov 6d093d
+                        stop -> rabbit_misc:quit(0);
Peter Lemenkov 6d093d
+                        _    -> rabbit_misc:quit(2)
Peter Lemenkov 6d093d
                     end
Peter Lemenkov 6d093d
             end;
Peter Lemenkov 6d093d
         {badrpc_multi, Reason, Nodes} ->
Peter Lemenkov 6d093d
             print_error("unable to connect to nodes ~p: ~w", [Nodes, Reason]),
Peter Lemenkov 6d093d
             print_badrpc_diagnostics(Nodes),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_UNAVAILABLE);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         function_clause ->
Peter Lemenkov 6d093d
             print_error("operation ~w used with invalid parameter: ~p",
Peter Lemenkov 6d093d
                         [Command, Args]),
Peter Lemenkov 6d093d
             usage(UsageMod);
Peter Lemenkov 6d093d
         {refused, Username, _, _} ->
Peter Lemenkov 6d093d
             print_error("failed to authenticate user \"~s\"", [Username]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_NOUSER);
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2);
Peter Lemenkov 6d093d
         Other ->
Peter Lemenkov 6d093d
             print_error("~p", [Other]),
Peter Lemenkov 6d093d
-            rabbit_misc:quit(?EX_SOFTWARE)
Peter Lemenkov 6d093d
+            rabbit_misc:quit(2)
Peter Lemenkov 6d093d
     end.
Peter Lemenkov 6d093d
 
Peter Lemenkov 6d093d
 start_distribution_anon(0, LastError) ->
4e8069
@@ -172,7 +172,7 @@ name_type() ->
Peter Lemenkov 6d093d
     end.
Peter Lemenkov 6d093d
 
Peter Lemenkov 6d093d
 usage(Mod) ->
Peter Lemenkov 6d093d
-    usage(Mod, ?EX_USAGE).
Peter Lemenkov 6d093d
+    usage(Mod, 1).
Peter Lemenkov 6d093d
 
Peter Lemenkov 6d093d
 usage(Mod, ExitCode) ->
Peter Lemenkov 6d093d
     io:format("~s", [Mod:usage()]),