os_mon & alarm_handler in R10B-10

Gunilla Arendt gunilla@REDACTED
Mon Mar 27 09:08:42 CEST 2006


It's a bug in os_mon, it shouldn't use get_alarms().
Thanks for the heads up.

Regards, Gunilla


Serge Aleynikov wrote:
> For now I used the following patch to take care of this issue, but I 
> would be curious to hear the opinion of the OTP staff.
> 
> Regards,
> 
> Serge
> 
> --- alarm_handler.erl.orig      Fri Mar 24 20:08:18 2006
> +++ alarm_handler.erl   Fri Mar 24 20:19:15 2006
> @@ -58,7 +58,12 @@
>  %% Returns: [{AlarmId, AlarmDesc}]
>  %%-----------------------------------------------------------------
>  get_alarms() ->
> -    gen_event:call(alarm_handler, alarm_handler, get_alarms).
> +    case gen_event:which_handlers(alarm_handler) of
> +    [M | _] ->
> +        gen_event:call(alarm_handler, M, get_alarms);
> +    [] ->
> +        []
> +    end.
> 
>  add_alarm_handler(Module) when atom(Module) ->
>      gen_event:add_handler(alarm_handler, Module, []).
> 
> 
> Serge Aleynikov wrote:
>> Hi,
>>
>> I've been experimenting with the reworked os_mon in R10B-10, and 
>> encountered the following issue.
>>
>> The documentation encourages to replace the default alarm handler with 
>> something more sophisticated.  For that reason I created a custom 
>> handler - lama_alarm_h (LAMA app in jungerl), which uses 
>> gen_event:swap_sup_handler/3.
>>
>> I initiate that handler prior to starting OS_MON, and then start OS_MON.
>>
>> In the latest release R10B-10, OS_MON calls alarm_handler:get_alarms/0 
>> upon startup.
>>
>> This causes the 'alarm_handler' event manager issue a call in the 
>> alarm_handler.erl module.  However, since that handler was replaced by 
>> a custom alarm handler, the gen_event's call fails with
>> {error, bad_module}.
>>
>> gen_event always dispatches a call/3 to a specific handler module 
>> passed as a parameter, e.g.:
>>
>> -----[alarm_handler.erl (line: 60)]-----
>> get_alarms() ->
>>     gen_event:call(alarm_handler, alarm_handler, get_alarms).
>> ----------------------------------------
>>
>> Yet, if the alarm_handler handler was swapped by another module, the 
>> gen_event:call will report an error, therefore crashing OS_MON.
>>
>> One way to resolve this problem would be to introduce another exported 
>> function in gen_event:
>>
>> gen_event:call(EventMgrRef, Request) -> Result
>>
>> Can the OTP team suggest some other workaround?
>>
>> Serge
>>
> 




More information about the erlang-questions mailing list