From 5c9cd96b49d77160d7be3a2a9f0810fa3d91d88d Mon Sep 17 00:00:00 2001 From: David Wragg Date: Fri, 14 Aug 2009 13:42:08 +0100 Subject: Use /bin/sh for rabbitmq-script-wrapper, not /bin/bash There's nothing in it that is an obvious dependency on bash, and some testing with dash as /bin/sh doesn't reveal any problems. Neither does checkbashisms. --- packaging/common/rabbitmq-script-wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/common/rabbitmq-script-wrapper b/packaging/common/rabbitmq-script-wrapper index 296a77d1..fbb300ac 100644 --- a/packaging/common/rabbitmq-script-wrapper +++ b/packaging/common/rabbitmq-script-wrapper @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Escape spaces and quotes, because shell is revolting. for arg in "$@" ; do # Escape quotes in parameters, so that they're passed through cleanly. -- cgit v1.2.1 From ebbdaef86a10a41c0bc7f76690d19c48d219d296 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 1 Sep 2009 15:40:12 +0100 Subject: improved dialysis --- .hgignore | 2 ++ Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.hgignore b/.hgignore index 839f1601..74c90eb0 100644 --- a/.hgignore +++ b/.hgignore @@ -11,6 +11,8 @@ syntax: regexp ^include/rabbit_framing.hrl$ ^src/rabbit_framing.erl$ ^rabbit.plt$ +^basic.plt$ +^\.last_valid_dialysis$ ^ebin/rabbit.app$ ^ebin/rabbit.rel$ ^ebin/rabbit.boot$ diff --git a/Makefile b/Makefile index f0702756..c065ef9c 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ ifndef TMPDIR TMPDIR := /tmp endif +ifndef ERL_HOME +ERL_HOME := /usr/local/lib/erlang +endif + RABBITMQ_NODENAME=rabbit RABBITMQ_SERVER_START_ARGS= RABBITMQ_MNESIA_DIR=$(TMPDIR)/rabbitmq-$(RABBITMQ_NODENAME)-mnesia @@ -18,6 +22,9 @@ MANPAGES=$(patsubst %.pod, %.gz, $(wildcard docs/*.[0-9].pod)) PYTHON=python +BASIC_PLT=basic.plt +PLT=rabbit.plt + ifndef USE_SPECS # our type specs rely on features / bug fixes in dialyzer that are # only available in R13B upwards (R13B is eshell 5.7.1) @@ -60,14 +67,54 @@ $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.rel $(TARGETS) erl -noshell -eval 'systools:make_script("ebin/rabbit", [{path, ["ebin"]}]), halt().' -dialyze: $(BEAM_TARGETS) - dialyzer -c $? +dialyze: $(BASIC_PLT) $(PLT) .last_valid_dialysis + +create_plt: $(BASIC_PLT) $(PLT) + +$(PLT): $(BEAM_TARGETS) + if [ -f $@ -a $(BASIC_PLT) -ot $@ ]; then \ + DIALYZER_INPUT_FILES="$?"; \ + else \ + cp $(BASIC_PLT) $@ && \ + DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \ + fi; \ + DIALYZER_OUTPUT=$$(dialyzer --plt $@ --add_to_plt -c $$DIALYZER_INPUT_FILES); \ + echo "$$DIALYZER_OUTPUT"; \ + echo "$$DIALYZER_OUTPUT" | grep "done (passed successfully)" + +.last_valid_dialysis: $(BEAM_TARGETS) + DIALYZER_OUTPUT=$$(erl -noinput -eval \ + "{ok, Files} = regexp:split(\"$?\", \" \"), \ + lists:foreach( \ + fun(Warning) -> io:format(\"~s\", [dialyzer:format_warning(Warning)]) end, \ + dialyzer:run([{init_plt, \"$(PLT)\"}, {files, Files}])), \ + halt()."); \ + if [ ! "$$DIALYZER_OUTPUT" ]; then \ + echo "Ok, dialyzer returned no warnings." && \ + touch .last_valid_dialysis; \ + else \ + echo "dialyzer returned the following warnings:" && \ + echo "$$DIALYZER_OUTPUT" && \ + false; \ + fi + +$(BASIC_PLT): $(ERL_HOME) + -dialyzer --plt $@ --build_plt -r \ + $(shell ls -d $(ERL_HOME)/lib/stdlib-*/ebin \ + $(ERL_HOME)/lib/kernel-*/ebin \ + $(ERL_HOME)/lib/mnesia-*/ebin \ + $(ERL_HOME)/lib/os_mon-*/ebin \ + $(ERL_HOME)/lib/ssl-*/ebin \ + $(ERL_HOME)/lib/eunit-*/ebin \ + $(ERL_HOME)/lib/tools-*/ebin \ + $(ERL_HOME)/lib/sasl-*/ebin) clean: rm -f $(EBIN_DIR)/*.beam rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc rm -f docs/*.[0-9].gz + rm -f $(PLT) .last_valid_dialysis cleandb: rm -rf $(RABBITMQ_MNESIA_DIR)/* -- cgit v1.2.1 From e35b2a8ee0bcd96da45cbc0d6c66c5903d5cece8 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 1 Sep 2009 16:14:42 +0100 Subject: nicer enumeration of otp applications rabbit depends on --- Makefile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c065ef9c..db8854ce 100644 --- a/Makefile +++ b/Makefile @@ -100,14 +100,7 @@ $(PLT): $(BEAM_TARGETS) $(BASIC_PLT): $(ERL_HOME) -dialyzer --plt $@ --build_plt -r \ - $(shell ls -d $(ERL_HOME)/lib/stdlib-*/ebin \ - $(ERL_HOME)/lib/kernel-*/ebin \ - $(ERL_HOME)/lib/mnesia-*/ebin \ - $(ERL_HOME)/lib/os_mon-*/ebin \ - $(ERL_HOME)/lib/ssl-*/ebin \ - $(ERL_HOME)/lib/eunit-*/ebin \ - $(ERL_HOME)/lib/tools-*/ebin \ - $(ERL_HOME)/lib/sasl-*/ebin) + $(shell bash -c "ls -d $(ERL_HOME)/lib/{stdlib,kernel,mnesia,os_mon,ssl,eunit,tools,sasl}-*/ebin") clean: rm -f $(EBIN_DIR)/*.beam -- cgit v1.2.1 From f43ab8b2fa61d4e1fd98fd0a57b81a119ec9f65a Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 1 Sep 2009 16:43:39 +0100 Subject: checking if required applications exist in specified ERL_HOME --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index db8854ce..4032d6b2 100644 --- a/Makefile +++ b/Makefile @@ -99,8 +99,13 @@ $(PLT): $(BEAM_TARGETS) fi $(BASIC_PLT): $(ERL_HOME) - -dialyzer --plt $@ --build_plt -r \ - $(shell bash -c "ls -d $(ERL_HOME)/lib/{stdlib,kernel,mnesia,os_mon,ssl,eunit,tools,sasl}-*/ebin") + OTP_APPS='$(shell bash -c "ls -d $(ERL_HOME)/lib/{stdlib,kernel,mnesia,os_mon,ssl,eunit,tools,sasl}-*/ebin")'; \ + if [ ! "$$OTP_APPS" ]; then \ + echo "Did not find required OTP applications. Check ERL_HOME variable." && \ + false; \ + else \ + dialyzer --plt $@ --build_plt -r $$OTP_APPS || true; \ + fi clean: rm -f $(EBIN_DIR)/*.beam -- cgit v1.2.1 From f6768066d5c604ced90def93d78541f0eb25a492 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 2 Sep 2009 16:15:01 +0100 Subject: basic.plt created via erlang shell; fixing create_plt make target name --- Makefile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4032d6b2..1174f1a9 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,6 @@ ifndef TMPDIR TMPDIR := /tmp endif -ifndef ERL_HOME -ERL_HOME := /usr/local/lib/erlang -endif - RABBITMQ_NODENAME=rabbit RABBITMQ_SERVER_START_ARGS= RABBITMQ_MNESIA_DIR=$(TMPDIR)/rabbitmq-$(RABBITMQ_NODENAME)-mnesia @@ -69,7 +65,7 @@ $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN dialyze: $(BASIC_PLT) $(PLT) .last_valid_dialysis -create_plt: $(BASIC_PLT) $(PLT) +create-plt: $(BASIC_PLT) $(PLT) $(PLT): $(BEAM_TARGETS) if [ -f $@ -a $(BASIC_PLT) -ot $@ ]; then \ @@ -98,14 +94,16 @@ $(PLT): $(BEAM_TARGETS) false; \ fi -$(BASIC_PLT): $(ERL_HOME) - OTP_APPS='$(shell bash -c "ls -d $(ERL_HOME)/lib/{stdlib,kernel,mnesia,os_mon,ssl,eunit,tools,sasl}-*/ebin")'; \ - if [ ! "$$OTP_APPS" ]; then \ - echo "Did not find required OTP applications. Check ERL_HOME variable." && \ - false; \ - else \ - dialyzer --plt $@ --build_plt -r $$OTP_APPS || true; \ - fi +$(BASIC_PLT): + erl -noinput -eval \ + "OptsRecord = dialyzer_options:build([ \ + {analysis_type, plt_build}, \ + {init_plt, \"$(BASIC_PLT)\"}, \ + {files_rec, lists:map( \ + fun(App) -> code:lib_dir(App) ++ \"/ebin\" end, \ + [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl])}]), \ + dialyzer_cl:start(OptsRecord), \ + halt()." clean: rm -f $(EBIN_DIR)/*.beam -- cgit v1.2.1 From b45448edcab38ae2c9a3ca52c450106a1ecf2634 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 2 Sep 2009 20:01:38 +0100 Subject: moving dialyzer stuff to src/rabbit_dialyzer.erl --- Makefile | 37 ++++++-------------- src/rabbit_dialyzer.erl | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 src/rabbit_dialyzer.erl diff --git a/Makefile b/Makefile index 1174f1a9..dab3ba94 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,8 @@ AMQP_SPEC_JSON_PATH=$(AMQP_CODEGEN_DIR)/amqp-0.8.json ERL_CALL=erl_call -sname $(RABBITMQ_NODENAME) -e +ERL_RABBIT_DIALYZER=erl -noinput -eval "code:load_abs(\"$(EBIN_DIR)/rabbit_dialyzer\")." + all: $(TARGETS) $(EBIN_DIR)/rabbit.app: $(EBIN_DIR)/rabbit_app.in $(BEAM_TARGETS) generate_app @@ -72,38 +74,21 @@ $(PLT): $(BEAM_TARGETS) DIALYZER_INPUT_FILES="$?"; \ else \ cp $(BASIC_PLT) $@ && \ + rm -f .last_valid_dialysis && \ DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \ fi; \ - DIALYZER_OUTPUT=$$(dialyzer --plt $@ --add_to_plt -c $$DIALYZER_INPUT_FILES); \ - echo "$$DIALYZER_OUTPUT"; \ - echo "$$DIALYZER_OUTPUT" | grep "done (passed successfully)" + $(ERL_RABBIT_DIALYZER) -eval \ + "rabbit_dialyzer:update_plt(\"$@\", \"$$DIALYZER_INPUT_FILES\"), halt()." .last_valid_dialysis: $(BEAM_TARGETS) - DIALYZER_OUTPUT=$$(erl -noinput -eval \ - "{ok, Files} = regexp:split(\"$?\", \" \"), \ - lists:foreach( \ - fun(Warning) -> io:format(\"~s\", [dialyzer:format_warning(Warning)]) end, \ - dialyzer:run([{init_plt, \"$(PLT)\"}, {files, Files}])), \ - halt()."); \ - if [ ! "$$DIALYZER_OUTPUT" ]; then \ - echo "Ok, dialyzer returned no warnings." && \ - touch .last_valid_dialysis; \ - else \ - echo "dialyzer returned the following warnings:" && \ - echo "$$DIALYZER_OUTPUT" && \ - false; \ - fi + $(ERL_RABBIT_DIALYZER) -eval \ + "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$?\"), halt()." && \ + touch $@ $(BASIC_PLT): - erl -noinput -eval \ - "OptsRecord = dialyzer_options:build([ \ - {analysis_type, plt_build}, \ - {init_plt, \"$(BASIC_PLT)\"}, \ - {files_rec, lists:map( \ - fun(App) -> code:lib_dir(App) ++ \"/ebin\" end, \ - [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl])}]), \ - dialyzer_cl:start(OptsRecord), \ - halt()." + $(MAKE) $(EBIN_DIR)/rabbit_dialyzer.beam + $(ERL_RABBIT_DIALYZER) -eval \ + "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()." clean: rm -f $(EBIN_DIR)/*.beam diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl new file mode 100644 index 00000000..cc3aaf12 --- /dev/null +++ b/src/rabbit_dialyzer.erl @@ -0,0 +1,93 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developers of the Original Code are LShift Ltd, +%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. +%% +%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, +%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd +%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial +%% Technologies LLC, and Rabbit Technologies Ltd. +%% +%% Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift +%% Ltd. Portions created by Cohesive Financial Technologies LLC are +%% Copyright (C) 2007-2009 Cohesive Financial Technologies +%% LLC. Portions created by Rabbit Technologies Ltd are Copyright +%% (C) 2007-2009 Rabbit Technologies Ltd. +%% +%% All Rights Reserved. +%% +%% Contributor(s): ______________________________________. +%% + +-module(rabbit_dialyzer). +-include("rabbit.hrl"). + +-export([create_basic_plt/1, update_plt/2, dialyze_files/2]). + +%%---------------------------------------------------------------------------- + +-ifdef(use_specs). + +-spec(create_basic_plt/1 :: (string()) -> 'ok'). +-spec(update_plt/2 :: (string(), string()) -> 'ok'). +-spec(dialyze_files/2 :: (string(), string()) -> 'ok'). + +-endif. + +%%---------------------------------------------------------------------------- + +create_basic_plt(BasicPltPath) -> + OptsRecord = dialyzer_options:build([ + {analysis_type, plt_build}, + {init_plt, BasicPltPath}, + {files_rec, otp_apps_dependencies_paths()}]), + dialyzer_cl:start(OptsRecord), + ok. + +update_plt(PltPath, ModifiedFiles) -> + {ok, Files} = regexp:split(ModifiedFiles, " "), + DialyzerWarnings = dialyzer:run([ + {analysis_type, plt_add}, + {init_plt, PltPath}, + {files, Files}]), + print_warnings(DialyzerWarnings), + ok. + +dialyze_files(PltPath, ModifiedFiles) -> + {ok, Files} = regexp:split(ModifiedFiles, " "), + DialyzerWarnings = dialyzer:run([ + {init_plt, PltPath}, + {files, Files}]), + case DialyzerWarnings of + [] -> + io:format("Ok, dialyzer returned no warnings.~n", []), + ok; + _ -> + io:format("~nFAILED! dialyzer returned the following warnings:~n", []), + print_warnings(DialyzerWarnings), + erlang:error({dialyzer_warnings, DialyzerWarnings}) + end. + +print_warnings(DialyzerWarnings) -> + lists:foreach( + fun + (Warning) -> io:format("~s", [dialyzer:format_warning(Warning)]) + end, + DialyzerWarnings), + io:format("~n", []), + ok. + +otp_apps_dependencies_paths() -> + lists:map( + fun(App) -> code:lib_dir(App, ebin) end, + [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]). -- cgit v1.2.1 From 206f26e2ba9d779ad47009e173c4a93aba9558e1 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 2 Sep 2009 20:53:08 +0100 Subject: nicer rabbit_dialyzer:otp_apps_dependencies_paths --- src/rabbit_dialyzer.erl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl index cc3aaf12..5664f1da 100644 --- a/src/rabbit_dialyzer.erl +++ b/src/rabbit_dialyzer.erl @@ -88,6 +88,5 @@ print_warnings(DialyzerWarnings) -> ok. otp_apps_dependencies_paths() -> - lists:map( - fun(App) -> code:lib_dir(App, ebin) end, - [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]). + [code:lib_dir(App, ebin) || + App <- [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]]. -- cgit v1.2.1 From 9dc88ef9363f55f11f5ada3b9a4918b2c36cabaa Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 7 Sep 2009 17:02:45 +0100 Subject: don't attempt rollbacks on non-tx channels --- src/rabbit_channel.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 16b7c938..1c08ad6d 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -126,7 +126,7 @@ handle_cast({method, Method, Content}, State) -> {stop, normal, State#ch{state = terminating}} catch exit:{amqp, Error, Explanation, none} -> - ok = notify_queues(internal_rollback(State)), + ok = rollback_and_notify(State), Reason = {amqp, Error, Explanation, rabbit_misc:method_record_type(Method)}, State#ch.reader_pid ! {channel_exit, State#ch.channel, Reason}, @@ -175,7 +175,7 @@ terminate(_Reason, #ch{writer_pid = WriterPid, limiter_pid = LimiterPid, terminate(Reason, State = #ch{writer_pid = WriterPid, limiter_pid = LimiterPid}) -> - Res = notify_queues(internal_rollback(State)), + Res = rollback_and_notify(State), case Reason of normal -> ok = Res; _ -> ok @@ -297,7 +297,7 @@ handle_method(_Method, _, #ch{state = starting}) -> rabbit_misc:protocol_error(channel_error, "expected 'channel.open'", []); handle_method(#'channel.close'{}, _, State = #ch{writer_pid = WriterPid}) -> - ok = notify_queues(internal_rollback(State)), + ok = rollback_and_notify(State), ok = rabbit_writer:send_command(WriterPid, #'channel.close_ok'{}), stop; @@ -872,6 +872,11 @@ internal_rollback(State = #ch{transaction_id = TxnKey, internal_error, "rollback failed: ~w", [Errors]) end. +rollback_and_notify(State = #ch{transaction_id = none}) -> + notify_queues(internal_rollback(State)); +rollback_and_notify(State) -> + notify_queues(State). + fold_per_queue(F, Acc0, UAQ) -> D = lists:foldl( fun ({_DTag, _CTag, -- cgit v1.2.1 From f363874972e9c7908d58daaf9deb426414107a5c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 7 Sep 2009 17:12:53 +0100 Subject: oops --- src/rabbit_channel.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 1c08ad6d..1285064f 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -873,9 +873,9 @@ internal_rollback(State = #ch{transaction_id = TxnKey, end. rollback_and_notify(State = #ch{transaction_id = none}) -> - notify_queues(internal_rollback(State)); + notify_queues(State); rollback_and_notify(State) -> - notify_queues(State). + notify_queues(internal_rollback(State)). fold_per_queue(F, Acc0, UAQ) -> D = lists:foldl( -- cgit v1.2.1 From cf6bad454391addb8cb70aa4e71e9f9928dbd4db Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 9 Sep 2009 13:48:07 +0100 Subject: fixing compatibility with latest dialyzer --- src/rabbit_dialyzer.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl index 5664f1da..4d78adbe 100644 --- a/src/rabbit_dialyzer.erl +++ b/src/rabbit_dialyzer.erl @@ -49,7 +49,7 @@ create_basic_plt(BasicPltPath) -> OptsRecord = dialyzer_options:build([ {analysis_type, plt_build}, - {init_plt, BasicPltPath}, + {output_plt, BasicPltPath}, {files_rec, otp_apps_dependencies_paths()}]), dialyzer_cl:start(OptsRecord), ok. @@ -59,6 +59,7 @@ update_plt(PltPath, ModifiedFiles) -> DialyzerWarnings = dialyzer:run([ {analysis_type, plt_add}, {init_plt, PltPath}, + {output_plt, PltPath}, {files, Files}]), print_warnings(DialyzerWarnings), ok. -- cgit v1.2.1 From 5ed84ee6fa15d9749b610a0d0bfc4ae3b118da6a Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 9 Sep 2009 15:12:29 +0100 Subject: fixing dependencies in dialyzer-related make targets --- Makefile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index dab3ba94..360ad1fc 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ SOURCE_DIR=src EBIN_DIR=ebin INCLUDE_DIR=include SOURCES=$(wildcard $(SOURCE_DIR)/*.erl) -BEAM_TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES)) +BEAM_TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam, $(SOURCES)) TARGETS=$(EBIN_DIR)/rabbit.app $(BEAM_TARGETS) WEB_URL=http://stage.rabbitmq.com/ MANPAGES=$(patsubst %.pod, %.gz, $(wildcard docs/*.[0-9].pod)) @@ -65,24 +65,23 @@ $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.rel $(TARGETS) erl -noshell -eval 'systools:make_script("ebin/rabbit", [{path, ["ebin"]}]), halt().' -dialyze: $(BASIC_PLT) $(PLT) .last_valid_dialysis +dialyze: .last_valid_dialysis -create-plt: $(BASIC_PLT) $(PLT) +create-plt: $(PLT) -$(PLT): $(BEAM_TARGETS) - if [ -f $@ -a $(BASIC_PLT) -ot $@ ]; then \ - DIALYZER_INPUT_FILES="$?"; \ +$(PLT): $(BEAM_TARGETS) $(BASIC_PLT) + test -f $@ -a $(BASIC_PLT) -ot $@ || cp $(BASIC_PLT) $@ + $(ERL_RABBIT_DIALYZER) -eval \ + "rabbit_dialyzer:update_plt(\"$@\", \"$(BEAM_TARGETS)\"), halt()." + +.last_valid_dialysis: $(BEAM_TARGETS) $(PLT) + if [ $(PLT) -ot $@ ]; then \ + DIALYZER_INPUT_FILES="$(filter %.beam, $?)"; \ else \ - cp $(BASIC_PLT) $@ && \ - rm -f .last_valid_dialysis && \ DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \ fi; \ $(ERL_RABBIT_DIALYZER) -eval \ - "rabbit_dialyzer:update_plt(\"$@\", \"$$DIALYZER_INPUT_FILES\"), halt()." - -.last_valid_dialysis: $(BEAM_TARGETS) - $(ERL_RABBIT_DIALYZER) -eval \ - "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$?\"), halt()." && \ + "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$$DIALYZER_INPUT_FILES\"), halt()." && \ touch $@ $(BASIC_PLT): -- cgit v1.2.1 From 3313f61b68c633ea3a4c042facd450875d1a3b1e Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Mon, 14 Sep 2009 12:48:49 +0100 Subject: replacing ERL_DIALYZER with ERL_EBIN in makefile --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 360ad1fc..3007baa6 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ AMQP_SPEC_JSON_PATH=$(AMQP_CODEGEN_DIR)/amqp-0.8.json ERL_CALL=erl_call -sname $(RABBITMQ_NODENAME) -e -ERL_RABBIT_DIALYZER=erl -noinput -eval "code:load_abs(\"$(EBIN_DIR)/rabbit_dialyzer\")." +ERL_EBIN=erl -noinput -pa $(EBIN_DIR) all: $(TARGETS) @@ -71,7 +71,7 @@ create-plt: $(PLT) $(PLT): $(BEAM_TARGETS) $(BASIC_PLT) test -f $@ -a $(BASIC_PLT) -ot $@ || cp $(BASIC_PLT) $@ - $(ERL_RABBIT_DIALYZER) -eval \ + $(ERL_EBIN) -eval \ "rabbit_dialyzer:update_plt(\"$@\", \"$(BEAM_TARGETS)\"), halt()." .last_valid_dialysis: $(BEAM_TARGETS) $(PLT) @@ -80,13 +80,13 @@ $(PLT): $(BEAM_TARGETS) $(BASIC_PLT) else \ DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \ fi; \ - $(ERL_RABBIT_DIALYZER) -eval \ + $(ERL_EBIN) -eval \ "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$$DIALYZER_INPUT_FILES\"), halt()." && \ touch $@ $(BASIC_PLT): - $(MAKE) $(EBIN_DIR)/rabbit_dialyzer.beam - $(ERL_RABBIT_DIALYZER) -eval \ + $(MAKE) all + $(ERL_EBIN) -eval \ "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()." clean: -- cgit v1.2.1 From ac7b3b581168a7fb7f37e9fe01a4bb7824e9480f Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Mon, 14 Sep 2009 13:51:05 +0100 Subject: displaying (none) for '$none' atoms in rabbit_control; changing value for undefined usernames to '$none', not to confuse with none username --- src/rabbit_control.erl | 2 ++ src/rabbit_reader.erl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index cf20520e..3258a04b 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -330,6 +330,8 @@ format_info_item(Items, Key) -> case Info of {_, #resource{name = Name}} -> escape(Name); + {_, '$none'} -> + "(none)"; _ when Key =:= address; Key =:= peer_address andalso is_tuple(Value) -> inet_parse:ntoa(Value); _ when is_pid(Value) -> diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 69dbc008..435919b6 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -703,7 +703,7 @@ i(channels, #v1{}) -> i(user, #v1{connection = #connection{user = #user{username = Username}}}) -> Username; i(user, #v1{connection = #connection{user = none}}) -> - none; + '$none'; i(vhost, #v1{connection = #connection{vhost = VHost}}) -> VHost; i(timeout, #v1{connection = #connection{timeout_sec = Timeout}}) -> -- cgit v1.2.1 From 6e4f32ff969b274cb64a5ef0a2fd8aeca5f7310e Mon Sep 17 00:00:00 2001 From: Marek Majkowski Date: Mon, 14 Sep 2009 15:29:27 +0100 Subject: fixed R12 incompatibility in gen_server2 --- src/gen_server2.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gen_server2.erl b/src/gen_server2.erl index 36fb4fa8..47ae545b 100644 --- a/src/gen_server2.erl +++ b/src/gen_server2.erl @@ -437,7 +437,10 @@ unregister_name({local,Name}) -> unregister_name({global,Name}) -> _ = global:unregister_name(Name); unregister_name(Pid) when is_pid(Pid) -> - Pid. + Pid; +% Under R12 let's just ignore it, as we have a single term as Name. +% On R13 it will never get here, as we get tuple with 'local/global' atom. +unregister_name(Name) -> ok. extend_backoff(undefined) -> undefined; -- cgit v1.2.1 From 8f113ab81b931589b42383ff74232f9a158f249c Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Mon, 14 Sep 2009 16:10:21 +0100 Subject: using '' instead of '$none' for undefined username, printing nothing for undefined username; adding state to the default list for list_connections in rabbit_control --- src/rabbit_control.erl | 6 +++--- src/rabbit_reader.erl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 3258a04b..36509358 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -271,7 +271,7 @@ action(list_bindings, Node, Args, Inform) -> action(list_connections, Node, Args, Inform) -> Inform("Listing connections", []), ArgAtoms = list_replace(node, pid, - default_if_empty(Args, [user, peer_address, peer_port])), + default_if_empty(Args, [user, peer_address, peer_port, state])), display_info_list(rpc_call(Node, rabbit_networking, connection_info_all, [ArgAtoms]), ArgAtoms); @@ -330,14 +330,14 @@ format_info_item(Items, Key) -> case Info of {_, #resource{name = Name}} -> escape(Name); - {_, '$none'} -> - "(none)"; _ when Key =:= address; Key =:= peer_address andalso is_tuple(Value) -> inet_parse:ntoa(Value); _ when is_pid(Value) -> atom_to_list(node(Value)); _ when is_binary(Value) -> escape(Value); + _ when is_atom(Value) -> + io_lib:format("~s", [Value]); _ -> io_lib:format("~w", [Value]) end. diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 435919b6..690e6f0e 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -703,7 +703,7 @@ i(channels, #v1{}) -> i(user, #v1{connection = #connection{user = #user{username = Username}}}) -> Username; i(user, #v1{connection = #connection{user = none}}) -> - '$none'; + ''; i(vhost, #v1{connection = #connection{vhost = VHost}}) -> VHost; i(timeout, #v1{connection = #connection{timeout_sec = Timeout}}) -> -- cgit v1.2.1 From e8c21f21c67d4843894400b4f22e3e89e12eb3bf Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Mon, 14 Sep 2009 18:06:42 +0100 Subject: updating comment on list_connections in rabbit_control --- src/rabbit_control.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 36509358..5f599ccf 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -164,7 +164,7 @@ exchange name, routing key, queue name and arguments, in that order. must be a member of the list [node, address, port, peer_address, peer_port, state, channels, user, vhost, timeout, frame_max, recv_oct, recv_cnt, send_oct, send_cnt, send_pend]. The default is to display -user, peer_address and peer_port. +user, peer_address, peer_port and state. "), halt(1). @@ -270,8 +270,9 @@ action(list_bindings, Node, Args, Inform) -> action(list_connections, Node, Args, Inform) -> Inform("Listing connections", []), - ArgAtoms = list_replace(node, pid, - default_if_empty(Args, [user, peer_address, peer_port, state])), + ArgAtoms = list_replace(node, pid, + default_if_empty(Args, [user, peer_address, + peer_port, state])), display_info_list(rpc_call(Node, rabbit_networking, connection_info_all, [ArgAtoms]), ArgAtoms); -- cgit v1.2.1 From 8410f62358678c2ff6453ea852b0e5f51bcb090d Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Mon, 14 Sep 2009 19:15:27 +0100 Subject: updating rabbitmqctl.1.pod --- docs/rabbitmqctl.1.pod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rabbitmqctl.1.pod b/docs/rabbitmqctl.1.pod index 6d4aadeb..c43ed2ea 100644 --- a/docs/rabbitmqctl.1.pod +++ b/docs/rabbitmqctl.1.pod @@ -287,7 +287,7 @@ separated by tab characters. List queue information by virtual host. Each line printed describes an connection, with the requested I values separated by tab characters. If no Is are specified then -I, I and I are assumed. +I, I, I and I are assumed. =back -- cgit v1.2.1 From ead039b155010045861229aa27424d6c3d7c7197 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 15 Sep 2009 10:05:51 +0100 Subject: fixed unused var warning --- src/gen_server2.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gen_server2.erl b/src/gen_server2.erl index 47ae545b..a2d9350c 100644 --- a/src/gen_server2.erl +++ b/src/gen_server2.erl @@ -440,7 +440,7 @@ unregister_name(Pid) when is_pid(Pid) -> Pid; % Under R12 let's just ignore it, as we have a single term as Name. % On R13 it will never get here, as we get tuple with 'local/global' atom. -unregister_name(Name) -> ok. +unregister_name(_Name) -> ok. extend_backoff(undefined) -> undefined; -- cgit v1.2.1 From f3118f859589ddbe741e04d9ad994cd7b36fa623 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 15 Sep 2009 13:18:59 +0100 Subject: fixing basic.plt dependencies --- Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3007baa6..609b645e 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ dialyze: .last_valid_dialysis create-plt: $(PLT) $(PLT): $(BEAM_TARGETS) $(BASIC_PLT) - test -f $@ -a $(BASIC_PLT) -ot $@ || cp $(BASIC_PLT) $@ + test -f $@ || cp $(BASIC_PLT) $@ $(ERL_EBIN) -eval \ "rabbit_dialyzer:update_plt(\"$@\", \"$(BEAM_TARGETS)\"), halt()." @@ -84,10 +84,13 @@ $(PLT): $(BEAM_TARGETS) $(BASIC_PLT) "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$$DIALYZER_INPUT_FILES\"), halt()." && \ touch $@ -$(BASIC_PLT): - $(MAKE) all - $(ERL_EBIN) -eval \ - "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()." +$(BASIC_PLT): $(BEAM_TARGETS) + if [ -f $@ ]; then \ + touch $@; \ + else \ + $(ERL_EBIN) -eval \ + "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()."; \ + fi clean: rm -f $(EBIN_DIR)/*.beam -- cgit v1.2.1 From 547ccadbe16baa714f8fdaa45cb0dcd21db93954 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 16 Sep 2009 15:55:42 +0100 Subject: changing uses of lists:key* functions to proplists:*, where the key is of type atom(); changing parse_status to is_rabbit_running in rabbit_multi --- src/rabbit_control.erl | 6 +++--- src/rabbit_misc.erl | 6 +++--- src/rabbit_multi.erl | 39 +++++++++++++++++++++------------------ src/rabbit_plugin_activator.erl | 2 +- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index cf20520e..e05b1886 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -314,7 +314,7 @@ default_if_empty(List, Default) when is_list(List) -> end. display_info_list(Results, InfoItemKeys) when is_list(Results) -> - lists:foreach(fun (Result) -> display_row([format_info_item(Result, X) || + lists:foreach(fun (Result) -> display_row([format_info_item(X, Result) || X <- InfoItemKeys]) end, Results), ok; @@ -325,8 +325,8 @@ display_row(Row) -> io:fwrite(lists:flatten(rabbit_misc:intersperse("\t", Row))), io:nl(). -format_info_item(Items, Key) -> - {value, Info = {Key, Value}} = lists:keysearch(Key, 1, Items), +format_info_item(Key, Items) -> + Info = {Key, Value} = proplists:lookup(Key, Items), case Info of {_, #resource{name = Name}} -> escape(Name); diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 95a274e3..814e3c31 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -189,9 +189,9 @@ r(VHostPath, Kind) when is_binary(VHostPath) -> r_arg(#resource{virtual_host = VHostPath}, Kind, Table, Key) -> r_arg(VHostPath, Kind, Table, Key); r_arg(VHostPath, Kind, Table, Key) -> - case lists:keysearch(Key, 1, Table) of - {value, {_, longstr, NameBin}} -> r(VHostPath, Kind, NameBin); - false -> undefined + case proplists:lookup(Key, Table) of + {_, longstr, NameBin} -> r(VHostPath, Kind, NameBin); + none -> undefined end. rs(#resource{virtual_host = VHostPath, kind = Kind, name = Name}) -> diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index d9197535..6fc7bd67 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -114,12 +114,13 @@ action(status, [], RpcTimeout) -> io:format("Status of all running nodes...~n", []), call_all_nodes( fun({Node, Pid}) -> - Status = rpc:call(Node, rabbit, status, [], RpcTimeout), + RabbitRunning = + case is_rabbit_running(Node, RpcTimeout) of + false -> not_running; + true -> running + end, io:format("Node '~p' with Pid ~p: ~p~n", - [Node, Pid, case parse_status(Status) of - false -> not_running; - true -> running - end]) + [Node, Pid, RabbitRunning]) end); action(stop_all, [], RpcTimeout) -> @@ -197,7 +198,7 @@ start_node(NodeName, NodePort, RpcTimeout) -> wait_for_rabbit_to_start(_ , RpcTimeout, _) when RpcTimeout < 0 -> false; wait_for_rabbit_to_start(Node, RpcTimeout, Port) -> - case parse_status(rpc:call(Node, rabbit, status, [])) of + case is_rabbit_running(Node, RpcTimeout) of true -> true; false -> receive {'EXIT', Port, PosixCode} -> @@ -211,22 +212,24 @@ wait_for_rabbit_to_start(Node, RpcTimeout, Port) -> run_cmd(FullPath) -> erlang:open_port({spawn, FullPath}, [nouse_stdio]). -parse_status({badrpc, _}) -> - false; - -parse_status(Status) -> - case lists:keysearch(running_applications, 1, Status) of - {value, {running_applications, Apps}} -> - lists:keymember(rabbit, 1, Apps); - _ -> - false +is_rabbit_running(Node, RpcTimeout) -> + case rpc:call(Node, rabbit, status, [], RpcTimeout) of + {badrpc, _} -> + false; + Status -> + case proplists:lookup(running_applications, Status) of + {running_applications, Apps} -> + proplists:is_defined(rabbit, Apps); + none -> + false + end end. with_os(Handlers) -> {OsFamily, _} = os:type(), - case lists:keysearch(OsFamily, 1, Handlers) of - {value, {_, Handler}} -> Handler(); - false -> throw({unsupported_os, OsFamily}) + case proplists:lookup(OsFamily, Handlers) of + {_, Handler} -> Handler(); + none -> throw({unsupported_os, OsFamily}) end. script_filename() -> diff --git a/src/rabbit_plugin_activator.erl b/src/rabbit_plugin_activator.erl index 71278bfb..0206f73e 100644 --- a/src/rabbit_plugin_activator.erl +++ b/src/rabbit_plugin_activator.erl @@ -68,7 +68,7 @@ start() -> AppList end, AppVersions = [determine_version(App) || App <- AllApps], - {value, {rabbit, RabbitVersion}} = lists:keysearch(rabbit, 1, AppVersions), + {rabbit, RabbitVersion} = proplists:lookup(rabbit, AppVersions), %% Build the overall release descriptor RDesc = {release, -- cgit v1.2.1 From 1eab9177adbaca05a21d719b791554c4914032f9 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Thu, 17 Sep 2009 12:49:15 +0100 Subject: using #amqp_error{} instead of {amqp, ...} --- include/rabbit.hrl | 7 +++++- include/rabbit_framing_spec.hrl | 2 -- src/rabbit_channel.erl | 9 ++++---- src/rabbit_misc.erl | 25 ++++++++++----------- src/rabbit_reader.erl | 48 +++++++++++++++++++++-------------------- 5 files changed, 49 insertions(+), 42 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index d1a2f3bd..fbe598cc 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -67,6 +67,8 @@ -record(ssl_socket, {tcp, ssl}). -record(delivery, {mandatory, immediate, txn, sender, message}). +-record(amqp_error, {name, expl = "", method = none}). + %%---------------------------------------------------------------------------- -ifdef(use_specs). @@ -154,7 +156,10 @@ port :: non_neg_integer()}). -type(not_found() :: {'error', 'not_found'}). -type(routing_result() :: 'routed' | 'unroutable' | 'not_delivered'). - +-type(amqp_error() :: + #amqp_error{name :: atom(), + expl :: string(), + method :: atom()}). -endif. %%---------------------------------------------------------------------------- diff --git a/include/rabbit_framing_spec.hrl b/include/rabbit_framing_spec.hrl index f45fa6ca..a78c2301 100644 --- a/include/rabbit_framing_spec.hrl +++ b/include/rabbit_framing_spec.hrl @@ -50,8 +50,6 @@ %% TODO: make this more precise -type(amqp_method_name() :: atom()). -type(channel_number() :: non_neg_integer()). -%% TODO: make this more precise --type(amqp_error() :: {bool(), non_neg_integer(), binary()}). -type(resource_name() :: binary()). -type(routing_key() :: binary()). -type(username() :: binary()). diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 1285064f..812b317a 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -125,11 +125,12 @@ handle_cast({method, Method, Content}, State) -> stop -> {stop, normal, State#ch{state = terminating}} catch - exit:{amqp, Error, Explanation, none} -> + exit:Reason = #amqp_error{} -> ok = rollback_and_notify(State), - Reason = {amqp, Error, Explanation, - rabbit_misc:method_record_type(Method)}, - State#ch.reader_pid ! {channel_exit, State#ch.channel, Reason}, + CompleteReason = Reason#amqp_error{method = + rabbit_misc:method_record_type(Method)}, + State#ch.reader_pid ! + {channel_exit, State#ch.channel, CompleteReason}, {stop, normal, State#ch{state = terminating}}; exit:normal -> {stop, normal, State}; diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 95a274e3..fc8d1381 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -35,7 +35,7 @@ -include_lib("kernel/include/file.hrl"). -export([method_record_type/1, polite_pause/0, polite_pause/1]). --export([die/1, frame_error/2, protocol_error/3, protocol_error/4]). +-export([die/1, frame_error/2, amqp_error/4, protocol_error/3, protocol_error/4]). -export([not_found/1]). -export([get_config/1, get_config/2, set_config/2]). -export([dirty_read/1]). @@ -74,10 +74,9 @@ -spec(polite_pause/1 :: (non_neg_integer()) -> 'done'). -spec(die/1 :: (atom()) -> no_return()). -spec(frame_error/2 :: (atom(), binary()) -> no_return()). --spec(protocol_error/3 :: - (atom() | amqp_error(), string(), [any()]) -> no_return()). --spec(protocol_error/4 :: - (atom() | amqp_error(), string(), [any()], atom()) -> no_return()). +-spec(amqp_error/4 :: (atom(), string(), [any()], atom()) -> amqp_error()). +-spec(protocol_error/3 :: (atom(), string(), [any()]) -> no_return()). +-spec(protocol_error/4 :: (atom(), string(), [any()], atom()) -> no_return()). -spec(not_found/1 :: (r(atom())) -> no_return()). -spec(get_config/1 :: (atom()) -> {'ok', any()} | not_found()). -spec(get_config/2 :: (atom(), A) -> A). @@ -144,15 +143,17 @@ die(Error) -> protocol_error(Error, "~w", [Error]). frame_error(MethodName, BinaryFields) -> - protocol_error(frame_error, "cannot decode ~w", - [BinaryFields], MethodName). + protocol_error(frame_error, "cannot decode ~w", [BinaryFields], MethodName). -protocol_error(Error, Explanation, Params) -> - protocol_error(Error, Explanation, Params, none). +amqp_error(Name, Explanation, Params, Method) -> + #amqp_error{name = Name, + expl = lists:flatten(io_lib:format(Explanation, Params)), + method = Method}. -protocol_error(Error, Explanation, Params, Method) -> - CompleteExplanation = lists:flatten(io_lib:format(Explanation, Params)), - exit({amqp, Error, CompleteExplanation, Method}). +protocol_error(Name, Explanation, Params) -> + protocol_error(Name, Explanation, Params, none). +protocol_error(Name, Explanation, Params, Method) -> + exit(amqp_error(Name, Explanation, Params, Method)). not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]). diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 69dbc008..20a9e6d3 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -269,12 +269,10 @@ mainloop(Parent, Deb, State = #v1{sock= Sock, recv_ref = Ref}) -> throw({inet_error, Reason}); {'EXIT', Parent, Reason} -> if State#v1.connection_state =:= running -> - send_exception( - State, 0, - {amqp, connection_forced, - io_lib:format( - "broker forced connection closure with reason '~w'", - [Reason]), none}); + send_exception(State, 0, + rabbit_misc:amqp_error(connection_forced, + "broker forced connection closure with reason '~w'", + [Reason], none)); true -> ok end, %% this is what we are expected to do according to @@ -567,12 +565,13 @@ handle_method0(MethodName, FieldsBin, State) -> MethodName, FieldsBin), State) catch exit:Reason -> - CompleteReason = - case Reason of - {amqp, Error, Explanation, none} -> - {amqp, Error, Explanation, MethodName}; - OtherReason -> OtherReason - end, + CompleteReason = + case Reason of + #amqp_error{method = none} -> + Reason#amqp_error{method = MethodName}; + _ -> + Reason + end, case State#v1.connection_state of running -> send_exception(State, 0, CompleteReason); Other -> throw({channel0_error, Other, CompleteReason}) @@ -793,18 +792,21 @@ map_exception(Channel, Reason) -> end, {ShouldClose, CloseChannel, CloseMethod}. -lookup_amqp_exception({amqp, {ShouldClose, Code, Text}, Expl, Method}) -> +lookup_amqp_exception(#amqp_error{name = Name, + expl = Expl, + method = Method}) -> + {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name), ExplBin = list_to_binary(Expl), CompleteTextBin = <>, - SafeTextBin = if size(CompleteTextBin) > 255 -> - <>; - true -> - CompleteTextBin - end, - {ShouldClose, Code, SafeTextBin, Method}; -lookup_amqp_exception({amqp, ErrorName, Expl, Method}) -> - Details = rabbit_framing:lookup_amqp_exception(ErrorName), - lookup_amqp_exception({amqp, Details, Expl, Method}); + SafeTextBin = + if + size(CompleteTextBin) > 255 -> + <>; + true -> + CompleteTextBin + end, + {ShouldClose, Code, SafeTextBin, Method}; + lookup_amqp_exception(Other) -> rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]), - {true, ?INTERNAL_ERROR, <<"INTERNAL_ERROR">>, none}. + lookup_amqp_exception(#amqp_error{name = internal_error}). -- cgit v1.2.1 From 239291cc0300fcae297caa7bdd2f5ebb20fb226f Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Thu, 17 Sep 2009 13:49:11 +0100 Subject: changing back a few usages of proplists:* to lists:key*; changing usages of proplists:lookup to proplists:get_value --- src/rabbit_control.erl | 4 ++-- src/rabbit_misc.erl | 6 +++--- src/rabbit_multi.erl | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index e05b1886..ed1d384d 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -326,8 +326,8 @@ display_row(Row) -> io:nl(). format_info_item(Key, Items) -> - Info = {Key, Value} = proplists:lookup(Key, Items), - case Info of + Value = proplists:get_value(Key, Items), + case {Key, Value} of {_, #resource{name = Name}} -> escape(Name); _ when Key =:= address; Key =:= peer_address andalso is_tuple(Value) -> diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 814e3c31..95a274e3 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -189,9 +189,9 @@ r(VHostPath, Kind) when is_binary(VHostPath) -> r_arg(#resource{virtual_host = VHostPath}, Kind, Table, Key) -> r_arg(VHostPath, Kind, Table, Key); r_arg(VHostPath, Kind, Table, Key) -> - case proplists:lookup(Key, Table) of - {_, longstr, NameBin} -> r(VHostPath, Kind, NameBin); - none -> undefined + case lists:keysearch(Key, 1, Table) of + {value, {_, longstr, NameBin}} -> r(VHostPath, Kind, NameBin); + false -> undefined end. rs(#resource{virtual_host = VHostPath, kind = Kind, name = Name}) -> diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 6fc7bd67..35b1def3 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -217,19 +217,19 @@ is_rabbit_running(Node, RpcTimeout) -> {badrpc, _} -> false; Status -> - case proplists:lookup(running_applications, Status) of - {running_applications, Apps} -> - proplists:is_defined(rabbit, Apps); - none -> - false + case proplists:get_value(running_applications, Status) of + undefined -> + false; + Apps -> + lists:keymember(rabbit, 1, Apps) end end. with_os(Handlers) -> {OsFamily, _} = os:type(), - case proplists:lookup(OsFamily, Handlers) of - {_, Handler} -> Handler(); - none -> throw({unsupported_os, OsFamily}) + case proplists:get_value(OsFamily, Handlers) of + Handler -> Handler(); + undefined -> throw({unsupported_os, OsFamily}) end. script_filename() -> -- cgit v1.2.1 From e514acb349470e84d5a10b748f8901991faa8f1a Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Thu, 17 Sep 2009 14:06:29 +0100 Subject: a little refactoring; fixing case patterns order --- src/rabbit_multi.erl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 35b1def3..b1cc4d02 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -214,22 +214,18 @@ run_cmd(FullPath) -> is_rabbit_running(Node, RpcTimeout) -> case rpc:call(Node, rabbit, status, [], RpcTimeout) of - {badrpc, _} -> - false; - Status -> - case proplists:get_value(running_applications, Status) of - undefined -> - false; - Apps -> - lists:keymember(rabbit, 1, Apps) - end + {badrpc, _} -> false; + Status -> case proplists:get_value(running_applications, Status) of + undefined -> false; + Apps -> lists:keymember(rabbit, 1, Apps) + end end. with_os(Handlers) -> {OsFamily, _} = os:type(), case proplists:get_value(OsFamily, Handlers) of - Handler -> Handler(); - undefined -> throw({unsupported_os, OsFamily}) + undefined -> throw({unsupported_os, OsFamily}); + Handler -> Handler() end. script_filename() -> -- cgit v1.2.1 From 133d7888fac7fd5efe13ddf62ca82ca1538b3777 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 17 Sep 2009 22:26:30 +0100 Subject: small simplification --- src/rabbit_control.erl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index ed1d384d..69e21f7e 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -326,17 +326,17 @@ display_row(Row) -> io:nl(). format_info_item(Key, Items) -> - Value = proplists:get_value(Key, Items), - case {Key, Value} of - {_, #resource{name = Name}} -> + case proplists:get_value(Key, Items) of + #resource{name = Name} -> escape(Name); - _ when Key =:= address; Key =:= peer_address andalso is_tuple(Value) -> + Value when Key =:= address; Key =:= peer_address andalso + is_tuple(Value) -> inet_parse:ntoa(Value); - _ when is_pid(Value) -> + Value when is_pid(Value) -> atom_to_list(node(Value)); - _ when is_binary(Value) -> + Value when is_binary(Value) -> escape(Value); - _ -> + Value -> io_lib:format("~w", [Value]) end. -- cgit v1.2.1 From 879fea84045d606716454fbaaecd39f84be69782 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 18 Sep 2009 06:08:44 +0100 Subject: handle timeouts in cpu_sup:avg1 gracefully Also, it turns out that the load avg is an int, not a float --- src/rabbit_load.erl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/rabbit_load.erl b/src/rabbit_load.erl index 7bf85347..6ef638cb 100644 --- a/src/rabbit_load.erl +++ b/src/rabbit_load.erl @@ -41,7 +41,7 @@ -ifdef(use_specs). -type(erlang_node() :: atom()). --type(load() :: {{non_neg_integer(), float()}, erlang_node()}). +-type(load() :: {{non_neg_integer(), integer() | 'unknown'}, erlang_node()}). -spec(local_load/0 :: () -> load()). -spec(remote_loads/0 :: () -> [load()]). -spec(pick/0 :: () -> erlang_node()). @@ -52,8 +52,11 @@ local_load() -> LoadAvg = case whereis(cpu_sup) of - undefined -> 0.0; - _Other -> cpu_sup:avg1() + undefined -> unknown; + _ -> case cpu_sup:avg1() of + L when is_integer(L) -> L; + {error, timeout} -> unknown + end end, {{statistics(run_queue), LoadAvg}, node()}. @@ -65,8 +68,12 @@ remote_loads() -> pick() -> RemoteLoads = remote_loads(), {{RunQ, LoadAvg}, Node} = local_load(), - %% add bias towards current node - AdjustedLoadAvg = LoadAvg * ?FUDGE_FACTOR, + %% add bias towards current node; we rely on Erlang's term order + %% of SomeFloat < local_unknown < unknown. + AdjustedLoadAvg = case LoadAvg of + unknown -> local_unknown; + _ -> LoadAvg * ?FUDGE_FACTOR + end, Loads = [{{RunQ, AdjustedLoadAvg}, Node} | RemoteLoads], {_, SelectedNode} = lists:min(Loads), SelectedNode. -- cgit v1.2.1 From 3d53ddc7cafc8dcaa560118285d2b96d26ab9579 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 18 Sep 2009 06:12:26 +0100 Subject: fix .hgignore regexps --- .hgignore | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.hgignore b/.hgignore index 839f1601..d77d4e5d 100644 --- a/.hgignore +++ b/.hgignore @@ -8,13 +8,10 @@ erl_crash.dump syntax: regexp ^cover/ ^dist/ -^include/rabbit_framing.hrl$ -^src/rabbit_framing.erl$ -^rabbit.plt$ -^ebin/rabbit.app$ -^ebin/rabbit.rel$ -^ebin/rabbit.boot$ -^ebin/rabbit.script$ +^include/rabbit_framing\.hrl$ +^src/rabbit_framing\.erl$ +^rabbit\.plt$ +^ebin/rabbit\.(app|rel|boot|script)$ ^plugins/ ^priv/plugins/ -- cgit v1.2.1 From d314c99966c715b6949222863fff2f99513c575c Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 18 Sep 2009 12:55:21 +0100 Subject: Escape atoms as lists and binaries are. --- src/rabbit_control.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index ac7e3eaa..69e91803 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -338,7 +338,7 @@ format_info_item(Key, Items) -> Value when is_binary(Value) -> escape(Value); Value when is_atom(Value) -> - io_lib:format("~s", [Value]); + escape(atom_to_list(Value)); Value -> io_lib:format("~w", [Value]) end. @@ -365,7 +365,9 @@ rpc_call(Node, Mod, Fun, Args) -> %% form part of UTF-8 strings. escape(Bin) when binary(Bin) -> - escape_char(lists:reverse(binary_to_list(Bin)), []). + escape(binary_to_list(Bin)); +escape(L) when is_list(L) -> + escape_char(lists:reverse(L), []). escape_char([$\\ | T], Acc) -> escape_char(T, [$\\, $\\ | Acc]); -- cgit v1.2.1 From 7ddef841e54ea2d5b9f035f3580eee96f419ee88 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 18 Sep 2009 14:17:49 +0100 Subject: Escape *all* the double-quotes in an arg, not just the first one. --- packaging/common/rabbitmq-asroot-script-wrapper | 2 +- packaging/common/rabbitmq-script-wrapper | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/common/rabbitmq-asroot-script-wrapper b/packaging/common/rabbitmq-asroot-script-wrapper index 0dd1c0fb..9ef59ad7 100644 --- a/packaging/common/rabbitmq-asroot-script-wrapper +++ b/packaging/common/rabbitmq-asroot-script-wrapper @@ -33,7 +33,7 @@ # Escape spaces and quotes, because shell is revolting. for arg in "$@" ; do # Escape quotes in parameters, so that they're passed through cleanly. - arg=$(sed -e 's/"/\\"/' <<-END + arg=$(sed -e 's/"/\\"/g' <<-END $arg END ) diff --git a/packaging/common/rabbitmq-script-wrapper b/packaging/common/rabbitmq-script-wrapper index 94d72f16..0c4bd0a8 100644 --- a/packaging/common/rabbitmq-script-wrapper +++ b/packaging/common/rabbitmq-script-wrapper @@ -33,7 +33,7 @@ # Escape spaces and quotes, because shell is revolting. for arg in "$@" ; do # Escape quotes in parameters, so that they're passed through cleanly. - arg=$(sed -e 's/"/\\"/' <<-END + arg=$(sed -e 's/"/\\"/g' <<-END $arg END ) -- cgit v1.2.1 From 078735c3b9379317f8f9153d20ba2a25c7c68e7d Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 19 Sep 2009 05:47:05 +0100 Subject: minor, mostly cosmetic, tweaks --- include/rabbit.hrl | 2 +- src/rabbit_channel.erl | 7 +++---- src/rabbit_misc.erl | 19 ++++++++++--------- src/rabbit_reader.erl | 36 ++++++++++++++++-------------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index fbe598cc..84a1d4f7 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -67,7 +67,7 @@ -record(ssl_socket, {tcp, ssl}). -record(delivery, {mandatory, immediate, txn, sender, message}). --record(amqp_error, {name, expl = "", method = none}). +-record(amqp_error, {name, expl, method = none}). %%---------------------------------------------------------------------------- diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 812b317a..a1fa1066 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -127,10 +127,9 @@ handle_cast({method, Method, Content}, State) -> catch exit:Reason = #amqp_error{} -> ok = rollback_and_notify(State), - CompleteReason = Reason#amqp_error{method = - rabbit_misc:method_record_type(Method)}, - State#ch.reader_pid ! - {channel_exit, State#ch.channel, CompleteReason}, + MethodName = rabbit_misc:method_record_type(Method), + State#ch.reader_pid ! {channel_exit, State#ch.channel, + Reason#amqp_error{method = MethodName}}, {stop, normal, State#ch{state = terminating}}; exit:normal -> {stop, normal, State}; diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index fc8d1381..7e15dfe8 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -35,7 +35,8 @@ -include_lib("kernel/include/file.hrl"). -export([method_record_type/1, polite_pause/0, polite_pause/1]). --export([die/1, frame_error/2, amqp_error/4, protocol_error/3, protocol_error/4]). +-export([die/1, frame_error/2, amqp_error/4, + protocol_error/3, protocol_error/4]). -export([not_found/1]). -export([get_config/1, get_config/2, set_config/2]). -export([dirty_read/1]). @@ -145,15 +146,15 @@ die(Error) -> frame_error(MethodName, BinaryFields) -> protocol_error(frame_error, "cannot decode ~w", [BinaryFields], MethodName). -amqp_error(Name, Explanation, Params, Method) -> - #amqp_error{name = Name, - expl = lists:flatten(io_lib:format(Explanation, Params)), - method = Method}. +amqp_error(Name, ExplanationFormat, Params, Method) -> + Explanation = lists:flatten(io_lib:format(ExplanationFormat, Params)), + #amqp_error{name = Name, expl = Explanation, method = Method}. -protocol_error(Name, Explanation, Params) -> - protocol_error(Name, Explanation, Params, none). -protocol_error(Name, Explanation, Params, Method) -> - exit(amqp_error(Name, Explanation, Params, Method)). +protocol_error(Name, ExplanationFormat, Params) -> + protocol_error(Name, ExplanationFormat, Params, none). + +protocol_error(Name, ExplanationFormat, Params, Method) -> + exit(amqp_error(Name, ExplanationFormat, Params, Method)). not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]). diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 1f09ba33..cb59d7dc 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -565,18 +565,17 @@ handle_method0(MethodName, FieldsBin, State) -> MethodName, FieldsBin), State) catch exit:Reason -> - CompleteReason = - case Reason of - #amqp_error{method = none} -> - Reason#amqp_error{method = MethodName}; - _ -> - Reason - end, + CompleteReason = case Reason of + #amqp_error{method = none} -> + Reason#amqp_error{method = MethodName}; + OtherReason -> OtherReason + end, case State#v1.connection_state of running -> send_exception(State, 0, CompleteReason); Other -> throw({channel0_error, Other, CompleteReason}) end end. + handle_method0(#'connection.start_ok'{mechanism = Mechanism, response = Response}, State = #v1{connection_state = starting, @@ -792,21 +791,18 @@ map_exception(Channel, Reason) -> end, {ShouldClose, CloseChannel, CloseMethod}. -lookup_amqp_exception(#amqp_error{name = Name, - expl = Expl, - method = Method}) -> +lookup_amqp_exception( + #amqp_error{name = Name, expl = Expl, method = Method}) -> {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name), ExplBin = list_to_binary(Expl), CompleteTextBin = <>, - SafeTextBin = - if - size(CompleteTextBin) > 255 -> - <>; - true -> - CompleteTextBin - end, - {ShouldClose, Code, SafeTextBin, Method}; - + SafeTextBin = if size(CompleteTextBin) > 255 -> + <>; + true -> CompleteTextBin + end, + {ShouldClose, Code, SafeTextBin, Method}; lookup_amqp_exception(Other) -> rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]), - lookup_amqp_exception(#amqp_error{name = internal_error}). + {ShouldClose, Code, Text} = + rabbit_framing:lookup_amqp_exception(internal_error), + {ShouldClose, Code, Text, none}. -- cgit v1.2.1 From b84783b5d9e607fbc967e5e261f4d89aa03962f0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Sep 2009 07:24:38 +0100 Subject: do not time out waitng for channel.close_ok, wait forever instead This is to prevent the following observable protocol violation: C->S: 1:channel.open S->C: 1:channel.open_ok C->S: 1:some command that triggers a channel close S->C: 1:channel.close (client waits for longer than server close_ok timeout) C->S: 1:channel.open S->C: 1:channel.open_ok The second channel.open should have been ignored by the server, and it should not have returned a channel.open_ok. --- src/rabbit_reader.erl | 85 +++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 57 deletions(-) diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 690e6f0e..5d7f8a42 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -49,7 +49,6 @@ -define(HANDSHAKE_TIMEOUT, 10). -define(NORMAL_TIMEOUT, 3). -define(CLOSING_TIMEOUT, 1). --define(CHANNEL_CLOSING_TIMEOUT, 1). -define(CHANNEL_TERMINATION_TIMEOUT, 3). %--------------------------------------------------------------------------- @@ -94,23 +93,19 @@ %% -> log error, wait for channels to terminate forcefully, start %% terminate_connection timer, send close, *closed* %% channel exit with soft error -%% -> log error, start terminate_channel timer, mark channel as -%% closing, *running* -%% terminate_channel timeout -> remove 'closing' mark, *running* +%% -> log error, mark channel as closing, *running* %% handshake_timeout -> ignore, *running* %% heartbeat timeout -> *throw* %% closing: %% socket close -> *terminate* %% receive frame -> ignore, *closing* -%% terminate_channel timeout -> remove 'closing' mark, *closing* %% handshake_timeout -> ignore, *closing* %% heartbeat timeout -> *throw* %% channel exit with hard error %% -> log error, wait for channels to terminate forcefully, start %% terminate_connection timer, send close, *closed* %% channel exit with soft error -%% -> log error, start terminate_channel timer, mark channel as -%% closing +%% -> log error, mark channel as closing %% if last channel to exit then send connection.close_ok, %% start terminate_connection timer, *closed* %% else *closing* @@ -123,7 +118,6 @@ %% *closed* %% receive frame -> ignore, *closed* %% terminate_connection timeout -> *terminate* -%% terminate_channel timeout -> remove 'closing' mark, *closed* %% handshake_timeout -> ignore, *closed* %% heartbeat timeout -> *throw* %% channel exit -> log error, *closed* @@ -292,8 +286,6 @@ mainloop(Parent, Deb, State = #v1{sock= Sock, recv_ref = Ref}) -> mainloop(Parent, Deb, handle_channel_exit(Channel, Reason, State)); {'EXIT', Pid, Reason} -> mainloop(Parent, Deb, handle_dependent_exit(Pid, Reason, State)); - {terminate_channel, Channel, Ref1} -> - mainloop(Parent, Deb, terminate_channel(Channel, Ref1, State)); terminate_connection -> State; handshake_timeout -> @@ -341,32 +333,15 @@ close_connection(State = #v1{connection = #connection{ State#v1{connection_state = closed}. close_channel(Channel, State) -> - Ref = make_ref(), - TRef = erlang:send_after(1000 * ?CHANNEL_CLOSING_TIMEOUT, - self(), - {terminate_channel, Channel, Ref}), - put({closing_channel, Channel}, {Ref, TRef}), - State. - -terminate_channel(Channel, Ref, State) -> - case get({closing_channel, Channel}) of - undefined -> ok; %% got close_ok in the meantime - {Ref, _} -> erase({closing_channel, Channel}), - ok; - {_Ref, _} -> ok %% got close_ok, and have new closing channel - end, + put({channel, Channel}, closing), State. handle_channel_exit(Channel, Reason, State) -> - %% We remove the channel from the inbound map only. That allows - %% the channel to be re-opened, but also means the remaining - %% cleanup, including possibly closing the connection, is deferred - %% until we get the (normal) exit signal. - erase({channel, Channel}), handle_exception(State, Channel, Reason). handle_dependent_exit(Pid, normal, State) -> - channel_cleanup(Pid), + erase({chpid, Pid}), + erase({closing_chpid, Pid}), maybe_close(State); handle_dependent_exit(Pid, Reason, State) -> case channel_cleanup(Pid) of @@ -470,10 +445,20 @@ handle_frame(Type, Channel, Payload, State) -> ok = check_for_close(Channel, ChPid, AnalyzedFrame), ok = rabbit_framing_channel:process(ChPid, AnalyzedFrame), State; + closing -> + %% According to the spec, after sending a + %% channel.close we must ignore all frames except + %% channel.close_ok. + case AnalyzedFrame of + {method, 'channel.close_ok', _} -> + erase({channel, Channel}); + _ -> ok + end, + State; undefined -> case State#v1.connection_state of - running -> send_to_new_channel( - Channel, AnalyzedFrame, State), + running -> ok = send_to_new_channel( + Channel, AnalyzedFrame, State), State; Other -> throw({channel_frame_while_starting, Channel, Other, AnalyzedFrame}) @@ -716,31 +701,17 @@ i(Item, #v1{}) -> %%-------------------------------------------------------------------------- send_to_new_channel(Channel, AnalyzedFrame, State) -> - case get({closing_channel, Channel}) of - undefined -> - #v1{sock = Sock, - connection = #connection{ - frame_max = FrameMax, - user = #user{username = Username}, - vhost = VHost}} = State, - WriterPid = rabbit_writer:start(Sock, Channel, FrameMax), - ChPid = rabbit_framing_channel:start_link( - fun rabbit_channel:start_link/5, - [Channel, self(), WriterPid, Username, VHost]), - put({channel, Channel}, {chpid, ChPid}), - put({chpid, ChPid}, {channel, Channel}), - ok = rabbit_framing_channel:process(ChPid, AnalyzedFrame); - {_, TRef} -> - %% According to the spec, after sending a channel.close we - %% must ignore all frames except channel.close_ok. - case AnalyzedFrame of - {method, 'channel.close_ok', _} -> - erlang:cancel_timer(TRef), - erase({closing_channel, Channel}), - ok; - _Other -> ok - end - end. + #v1{sock = Sock, connection = #connection{ + frame_max = FrameMax, + user = #user{username = Username}, + vhost = VHost}} = State, + WriterPid = rabbit_writer:start(Sock, Channel, FrameMax), + ChPid = rabbit_framing_channel:start_link( + fun rabbit_channel:start_link/5, + [Channel, self(), WriterPid, Username, VHost]), + put({channel, Channel}, {chpid, ChPid}), + put({chpid, ChPid}, {channel, Channel}), + ok = rabbit_framing_channel:process(ChPid, AnalyzedFrame). check_for_close(Channel, ChPid, {method, 'channel.close', _}) -> channel_cleanup(ChPid), -- cgit v1.2.1 From 5ff2563f1ab5305509bf3be6691ea4493f98e85e Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Sep 2009 08:19:07 +0100 Subject: get rid of closing_chpid process dict entries They were entirely redundant. It is now the case the the chpid process dict entries only get removed when receiving an EXIT signal from a channel, which is more obviously correct. --- src/rabbit_reader.erl | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 5d7f8a42..ec0c70fb 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -341,7 +341,6 @@ handle_channel_exit(Channel, Reason, State) -> handle_dependent_exit(Pid, normal, State) -> erase({chpid, Pid}), - erase({closing_chpid, Pid}), maybe_close(State); handle_dependent_exit(Pid, Reason, State) -> case channel_cleanup(Pid) of @@ -351,17 +350,10 @@ handle_dependent_exit(Pid, Reason, State) -> channel_cleanup(Pid) -> case get({chpid, Pid}) of - undefined -> - case get({closing_chpid, Pid}) of - undefined -> undefined; - {channel, Channel} -> - erase({closing_chpid, Pid}), - Channel - end; - {channel, Channel} -> - erase({channel, Channel}), - erase({chpid, Pid}), - Channel + undefined -> undefined; + {channel, Channel} -> erase({channel, Channel}), + erase({chpid, Pid}), + Channel end. all_channels() -> [Pid || {{chpid, Pid},_} <- get()]. @@ -442,7 +434,11 @@ handle_frame(Type, Channel, Payload, State) -> %%?LOGDEBUG("Ch ~p Frame ~p~n", [Channel, AnalyzedFrame]), case get({channel, Channel}) of {chpid, ChPid} -> - ok = check_for_close(Channel, ChPid, AnalyzedFrame), + case AnalyzedFrame of + {method, 'channel.close', _} -> + erase({channel, Channel}); + _ -> ok + end, ok = rabbit_framing_channel:process(ChPid, AnalyzedFrame), State; closing -> @@ -713,13 +709,6 @@ send_to_new_channel(Channel, AnalyzedFrame, State) -> put({chpid, ChPid}, {channel, Channel}), ok = rabbit_framing_channel:process(ChPid, AnalyzedFrame). -check_for_close(Channel, ChPid, {method, 'channel.close', _}) -> - channel_cleanup(ChPid), - put({closing_chpid, ChPid}, {channel, Channel}), - ok; -check_for_close(_Channel, _ChPid, _Frame) -> - ok. - log_channel_error(ConnectionState, Channel, Reason) -> rabbit_log:error("connection ~p (~p), channel ~p - error:~n~p~n", [self(), ConnectionState, Channel, Reason]). -- cgit v1.2.1 From fbe392f9fb86cd25f0852e9ab3361c01894913a3 Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Mon, 21 Sep 2009 08:21:34 +0100 Subject: Removed unused .boot generation target; added rabbit.rel to list of files removed on clean --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f0702756..a94406a3 100644 --- a/Makefile +++ b/Makefile @@ -57,15 +57,12 @@ $(INCLUDE_DIR)/rabbit_framing.hrl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.p $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(AMQP_SPEC_JSON_PATH) $(PYTHON) codegen.py body $(AMQP_SPEC_JSON_PATH) $@ -$(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.rel $(TARGETS) - erl -noshell -eval 'systools:make_script("ebin/rabbit", [{path, ["ebin"]}]), halt().' - dialyze: $(BEAM_TARGETS) dialyzer -c $? clean: rm -f $(EBIN_DIR)/*.beam - rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script + rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script $(EBIN_DIR)/rabbit.rel rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc rm -f docs/*.[0-9].gz -- cgit v1.2.1 From 10fb1ebf5b464101b11989a333cee73f3d02c2c8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Sep 2009 08:22:59 +0100 Subject: include channel# in unknown_frame error --- src/rabbit_reader.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 690e6f0e..761794f1 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -451,7 +451,7 @@ handle_frame(_Type, _Channel, _Payload, State = #v1{connection_state = CS}) State; handle_frame(Type, 0, Payload, State) -> case analyze_frame(Type, Payload) of - error -> throw({unknown_frame, Type, Payload}); + error -> throw({unknown_frame, 0, Type, Payload}); heartbeat -> State; trace -> State; {method, MethodName, FieldsBin} -> @@ -460,7 +460,7 @@ handle_frame(Type, 0, Payload, State) -> end; handle_frame(Type, Channel, Payload, State) -> case analyze_frame(Type, Payload) of - error -> throw({unknown_frame, Type, Payload}); + error -> throw({unknown_frame, Channel, Type, Payload}); heartbeat -> throw({unexpected_heartbeat_frame, Channel}); trace -> throw({unexpected_trace_frame, Channel}); AnalyzedFrame -> -- cgit v1.2.1 From 4ec4db48aa0803d15e682d57cca47bc66a43293c Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Mon, 21 Sep 2009 08:44:49 +0100 Subject: Added unix and windows variants of deactivate plugins script; initial packaging changes --- packaging/debs/Debian/debian/rules | 2 +- packaging/macports/net/rabbitmq-server/Portfile | 1 + packaging/windows/Makefile | 1 + scripts/rabbitmq-deactivate-plugins | 37 +++++++++++++++++++++++++ scripts/rabbitmq-deactivate-plugins.bat | 35 +++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 scripts/rabbitmq-deactivate-plugins create mode 100644 scripts/rabbitmq-deactivate-plugins.bat diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index 365eea6e..5e357955 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -17,6 +17,6 @@ install/rabbitmq-server:: for script in rabbitmqctl rabbitmq-server rabbitmq-multi; do \ install -p -D -m 0755 debian/rabbitmq-script-wrapper $(DEB_DESTDIR)usr/sbin/$$script; \ done - for script in rabbitmq-activate-plugins; do \ + for script in rabbitmq-activate-plugins rabbitmq-deactivate-plugins; do \ install -p -D -m 0755 debian/rabbitmq-asroot-script-wrapper $(DEB_DESTDIR)usr/sbin/$$script; \ done diff --git a/packaging/macports/net/rabbitmq-server/Portfile b/packaging/macports/net/rabbitmq-server/Portfile index 1826d5c4..cf1a3a03 100644 --- a/packaging/macports/net/rabbitmq-server/Portfile +++ b/packaging/macports/net/rabbitmq-server/Portfile @@ -94,6 +94,7 @@ post-destroot { ${wrappersbin}/rabbitmq-activate-plugins file copy ${wrappersbin}/rabbitmq-multi ${wrappersbin}/rabbitmq-server file copy ${wrappersbin}/rabbitmq-multi ${wrappersbin}/rabbitmqctl + file copy ${wrappersbin}/rabbitmq-activate-plugins ${wrappersbin}/rabbitmq-deactivate-plugins } pre-install { diff --git a/packaging/windows/Makefile b/packaging/windows/Makefile index 387becb3..f17fe777 100644 --- a/packaging/windows/Makefile +++ b/packaging/windows/Makefile @@ -14,6 +14,7 @@ dist: mv $(SOURCE_DIR)/scripts/rabbitmqctl.bat $(SOURCE_DIR)/sbin mv $(SOURCE_DIR)/scripts/rabbitmq-multi.bat $(SOURCE_DIR)/sbin mv $(SOURCE_DIR)/scripts/rabbitmq-activate-plugins.bat $(SOURCE_DIR)/sbin + mv $(SOURCE_DIR)/scripts/rabbitmq-deactivate-plugins.bat $(SOURCE_DIR)/sbin rm -rf $(SOURCE_DIR)/scripts rm -rf $(SOURCE_DIR)/codegen* $(SOURCE_DIR)/Makefile rm -f $(SOURCE_DIR)/README diff --git a/scripts/rabbitmq-deactivate-plugins b/scripts/rabbitmq-deactivate-plugins new file mode 100755 index 00000000..771c4734 --- /dev/null +++ b/scripts/rabbitmq-deactivate-plugins @@ -0,0 +1,37 @@ +#!/bin/sh +## The contents of this file are subject to the Mozilla Public License +## Version 1.1 (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://www.mozilla.org/MPL/ +## +## Software distributed under the License is distributed on an "AS IS" +## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +## License for the specific language governing rights and limitations +## under the License. +## +## The Original Code is RabbitMQ. +## +## The Initial Developers of the Original Code are LShift Ltd, +## Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. +## +## Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, +## Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd +## are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial +## Technologies LLC, and Rabbit Technologies Ltd. +## +## Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift +## Ltd. Portions created by Cohesive Financial Technologies LLC are +## Copyright (C) 2007-2009 Cohesive Financial Technologies +## LLC. Portions created by Rabbit Technologies Ltd are Copyright +## (C) 2007-2009 Rabbit Technologies Ltd. +## +## All Rights Reserved. +## +## Contributor(s): ______________________________________. +## + +. `dirname $0`/rabbitmq-env + +RABBITMQ_EBIN=${RABBITMQ_HOME}/ebin + +rm -f ${RABBITMQ_EBIN}/rabbit.rel ${RABBITMQ_EBIN}/rabbit.script ${RABBITMQ_EBIN}/rabbit.boot diff --git a/scripts/rabbitmq-deactivate-plugins.bat b/scripts/rabbitmq-deactivate-plugins.bat new file mode 100644 index 00000000..190fdef7 --- /dev/null +++ b/scripts/rabbitmq-deactivate-plugins.bat @@ -0,0 +1,35 @@ +@echo off +REM The contents of this file are subject to the Mozilla Public License +REM Version 1.1 (the "License"); you may not use this file except in +REM compliance with the License. You may obtain a copy of the License at +REM http://www.mozilla.org/MPL/ +REM +REM Software distributed under the License is distributed on an "AS IS" +REM basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +REM License for the specific language governing rights and limitations +REM under the License. +REM +REM The Original Code is RabbitMQ. +REM +REM The Initial Developers of the Original Code are LShift Ltd, +REM Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. +REM +REM Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, +REM Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd +REM are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial +REM Technologies LLC, and Rabbit Technologies Ltd. +REM +REM Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift +REM Ltd. Portions created by Cohesive Financial Technologies LLC are +REM Copyright (C) 2007-2009 Cohesive Financial Technologies +REM LLC. Portions created by Rabbit Technologies Ltd are Copyright +REM (C) 2007-2009 Rabbit Technologies Ltd. +REM +REM All Rights Reserved. +REM +REM Contributor(s): ______________________________________. +REM + +set RABBITMQ_EBIN_DIR="%~dp0..\ebin" + +del /f %RABBITMQ_EBIN_DIR%\rabbit.rel %RABBITMQ_EBIN_DIR%\rabbit.script %RABBITMQ_EBIN_DIR%\rabbit.boot -- cgit v1.2.1 From 2cf2fbb166fffe331310e453cb02c1c57e85c54e Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Mon, 21 Sep 2009 08:55:48 +0100 Subject: Added rabbitmq-deactivate-plugins to output package --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a94406a3..5f36d13e 100644 --- a/Makefile +++ b/Makefile @@ -170,7 +170,7 @@ install: all docs_all install_dirs cp -r ebin include LICENSE LICENSE-MPL-RabbitMQ INSTALL $(TARGET_DIR) chmod 0755 scripts/* - for script in rabbitmq-env rabbitmq-server rabbitmqctl rabbitmq-multi rabbitmq-activate-plugins; do \ + for script in rabbitmq-env rabbitmq-server rabbitmqctl rabbitmq-multi rabbitmq-activate-plugins rabbitmq-deactivate-plugins; do \ cp scripts/$$script $(TARGET_DIR)/sbin; \ [ -e $(SBIN_DIR)/$$script ] || ln -s $(SCRIPTS_REL_PATH)/$$script $(SBIN_DIR)/$$script; \ done -- cgit v1.2.1 From fe8952249034da820d4cdda353cab4680c44f67a Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Mon, 21 Sep 2009 08:59:39 +0100 Subject: Added deactivate plugins wrapper in RPM packages --- packaging/RPMS/Fedora/rabbitmq-server.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 7f442831..30cfb99f 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -56,6 +56,7 @@ install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmqctl install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmq-server install -p -D -m 0755 %{_rabbit_wrapper} %{buildroot}%{_sbindir}/rabbitmq-multi install -p -D -m 0755 %{_rabbit_asroot_wrapper} %{buildroot}%{_sbindir}/rabbitmq-activate-plugins +install -p -D -m 0755 %{_rabbit_asroot_wrapper} %{buildroot}%{_sbindir}/rabbitmq-deactivate-plugins install -p -D -m 0644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/rabbitmq-server -- cgit v1.2.1 From 3c047addbb00dd8f3d441a9289f4855d553e7344 Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Mon, 21 Sep 2009 09:18:03 +0100 Subject: Corrected behaviour of run-node so the boot file is not used --- Makefile | 3 ++- scripts/rabbitmq-server | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a94406a3..cc5f92ac 100644 --- a/Makefile +++ b/Makefile @@ -79,13 +79,14 @@ BASIC_SCRIPT_ENVIRONMENT_SETTINGS=\ run: all $(BASIC_SCRIPT_ENVIRONMENT_SETTINGS) \ - RABBITMQ_NODE_ONLY=true \ + RABBITMQ_ALLOW_INPUT=true \ RABBITMQ_SERVER_START_ARGS="$(RABBITMQ_SERVER_START_ARGS) -s rabbit" \ ./scripts/rabbitmq-server run-node: all $(BASIC_SCRIPT_ENVIRONMENT_SETTINGS) \ RABBITMQ_NODE_ONLY=true \ + RABBITMQ_ALLOW_INPUT=true \ RABBITMQ_SERVER_START_ARGS="$(RABBITMQ_SERVER_START_ARGS)" \ ./scripts/rabbitmq-server diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index 547220b4..e5317bb1 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -73,10 +73,11 @@ else fi RABBITMQ_START_RABBIT= -[ "x" = "x$RABBITMQ_NODE_ONLY" ] && RABBITMQ_START_RABBIT='-noinput -s rabbit' +[ "x" = "x$RABBITMQ_ALLOW_INPUT" ] && RABBITMQ_START_RABBIT='-noinput' +[ "x" = "x$RABBITMQ_NODE_ONLY" ] && RABBITMQ_START_RABBIT="${RABBITMQ_START_RABBIT} -s rabbit" RABBITMQ_EBIN_ROOT="${RABBITMQ_HOME}/ebin" -if [ -f "${RABBITMQ_EBIN_ROOT}/rabbit.boot" ]; then +if [ -f "${RABBITMQ_EBIN_ROOT}/rabbit.boot" ] && [ "x" = "x$RABBITMQ_NODE_ONLY" ]; then RABBITMQ_BOOT_FILE="${RABBITMQ_EBIN_ROOT}/rabbit" RABBITMQ_EBIN_PATH="" else -- cgit v1.2.1 From 07dfd12d73756d53c2362e4644d196f4b4c2e890 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 22 Sep 2009 10:55:57 +0100 Subject: remove extra_startup_steps from app config This should have been done as part of bug17880. --- ebin/rabbit_app.in | 1 - 1 file changed, 1 deletion(-) diff --git a/ebin/rabbit_app.in b/ebin/rabbit_app.in index 6fc6e464..dd907d1a 100644 --- a/ebin/rabbit_app.in +++ b/ebin/rabbit_app.in @@ -17,7 +17,6 @@ {env, [{tcp_listeners, [{"0.0.0.0", 5672}]}, {ssl_listeners, []}, {ssl_options, []}, - {extra_startup_steps, []}, {default_user, <<"guest">>}, {default_pass, <<"guest">>}, {default_vhost, <<"/">>}, -- cgit v1.2.1 From 8671674d89d11173f260b67185060aed8ed6d14e Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 22 Sep 2009 13:45:10 +0100 Subject: renaming expl to explanation in #amqp_error{} --- include/rabbit.hrl | 8 ++++---- src/rabbit_misc.erl | 2 +- src/rabbit_reader.erl | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 84a1d4f7..c95ce738 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -67,7 +67,7 @@ -record(ssl_socket, {tcp, ssl}). -record(delivery, {mandatory, immediate, txn, sender, message}). --record(amqp_error, {name, expl, method = none}). +-record(amqp_error, {name, explanation, method = none}). %%---------------------------------------------------------------------------- @@ -157,9 +157,9 @@ -type(not_found() :: {'error', 'not_found'}). -type(routing_result() :: 'routed' | 'unroutable' | 'not_delivered'). -type(amqp_error() :: - #amqp_error{name :: atom(), - expl :: string(), - method :: atom()}). + #amqp_error{name :: atom(), + explanation :: string(), + method :: atom()}). -endif. %%---------------------------------------------------------------------------- diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 7e15dfe8..58431438 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -148,7 +148,7 @@ frame_error(MethodName, BinaryFields) -> amqp_error(Name, ExplanationFormat, Params, Method) -> Explanation = lists:flatten(io_lib:format(ExplanationFormat, Params)), - #amqp_error{name = Name, expl = Explanation, method = Method}. + #amqp_error{name = Name, explanation = Explanation, method = Method}. protocol_error(Name, ExplanationFormat, Params) -> protocol_error(Name, ExplanationFormat, Params, none). diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index cb59d7dc..677144a5 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -792,7 +792,7 @@ map_exception(Channel, Reason) -> {ShouldClose, CloseChannel, CloseMethod}. lookup_amqp_exception( - #amqp_error{name = Name, expl = Expl, method = Method}) -> + #amqp_error{name = Name, explanation = Expl, method = Method}) -> {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name), ExplBin = list_to_binary(Expl), CompleteTextBin = <>, -- cgit v1.2.1 From c759aea4c0f1116714bf6aa14320d613acbb4a09 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Tue, 22 Sep 2009 16:41:50 +0100 Subject: getting rid of the .last_valid_dialysis approach; better erlang termination on failed dialysis --- .hgignore | 1 - Makefile | 28 ++++++++++------------------ src/rabbit_dialyzer.erl | 16 +++++++++++----- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.hgignore b/.hgignore index 74c90eb0..766e3aa8 100644 --- a/.hgignore +++ b/.hgignore @@ -12,7 +12,6 @@ syntax: regexp ^src/rabbit_framing.erl$ ^rabbit.plt$ ^basic.plt$ -^\.last_valid_dialysis$ ^ebin/rabbit.app$ ^ebin/rabbit.rel$ ^ebin/rabbit.boot$ diff --git a/Makefile b/Makefile index 609b645e..1199b73f 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ MANPAGES=$(patsubst %.pod, %.gz, $(wildcard docs/*.[0-9].pod)) PYTHON=python BASIC_PLT=basic.plt -PLT=rabbit.plt +RABBIT_PLT=rabbit.plt ifndef USE_SPECS # our type specs rely on features / bug fixes in dialyzer that are @@ -65,31 +65,23 @@ $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.rel $(TARGETS) erl -noshell -eval 'systools:make_script("ebin/rabbit", [{path, ["ebin"]}]), halt().' -dialyze: .last_valid_dialysis - -create-plt: $(PLT) - -$(PLT): $(BEAM_TARGETS) $(BASIC_PLT) - test -f $@ || cp $(BASIC_PLT) $@ +dialyze: $(BEAM_TARGETS) $(BASIC_PLT) $(ERL_EBIN) -eval \ - "rabbit_dialyzer:update_plt(\"$@\", \"$(BEAM_TARGETS)\"), halt()." + "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\"))." -.last_valid_dialysis: $(BEAM_TARGETS) $(PLT) - if [ $(PLT) -ot $@ ]; then \ - DIALYZER_INPUT_FILES="$(filter %.beam, $?)"; \ - else \ - DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \ - fi; \ +create-plt: $(RABBIT_PLT) + +$(RABBIT_PLT): $(BEAM_TARGETS) $(BASIC_PLT) + cp $(BASIC_PLT) $@ $(ERL_EBIN) -eval \ - "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$$DIALYZER_INPUT_FILES\"), halt()." && \ - touch $@ + "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:add_to_plt(\"$@\", \"$(BEAM_TARGETS)\"))." $(BASIC_PLT): $(BEAM_TARGETS) if [ -f $@ ]; then \ touch $@; \ else \ $(ERL_EBIN) -eval \ - "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()."; \ + "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:create_basic_plt(\"$@\"))."; \ fi clean: @@ -97,7 +89,7 @@ clean: rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc rm -f docs/*.[0-9].gz - rm -f $(PLT) .last_valid_dialysis + rm -f $(RABBIT_PLT) cleandb: rm -rf $(RABBITMQ_MNESIA_DIR)/* diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl index 4d78adbe..c75a001b 100644 --- a/src/rabbit_dialyzer.erl +++ b/src/rabbit_dialyzer.erl @@ -32,15 +32,16 @@ -module(rabbit_dialyzer). -include("rabbit.hrl"). --export([create_basic_plt/1, update_plt/2, dialyze_files/2]). +-export([create_basic_plt/1, add_to_plt/2, dialyze_files/2, halt_with_code/1]). %%---------------------------------------------------------------------------- -ifdef(use_specs). -spec(create_basic_plt/1 :: (string()) -> 'ok'). --spec(update_plt/2 :: (string(), string()) -> 'ok'). +-spec(add_to_plt/2 :: (string(), string()) -> 'ok'). -spec(dialyze_files/2 :: (string(), string()) -> 'ok'). +-spec(halt_with_code/1 :: (atom()) -> no_return()). -endif. @@ -54,8 +55,8 @@ create_basic_plt(BasicPltPath) -> dialyzer_cl:start(OptsRecord), ok. -update_plt(PltPath, ModifiedFiles) -> - {ok, Files} = regexp:split(ModifiedFiles, " "), +add_to_plt(PltPath, FilesString) -> + {ok, Files} = regexp:split(FilesString, " "), DialyzerWarnings = dialyzer:run([ {analysis_type, plt_add}, {init_plt, PltPath}, @@ -76,7 +77,7 @@ dialyze_files(PltPath, ModifiedFiles) -> _ -> io:format("~nFAILED! dialyzer returned the following warnings:~n", []), print_warnings(DialyzerWarnings), - erlang:error({dialyzer_warnings, DialyzerWarnings}) + fail end. print_warnings(DialyzerWarnings) -> @@ -91,3 +92,8 @@ print_warnings(DialyzerWarnings) -> otp_apps_dependencies_paths() -> [code:lib_dir(App, ebin) || App <- [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]]. + +halt_with_code(ok) -> + halt(); +halt_with_code(fail) -> + halt(1). -- cgit v1.2.1 From 936e4de0ee9cf55ebb08246e2c367c8c64c66b51 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 23 Sep 2009 13:58:05 +0100 Subject: broker now prints the location of rabbit.app on startup --- src/rabbit.erl | 14 ++++++++++---- src/rabbit_misc.erl | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index ef1e0049..2b292412 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -215,6 +215,11 @@ log_location(Type) -> _ -> undefined end. +app_location() -> + {ok, Application} = application:get_application(), + rabbit_misc:absolute_path( + code:where_is_file(atom_to_list(Application) ++ ".app")). + %--------------------------------------------------------------------------- print_banner() -> @@ -237,10 +242,11 @@ print_banner() -> [Product, string:right([$v|Version], ProductLen), ?PROTOCOL_VERSION_MAJOR, ?PROTOCOL_VERSION_MINOR, ?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]), - Settings = [{"node", node()}, - {"log", log_location(kernel)}, - {"sasl log", log_location(sasl)}, - {"database dir", rabbit_mnesia:dir()}], + Settings = [{"node", node()}, + {"app descriptor", app_location()}, + {"log", log_location(kernel)}, + {"sasl log", log_location(sasl)}, + {"database dir", rabbit_mnesia:dir()}], DescrLen = lists:max([length(K) || {K, _V} <- Settings]), Format = "~-" ++ integer_to_list(DescrLen) ++ "s: ~s~n", lists:foreach(fun ({K, V}) -> io:format(Format, [K, V]) end, Settings), diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 95a274e3..1af02ddf 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -55,6 +55,7 @@ -export([format_stderr/2]). -export([start_applications/1, stop_applications/1]). -export([unfold/2, ceil/1]). +-export([absolute_path/1]). -import(mnesia). -import(lists). @@ -124,6 +125,7 @@ -spec(stop_applications/1 :: ([atom()]) -> 'ok'). -spec(unfold/2 :: (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}). -spec(ceil/1 :: (number()) -> number()). +-spec(absolute_path/1 :: (string()) -> string()). -endif. @@ -475,3 +477,17 @@ ceil(N) -> 0 -> N; _ -> 1 + T end. + +absolute_path(RelPath) -> + filename:join(absolute_path([], filename:split(filename:absname(RelPath)))). + +absolute_path([_ | ResultParts], [".." | Parts]) -> + absolute_path(ResultParts, Parts); +absolute_path([], [".." | Parts]) -> + absolute_path([], Parts); +absolute_path(ResultParts, ["." | Parts]) -> + absolute_path(ResultParts, Parts); +absolute_path(ResultParts, [Part | Parts]) -> + absolute_path([Part | ResultParts], Parts); +absolute_path(ResultParts, []) -> + lists:reverse(ResultParts). -- cgit v1.2.1 From 73956170c3aaba621371e968d66d55323bca9756 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 23 Sep 2009 14:31:30 +0100 Subject: removing rabbit_misc:absolute_path --- src/rabbit.erl | 3 +-- src/rabbit_misc.erl | 16 ---------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 2b292412..27f085c2 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -217,8 +217,7 @@ log_location(Type) -> app_location() -> {ok, Application} = application:get_application(), - rabbit_misc:absolute_path( - code:where_is_file(atom_to_list(Application) ++ ".app")). + filename:absname(code:where_is_file(atom_to_list(Application) ++ ".app")). %--------------------------------------------------------------------------- diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 1af02ddf..95a274e3 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -55,7 +55,6 @@ -export([format_stderr/2]). -export([start_applications/1, stop_applications/1]). -export([unfold/2, ceil/1]). --export([absolute_path/1]). -import(mnesia). -import(lists). @@ -125,7 +124,6 @@ -spec(stop_applications/1 :: ([atom()]) -> 'ok'). -spec(unfold/2 :: (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}). -spec(ceil/1 :: (number()) -> number()). --spec(absolute_path/1 :: (string()) -> string()). -endif. @@ -477,17 +475,3 @@ ceil(N) -> 0 -> N; _ -> 1 + T end. - -absolute_path(RelPath) -> - filename:join(absolute_path([], filename:split(filename:absname(RelPath)))). - -absolute_path([_ | ResultParts], [".." | Parts]) -> - absolute_path(ResultParts, Parts); -absolute_path([], [".." | Parts]) -> - absolute_path([], Parts); -absolute_path(ResultParts, ["." | Parts]) -> - absolute_path(ResultParts, Parts); -absolute_path(ResultParts, [Part | Parts]) -> - absolute_path([Part | ResultParts], Parts); -absolute_path(ResultParts, []) -> - lists:reverse(ResultParts). -- cgit v1.2.1 From 562eeaf6ea09d0112f59a6086ba6e820203be4c0 Mon Sep 17 00:00:00 2001 From: Vlad Ionescu Date: Wed, 23 Sep 2009 18:27:31 +0100 Subject: comment for create-plt make target --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index eab81cb0..57b2a793 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ dialyze: $(BEAM_TARGETS) $(BASIC_PLT) $(ERL_EBIN) -eval \ "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\"))." +# rabbit.plt is used by rabbitmq-erlang-client's dialyze make target create-plt: $(RABBIT_PLT) $(RABBIT_PLT): $(BEAM_TARGETS) $(BASIC_PLT) -- cgit v1.2.1 From 5e55c7df8d5536c1260f9baa2eb553b033b020a6 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 24 Sep 2009 06:52:47 +0100 Subject: cosmetic --- src/rabbit_dialyzer.erl | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl index c75a001b..23e6fc44 100644 --- a/src/rabbit_dialyzer.erl +++ b/src/rabbit_dialyzer.erl @@ -48,50 +48,42 @@ %%---------------------------------------------------------------------------- create_basic_plt(BasicPltPath) -> - OptsRecord = dialyzer_options:build([ - {analysis_type, plt_build}, - {output_plt, BasicPltPath}, - {files_rec, otp_apps_dependencies_paths()}]), + OptsRecord = dialyzer_options:build( + [{analysis_type, plt_build}, + {output_plt, BasicPltPath}, + {files_rec, otp_apps_dependencies_paths()}]), dialyzer_cl:start(OptsRecord), ok. add_to_plt(PltPath, FilesString) -> {ok, Files} = regexp:split(FilesString, " "), - DialyzerWarnings = dialyzer:run([ - {analysis_type, plt_add}, - {init_plt, PltPath}, - {output_plt, PltPath}, - {files, Files}]), + DialyzerWarnings = dialyzer:run([{analysis_type, plt_add}, + {init_plt, PltPath}, + {output_plt, PltPath}, + {files, Files}]), print_warnings(DialyzerWarnings), ok. dialyze_files(PltPath, ModifiedFiles) -> {ok, Files} = regexp:split(ModifiedFiles, " "), - DialyzerWarnings = dialyzer:run([ - {init_plt, PltPath}, - {files, Files}]), + DialyzerWarnings = dialyzer:run([{init_plt, PltPath}, + {files, Files}]), case DialyzerWarnings of - [] -> - io:format("Ok, dialyzer returned no warnings.~n", []), - ok; - _ -> - io:format("~nFAILED! dialyzer returned the following warnings:~n", []), - print_warnings(DialyzerWarnings), - fail + [] -> io:format("~nOk~n"), + ok; + _ -> io:format("~nFAILED with the following warnings:~n"), + print_warnings(DialyzerWarnings), + fail end. -print_warnings(DialyzerWarnings) -> - lists:foreach( - fun - (Warning) -> io:format("~s", [dialyzer:format_warning(Warning)]) - end, - DialyzerWarnings), - io:format("~n", []), +print_warnings(Warnings) -> + [io:format("~s", [dialyzer:format_warning(W)]) || W <- Warnings], + io:format("~n"), ok. otp_apps_dependencies_paths() -> [code:lib_dir(App, ebin) || - App <- [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]]. + App <- [kernel, stdlib, sasl, mnesia, os_mon, ssl, eunit, tools]]. halt_with_code(ok) -> halt(); -- cgit v1.2.1 From f2fd881c9bafa8ca8df21d37ae2ba01d965771ce Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Thu, 24 Sep 2009 08:14:08 +0100 Subject: Removed redundant -s rabbit from the startup args in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 57b2a793..c98a45ba 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ BASIC_SCRIPT_ENVIRONMENT_SETTINGS=\ run: all $(BASIC_SCRIPT_ENVIRONMENT_SETTINGS) \ RABBITMQ_ALLOW_INPUT=true \ - RABBITMQ_SERVER_START_ARGS="$(RABBITMQ_SERVER_START_ARGS) -s rabbit" \ + RABBITMQ_SERVER_START_ARGS="$(RABBITMQ_SERVER_START_ARGS)" \ ./scripts/rabbitmq-server run-node: all -- cgit v1.2.1 From 95a97da5af4a488cc1ce62476ea6d518bb61d310 Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Thu, 24 Sep 2009 10:16:44 +0100 Subject: Added pod file to describe rabbitmq-deactivate-plugins --- docs/rabbitmq-activate-plugins.1.pod | 2 +- docs/rabbitmq-deactivate-plugins.1.pod | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/rabbitmq-deactivate-plugins.1.pod diff --git a/docs/rabbitmq-activate-plugins.1.pod b/docs/rabbitmq-activate-plugins.1.pod index 58ffea79..42f0c4d2 100644 --- a/docs/rabbitmq-activate-plugins.1.pod +++ b/docs/rabbitmq-activate-plugins.1.pod @@ -26,7 +26,7 @@ execute: =head1 SEE ALSO L, L, L, -L +L, L =head1 AUTHOR diff --git a/docs/rabbitmq-deactivate-plugins.1.pod b/docs/rabbitmq-deactivate-plugins.1.pod new file mode 100644 index 00000000..eb4fbb90 --- /dev/null +++ b/docs/rabbitmq-deactivate-plugins.1.pod @@ -0,0 +1,37 @@ +=head1 NAME + +rabbitmq-deactivate-plugins - command line tool for deactivating plugins +in a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmq-deactivate-plugins + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmq-deactivate-plugins is a command line tool for deactivating +plugins installed into the broker. + +=head1 EXAMPLES + +To deactivate all of the installed plugins in the current RabbitMQ install, +execute: + + rabbitmq-deactivate-plugins + +=head1 SEE ALSO + +L, L, L, +L, L + +=head1 AUTHOR + +The RabbitMQ Team + +=head1 REFERENCES + +RabbitMQ Web Site: L -- cgit v1.2.1 From 11162837adfbd97da08c20d12be96900363ebbf9 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 28 Sep 2009 16:15:10 +0100 Subject: produce error 2-tuple since that is expected by things like application:start --- src/rabbit_networking.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl index eed21a01..1dd93518 100644 --- a/src/rabbit_networking.erl +++ b/src/rabbit_networking.erl @@ -101,7 +101,7 @@ check_tcp_listener_address(NamePrefix, Host, Port) -> if is_integer(Port) andalso (Port >= 0) andalso (Port =< 65535) -> ok; true -> error_logger:error_msg("invalid port ~p - not 0..65535~n", [Port]), - throw({error, invalid_port, Port}) + throw({error, {invalid_port, Port}}) end, Name = rabbit_misc:tcp_name(NamePrefix, IPAddress, Port), {IPAddress, Name}. -- cgit v1.2.1 From e4cc07157d01016d2db23a0829a754a97c92f2db Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 29 Sep 2009 12:56:42 +0100 Subject: do not ignore error on 'rabbitmqctl status' --- src/rabbit_control.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 69e91803..f701c4aa 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -197,9 +197,11 @@ action(cluster, Node, ClusterNodeSs, Inform) -> action(status, Node, [], Inform) -> Inform("Status of node ~p", [Node]), - Res = call(Node, {rabbit, status, []}), - io:format("~p~n", [Res]), - ok; + case call(Node, {rabbit, status, []}) of + {badrpc, _} = Res -> Res; + Res -> io:format("~p~n", [Res]), + ok + end; action(rotate_logs, Node, [], Inform) -> Inform("Reopening logs for node ~p", [Node]), -- cgit v1.2.1 From fd4b84e0cbe06dc2c0f61e1748acbbfb6231f2c6 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 29 Sep 2009 14:49:25 +0100 Subject: display helpful diagnostics on badrpc error in rabbitmqctl --- src/rabbit.erl | 8 ++++++++ src/rabbit_control.erl | 29 +++++++++++++++++++++++++++-- src/rabbit_misc.erl | 14 ++++++++++---- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 27f085c2..b098fd5a 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -219,6 +219,12 @@ app_location() -> {ok, Application} = application:get_application(), filename:absname(code:where_is_file(atom_to_list(Application) ++ ".app")). +home_dir() -> + case init:get_argument(home) of + {ok, [[Home]]} -> Home; + Other -> Other + end. + %--------------------------------------------------------------------------- print_banner() -> @@ -243,6 +249,8 @@ print_banner() -> ?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]), Settings = [{"node", node()}, {"app descriptor", app_location()}, + {"home dir", home_dir()}, + {"cookie hash", rabbit_misc:cookie_hash()}, {"log", log_location(kernel)}, {"sasl log", log_location(sasl)}, {"database dir", rabbit_mnesia:dir()}], diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index f701c4aa..a15c7fd8 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -80,13 +80,38 @@ start() -> {error, Reason} -> error("~p", [Reason]), halt(2); + {badrpc, Reason} -> + error("unable to connect to node ~w: ~w", [Node, Reason]), + print_badrpc_diagnostics(Node), + halt(2); Other -> error("~p", [Other]), halt(2) end. -error(Format, Args) -> - rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args). +fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args). + +error(Format, Args) -> fmt_stderr("Error: " ++ Format, Args). + +print_badrpc_diagnostics(Node) -> + fmt_stderr("diagnostics:", []), + NodeHost = rabbit_misc:nodehost(Node), + case net_adm:names(NodeHost) of + {error, EpmdReason} -> + fmt_stderr("- unable to connect to epmd on ~s: ~w", + [NodeHost, EpmdReason]); + {ok, NamePorts} -> + fmt_stderr("- nodes and their ports on ~s: ~p", + [NodeHost, [{list_to_atom(Name), Port} || + {Name, Port} <- NamePorts]]) + end, + fmt_stderr("- current node: ~w", [node()]), + case init:get_argument(home) of + {ok, [[Home]]} -> fmt_stderr("- current node home dir: ~s", [Home]); + Other -> fmt_stderr("- no current node home dir: ~p", [Other]) + end, + fmt_stderr("- current node cookie hash: ~s", [rabbit_misc:cookie_hash()]), + ok. parse_args(["-n", NodeS | Args], Params) -> Node = case lists:member($@, NodeS) of diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 58431438..b20e9a86 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -47,7 +47,7 @@ -export([with_user/2, with_vhost/2, with_user_and_vhost/3]). -export([execute_mnesia_transaction/1]). -export([ensure_ok/2]). --export([localnode/1, tcp_name/3]). +-export([localnode/1, nodehost/1, cookie_hash/0, tcp_name/3]). -export([intersperse/2, upmap/2, map_in_order/2]). -export([table_foreach/2]). -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). @@ -106,6 +106,8 @@ -spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). -spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok'). -spec(localnode/1 :: (atom()) -> erlang_node()). +-spec(nodehost/1 :: (erlang_node()) -> string()). +-spec(cookie_hash/0 :: () -> string()). -spec(tcp_name/3 :: (atom(), ip_address(), ip_port()) -> atom()). -spec(intersperse/2 :: (A, [A]) -> [A]). -spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]). @@ -307,11 +309,15 @@ ensure_ok(ok, _) -> ok; ensure_ok({error, Reason}, ErrorTag) -> throw({error, {ErrorTag, Reason}}). localnode(Name) -> + list_to_atom(lists:append([atom_to_list(Name), "@", nodehost(node())])). + +nodehost(Node) -> %% This is horrible, but there doesn't seem to be a way to split a %% nodename into its constituent parts. - list_to_atom(lists:append(atom_to_list(Name), - lists:dropwhile(fun (E) -> E =/= $@ end, - atom_to_list(node())))). + tl(lists:dropwhile(fun (E) -> E =/= $@ end, atom_to_list(Node))). + +cookie_hash() -> + ssl_base64:encode(erlang:md5(atom_to_list(erlang:get_cookie()))). tcp_name(Prefix, IPAddress, Port) when is_atom(Prefix) andalso is_number(Port) -> -- cgit v1.2.1 From fe8547dbc3bd88e3bceb30abfed1041af3aab293 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 30 Sep 2009 00:12:05 +0100 Subject: cosmetic --- src/rabbit_networking.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl index 1dd93518..4bbdb65e 100644 --- a/src/rabbit_networking.erl +++ b/src/rabbit_networking.erl @@ -39,8 +39,8 @@ %%used by TCP-based transports, e.g. STOMP adapter -export([check_tcp_listener_address/3]). --export([tcp_listener_started/2, ssl_connection_upgrade/2, - tcp_listener_stopped/2, start_client/1]). +-export([tcp_listener_started/2, tcp_listener_stopped/2, + start_client/1, start_ssl_client/2]). -include("rabbit.hrl"). -include_lib("kernel/include/inet.hrl"). @@ -112,7 +112,7 @@ start_tcp_listener(Host, Port) -> start_ssl_listener(Host, Port, SslOpts) -> start_listener(Host, Port, "SSL Listener", - {?MODULE, ssl_connection_upgrade, [SslOpts]}). + {?MODULE, start_ssl_client, [SslOpts]}). start_listener(Host, Port, Label, OnConnect) -> {IPAddress, Name} = @@ -166,7 +166,7 @@ start_client(Sock) -> Child ! {go, Sock}, Child. -ssl_connection_upgrade(SslOpts, Sock) -> +start_ssl_client(SslOpts, Sock) -> {ok, {PeerAddress, PeerPort}} = rabbit_net:peername(Sock), PeerIp = inet_parse:ntoa(PeerAddress), -- cgit v1.2.1 From 6da50e1065166563468de17a2076c9769edb280d Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 30 Sep 2009 09:52:42 +0100 Subject: s/bool()/boolean() in type specs since in R13B02 erlc spits out deprecation warnings otherwise --- Makefile | 4 ++-- include/rabbit.hrl | 14 +++++++------- src/priority_queue.erl | 4 ++-- src/rabbit_alarm.erl | 2 +- src/rabbit_amqqueue.erl | 12 ++++++------ src/rabbit_basic.erl | 5 +++-- src/rabbit_channel.erl | 4 ++-- src/rabbit_exchange.erl | 8 ++++---- src/rabbit_limiter.erl | 2 +- src/rabbit_mnesia.erl | 2 +- 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index bf78b1cc..125761d8 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,10 @@ RABBIT_PLT=rabbit.plt ifndef USE_SPECS # our type specs rely on features / bug fixes in dialyzer that are -# only available in R13B upwards (R13B is eshell 5.7.1) +# only available in R13B01 upwards (R13B01 is eshell 5.7.2) # # NB: the test assumes that version number will only contain single digits -USE_SPECS=$(shell if [ $$(erl -noshell -eval 'io:format(erlang:system_info(version)), halt().') \> "5.7.0" ]; then echo "true"; else echo "false"; fi) +USE_SPECS=$(shell if [ $$(erl -noshell -eval 'io:format(erlang:system_info(version)), halt().') \> "5.7.1" ]; then echo "true"; else echo "false"; fi) endif #other args: +native +"{hipe,[o3,verbose]}" -Ddebug=true +debug_info +no_strict_record_tests diff --git a/include/rabbit.hrl b/include/rabbit.hrl index c95ce738..5703d0d6 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -103,15 +103,15 @@ read :: regexp()}). -type(amqqueue() :: #amqqueue{name :: queue_name(), - durable :: bool(), - auto_delete :: bool(), + durable :: boolean(), + auto_delete :: boolean(), arguments :: amqp_table(), pid :: maybe(pid())}). -type(exchange() :: #exchange{name :: exchange_name(), type :: exchange_type(), - durable :: bool(), - auto_delete :: bool(), + durable :: boolean(), + auto_delete :: boolean(), arguments :: amqp_table()}). -type(binding() :: #binding{exchange_name :: exchange_name(), @@ -141,14 +141,14 @@ persistent_key :: maybe(pkey())}). -type(message() :: basic_message()). -type(delivery() :: - #delivery{mandatory :: bool(), - immediate :: bool(), + #delivery{mandatory :: boolean(), + immediate :: boolean(), txn :: maybe(txn()), sender :: pid(), message :: message()}). %% this really should be an abstract type -type(msg_id() :: non_neg_integer()). --type(msg() :: {queue_name(), pid(), msg_id(), bool(), message()}). +-type(msg() :: {queue_name(), pid(), msg_id(), boolean(), message()}). -type(listener() :: #listener{node :: erlang_node(), protocol :: atom(), diff --git a/src/priority_queue.erl b/src/priority_queue.erl index c74b39a9..74b41a91 100644 --- a/src/priority_queue.erl +++ b/src/priority_queue.erl @@ -67,8 +67,8 @@ -type(pqueue() :: squeue() | {pqueue, [{priority(), squeue()}]}). -spec(new/0 :: () -> pqueue()). --spec(is_queue/1 :: (any()) -> bool()). --spec(is_empty/1 :: (pqueue()) -> bool()). +-spec(is_queue/1 :: (any()) -> boolean()). +-spec(is_empty/1 :: (pqueue()) -> boolean()). -spec(len/1 :: (pqueue()) -> non_neg_integer()). -spec(to_list/1 :: (pqueue()) -> [{priority(), any()}]). -spec(in/2 :: (any(), pqueue()) -> pqueue()). diff --git a/src/rabbit_alarm.erl b/src/rabbit_alarm.erl index 309c9a0e..7a2fbcb8 100644 --- a/src/rabbit_alarm.erl +++ b/src/rabbit_alarm.erl @@ -50,7 +50,7 @@ -ifdef(use_specs). -type(mfa_tuple() :: {atom(), atom(), list()}). --spec(start/1 :: (bool() | 'auto') -> 'ok'). +-spec(start/1 :: (boolean() | 'auto') -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(register/2 :: (pid(), mfa_tuple()) -> 'ok'). diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index f05f7880..1a5e82d7 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -63,7 +63,7 @@ -spec(start/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(declare/4 :: (queue_name(), bool(), bool(), amqp_table()) -> +-spec(declare/4 :: (queue_name(), boolean(), boolean(), amqp_table()) -> amqqueue()). -spec(lookup/1 :: (queue_name()) -> {'ok', amqqueue()} | not_found()). -spec(with/2 :: (queue_name(), qfun(A)) -> A | not_found()). @@ -83,8 +83,8 @@ {'error', 'in_use'} | {'error', 'not_empty'}). -spec(purge/1 :: (amqqueue()) -> qlen()). --spec(deliver/2 :: (pid(), delivery()) -> bool()). --spec(redeliver/2 :: (pid(), [{message(), bool()}]) -> 'ok'). +-spec(deliver/2 :: (pid(), delivery()) -> boolean()). +-spec(redeliver/2 :: (pid(), [{message(), boolean()}]) -> 'ok'). -spec(requeue/3 :: (pid(), [msg_id()], pid()) -> 'ok'). -spec(ack/4 :: (pid(), maybe(txn()), [msg_id()], pid()) -> 'ok'). -spec(commit_all/2 :: ([pid()], txn()) -> ok_or_errors()). @@ -92,16 +92,16 @@ -spec(notify_down_all/2 :: ([pid()], pid()) -> ok_or_errors()). -spec(limit_all/3 :: ([pid()], pid(), pid() | 'undefined') -> ok_or_errors()). -spec(claim_queue/2 :: (amqqueue(), pid()) -> 'ok' | 'locked'). --spec(basic_get/3 :: (amqqueue(), pid(), bool()) -> +-spec(basic_get/3 :: (amqqueue(), pid(), boolean()) -> {'ok', non_neg_integer(), msg()} | 'empty'). -spec(basic_consume/8 :: - (amqqueue(), bool(), pid(), pid(), pid(), ctag(), bool(), any()) -> + (amqqueue(), boolean(), pid(), pid(), pid(), ctag(), boolean(), any()) -> 'ok' | {'error', 'queue_owned_by_another_connection' | 'exclusive_consume_unavailable'}). -spec(basic_cancel/4 :: (amqqueue(), pid(), ctag(), any()) -> 'ok'). -spec(notify_sent/2 :: (pid(), pid()) -> 'ok'). -spec(unblock/2 :: (pid(), pid()) -> 'ok'). --spec(internal_declare/2 :: (amqqueue(), bool()) -> amqqueue()). +-spec(internal_declare/2 :: (amqqueue(), boolean()) -> amqqueue()). -spec(internal_delete/1 :: (queue_name()) -> 'ok' | not_found()). -spec(on_node_down/1 :: (erlang_node()) -> 'ok'). -spec(pseudo_queue/2 :: (binary(), pid()) -> amqqueue()). diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index 4033aaaf..bec2cd08 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -45,13 +45,14 @@ -type(publish_result() :: ({ok, routing_result(), [pid()]} | not_found())). -spec(publish/1 :: (delivery()) -> publish_result()). --spec(delivery/4 :: (bool(), bool(), maybe(txn()), message()) -> delivery()). +-spec(delivery/4 :: (boolean(), boolean(), maybe(txn()), message()) -> + delivery()). -spec(message/4 :: (exchange_name(), routing_key(), properties_input(), binary()) -> message()). -spec(properties/1 :: (properties_input()) -> amqp_properties()). -spec(publish/4 :: (exchange_name(), routing_key(), properties_input(), binary()) -> publish_result()). --spec(publish/7 :: (exchange_name(), routing_key(), bool(), bool(), +-spec(publish/7 :: (exchange_name(), routing_key(), boolean(), boolean(), maybe(txn()), properties_input(), binary()) -> publish_result()). -spec(build_content/2 :: (amqp_properties(), binary()) -> content()). diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index a1fa1066..d7eaf37c 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -60,8 +60,8 @@ -spec(do/3 :: (pid(), amqp_method(), maybe(content())) -> 'ok'). -spec(shutdown/1 :: (pid()) -> 'ok'). -spec(send_command/2 :: (pid(), amqp_method()) -> 'ok'). --spec(deliver/4 :: (pid(), ctag(), bool(), msg()) -> 'ok'). --spec(conserve_memory/2 :: (pid(), bool()) -> 'ok'). +-spec(deliver/4 :: (pid(), ctag(), boolean(), msg()) -> 'ok'). +-spec(conserve_memory/2 :: (pid(), boolean()) -> 'ok'). -endif. diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 8fb9eae3..33dea8c7 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -61,7 +61,7 @@ 'exchange_not_found' | 'exchange_and_queue_not_found'}). -spec(recover/0 :: () -> 'ok'). --spec(declare/5 :: (exchange_name(), exchange_type(), bool(), bool(), +-spec(declare/5 :: (exchange_name(), exchange_type(), boolean(), boolean(), amqp_table()) -> exchange()). -spec(check_type/1 :: (binary()) -> atom()). -spec(assert_type/2 :: (exchange(), atom()) -> 'ok'). @@ -83,9 +83,9 @@ [{exchange_name(), queue_name(), routing_key(), amqp_table()}]). -spec(delete_queue_bindings/1 :: (queue_name()) -> 'ok'). -spec(delete_transient_queue_bindings/1 :: (queue_name()) -> 'ok'). --spec(topic_matches/2 :: (binary(), binary()) -> bool()). --spec(headers_match/2 :: (amqp_table(), amqp_table()) -> bool()). --spec(delete/2 :: (exchange_name(), bool()) -> +-spec(topic_matches/2 :: (binary(), binary()) -> boolean()). +-spec(headers_match/2 :: (amqp_table(), amqp_table()) -> boolean()). +-spec(delete/2 :: (exchange_name(), boolean()) -> 'ok' | not_found() | {'error', 'in_use'}). -spec(list_queue_bindings/1 :: (queue_name()) -> [{exchange_name(), routing_key(), amqp_table()}]). diff --git a/src/rabbit_limiter.erl b/src/rabbit_limiter.erl index 9f3dcbd0..087a9f64 100644 --- a/src/rabbit_limiter.erl +++ b/src/rabbit_limiter.erl @@ -47,7 +47,7 @@ -spec(start_link/1 :: (pid()) -> pid()). -spec(shutdown/1 :: (maybe_pid()) -> 'ok'). -spec(limit/2 :: (maybe_pid(), non_neg_integer()) -> 'ok'). --spec(can_send/3 :: (maybe_pid(), pid(), bool()) -> bool()). +-spec(can_send/3 :: (maybe_pid(), pid(), boolean()) -> boolean()). -spec(ack/2 :: (maybe_pid(), non_neg_integer()) -> 'ok'). -spec(register/2 :: (maybe_pid(), pid()) -> 'ok'). -spec(unregister/2 :: (maybe_pid(), pid()) -> 'ok'). diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 37e20335..c4d5aac6 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -50,7 +50,7 @@ -spec(dir/0 :: () -> string()). -spec(ensure_mnesia_dir/0 :: () -> 'ok'). -spec(init/0 :: () -> 'ok'). --spec(is_db_empty/0 :: () -> bool()). +-spec(is_db_empty/0 :: () -> boolean()). -spec(cluster/1 :: ([erlang_node()]) -> 'ok'). -spec(reset/0 :: () -> 'ok'). -spec(force_reset/0 :: () -> 'ok'). -- cgit v1.2.1