Skip to content

Instantly share code, notes, and snippets.

@ztmr
Created June 26, 2013 18:43
Show Gist options
  • Save ztmr/5870171 to your computer and use it in GitHub Desktop.
Save ztmr/5870171 to your computer and use it in GitHub Desktop.
Erlang Restricted Shell Module -- as mentioned in [erlang-programming groups.](https://groups.google.com/d/msg/erlang-programming/LI3O8VwMbGc/LDPm6fkUEy0J)
-module (restricted_shell).
-export ([local_allowed/3, non_local_allowed/3]).
-export ([lock/0, unlock/0, is_locked/0]).
-define (APP, 'SuperCluster').
-define (IS_LOCKED, 'restricted.is_locked').
local_allowed (q, [], _State) ->
{not is_locked (), _State};
local_allowed ({init, stop}, [], _State) ->
{not is_locked (), _State};
local_allowed (_Func, _ArgList, _State) ->
{true, _State}.
non_local_allowed (q, [], _State) ->
{not is_locked (), _State};
non_local_allowed ({init, stop}, [], _State) ->
{not is_locked (), _State};
non_local_allowed (_Func, _ArgList, _State) ->
{true, _State}.
is_locked () ->
{ok, false} =/= application:get_env (?APP, ?IS_LOCKED).
lock () -> application:set_env (?APP, ?IS_LOCKED, true).
unlock () -> application:set_env (?APP, ?IS_LOCKED, false).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment