summaryrefslogtreecommitdiff
path: root/priv/templates
diff options
context:
space:
mode:
Diffstat (limited to 'priv/templates')
-rw-r--r--priv/templates/basicnif.c34
-rw-r--r--priv/templates/basicnif.erl28
-rw-r--r--priv/templates/simplefsm.erl22
-rw-r--r--priv/templates/simplemod.erl2
-rw-r--r--priv/templates/simplenode.erl.script6
-rwxr-xr-xpriv/templates/simplenode.runner31
-rw-r--r--priv/templates/simplesrv.erl17
7 files changed, 86 insertions, 54 deletions
diff --git a/priv/templates/basicnif.c b/priv/templates/basicnif.c
index 36bf938..a4a65be 100644
--- a/priv/templates/basicnif.c
+++ b/priv/templates/basicnif.c
@@ -1,4 +1,3 @@
-
#include "erl_nif.h"
static ErlNifResourceType* {{module}}_RESOURCE;
@@ -8,8 +7,10 @@ typedef struct
} {{module}}_handle;
// Prototypes
-ERL_NIF_TERM {{module}}_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
-ERL_NIF_TERM {{module}}_myfunction(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
+static ERL_NIF_TERM {{module}}_new(ErlNifEnv* env, int argc,
+ const ERL_NIF_TERM argv[]);
+static ERL_NIF_TERM {{module}}_myfunction(ErlNifEnv* env, int argc,
+ const ERL_NIF_TERM argv[]);
static ErlNifFunc nif_funcs[] =
{
@@ -17,34 +18,39 @@ static ErlNifFunc nif_funcs[] =
{"myfunction", 1, {{module}}_myfunction}
};
-ERL_NIF_TERM {{module}}_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM {{module}}_new(ErlNifEnv* env, int argc,
+ const ERL_NIF_TERM argv[])
{
- {{module}}_handle* handle = enif_alloc_resource(env,
- {{module}}_RESOURCE,
+ {{module}}_handle* handle = enif_alloc_resource({{module}}_RESOURCE,
sizeof({{module}}_handle));
ERL_NIF_TERM result = enif_make_resource(env, handle);
- enif_release_resource(env, handle);
+ enif_release_resource(handle);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), result);
}
-ERL_NIF_TERM {{module}}_myfunction(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM {{module}}_myfunction(ErlNifEnv* env, int argc,
+ const ERL_NIF_TERM argv[])
{
return enif_make_atom(env, "ok");
}
static void {{module}}_resource_cleanup(ErlNifEnv* env, void* arg)
{
- // Delete any dynamically allocated memory stored in {{module}}_handle
- // {{module}}_handle* handle = ({{module}}_handle*)arg;
+ /* Delete any dynamically allocated memory stored in {{module}}_handle */
+ /* {{module}}_handle* handle = ({{module}}_handle*)arg; */
}
static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
- {{module}}_RESOURCE = enif_open_resource_type(env, "{{module}}_resource",
- &{{module}}_resource_cleanup,
- ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER,
- 0);
+ ErlNifResourceFlags flags = ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER;
+ ErlNifResourceType* rt = enif_open_resource_type(env, NULL,
+ "{{module}}_resource",
+ &{{module}}_resource_cleanup,
+ flags, NULL);
+ if (rt == NULL)
+ return -1;
+
return 0;
}
diff --git a/priv/templates/basicnif.erl b/priv/templates/basicnif.erl
index 5f1ce11..e1f4143 100644
--- a/priv/templates/basicnif.erl
+++ b/priv/templates/basicnif.erl
@@ -5,24 +5,30 @@
-on_load(init/0).
+-define(nif_stub, nif_stub_error(?LINE)).
+nif_stub_error(Line) ->
+ erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
+
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
init() ->
- case code:priv_dir({{module}}) of
- {error, bad_name} ->
- SoName = filename:join("../priv", {{module}});
- Dir ->
- SoName = filename:join(Dir, {{module}})
- end,
- erlang:load_nif(SoName, 0).
+ PrivDir = case code:priv_dir(?MODULE) of
+ {error, bad_name} ->
+ EbinDir = filename:dirname(code:which(?MODULE)),
+ AppPath = filename:dirname(EbinDir),
+ filename:join(AppPath, "priv");
+ Path ->
+ Path
+ end,
+ erlang:load_nif(filename:join(PrivDir, ?MODULE), 0).
new() ->
- "NIF library not loaded".
+ ?nif_stub.
-myfunction(Ref) ->
- "NIF library not loaded".
+myfunction(_Ref) ->
+ ?nif_stub.
%% ===================================================================
%% EUnit tests
@@ -31,6 +37,6 @@ myfunction(Ref) ->
basic_test() ->
{ok, Ref} = new(),
- ok = myfunction(Ref).
+ ?assertEqual(ok, myfunction(Ref)).
-endif.
diff --git a/priv/templates/simplefsm.erl b/priv/templates/simplefsm.erl
index 039532c..776081e 100644
--- a/priv/templates/simplefsm.erl
+++ b/priv/templates/simplefsm.erl
@@ -12,42 +12,44 @@
%% gen_fsm Function Exports
%% ------------------------------------------------------------------
--export([init/1, state_name/2, state_name/3, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]).
+-export([init/1, state_name/2, state_name/3, handle_event/3,
+ handle_sync_event/4, handle_info/3, terminate/3,
+ code_change/4]).
%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------
start_link() ->
- gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], []).
+ gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], []).
%% ------------------------------------------------------------------
%% gen_fsm Function Definitions
%% ------------------------------------------------------------------
init(_Args) ->
- {ok, initial_state_name, initial_state}.
+ {ok, initial_state_name, initial_state}.
state_name(_Event, State) ->
- {next_state, state_name, State}.
+ {next_state, state_name, State}.
state_name(_Event, _From, State) ->
- {reply, ok, state_name, State}.
+ {reply, ok, state_name, State}.
handle_event(_Event, StateName, State) ->
- {next_state, StateName, State}.
+ {next_state, StateName, State}.
handle_sync_event(_Event, _From, StateName, State) ->
- {reply, ok, StateName, State}.
+ {reply, ok, StateName, State}.
handle_info(_Info, StateName, State) ->
- {next_state, StateName, State}.
+ {next_state, StateName, State}.
terminate(_Reason, _StateName, _State) ->
- ok.
+ ok.
code_change(_OldVsn, StateName, State, _Extra) ->
- {ok, StateName, State}.
+ {ok, StateName, State}.
%% ------------------------------------------------------------------
%% Internal Function Definitions
diff --git a/priv/templates/simplemod.erl b/priv/templates/simplemod.erl
index 2baff59..99d0196 100644
--- a/priv/templates/simplemod.erl
+++ b/priv/templates/simplemod.erl
@@ -7,4 +7,4 @@
-endif.
my_func() ->
- ok.
+ ok.
diff --git a/priv/templates/simplenode.erl.script b/priv/templates/simplenode.erl.script
index e500626..6f65e3f 100644
--- a/priv/templates/simplenode.erl.script
+++ b/priv/templates/simplenode.erl.script
@@ -1,10 +1,10 @@
-#!/bin/bash
+#!/bin/sh
## This script replaces the default "erl" in erts-VSN/bin. This is necessary
## as escript depends on erl and in turn, erl depends on having access to a
## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect
## of running escript -- the embedded node bypasses erl and uses erlexec directly
-## (as it should).
+## (as it should).
##
## Note that this script makes the assumption that there is a start_clean.boot
## file available in $ROOTDIR/release/VSN.
@@ -31,4 +31,4 @@ export ROOTDIR
export BINDIR
export PROGNAME
-exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"} \ No newline at end of file
+exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"}
diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner
index 4b1efa2..bacce8d 100755
--- a/priv/templates/simplenode.runner
+++ b/priv/templates/simplenode.runner
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# -*- tab-width:4;indent-tabs-mode:nil -*-
# ex: ts=4 sw=4 et
@@ -23,14 +23,14 @@ cd $RUNNER_BASE_DIR
mkdir -p $RUNNER_LOG_DIR
# Extract the target node name from node.args
-NAME_ARG=`egrep -e '^-s?name' $RUNNER_ETC_DIR/vm.args`
+NAME_ARG=`egrep '^-s?name' $RUNNER_ETC_DIR/vm.args`
if [ -z "$NAME_ARG" ]; then
echo "vm.args needs to have either -name or -sname parameter."
exit 1
fi
# Extract the target cookie
-COOKIE_ARG=`grep -e '^-setcookie' $RUNNER_ETC_DIR/vm.args`
+COOKIE_ARG=`grep '^-setcookie' $RUNNER_ETC_DIR/vm.args`
if [ -z "$COOKIE_ARG" ]; then
echo "vm.args needs to have a -setcookie parameter."
exit 1
@@ -85,6 +85,10 @@ case "$1" in
;;
esac
$NODETOOL stop
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
while `kill -0 $PID 2>/dev/null`;
do
sleep 1
@@ -94,28 +98,41 @@ case "$1" in
restart)
## Restart the VM without exiting the process
$NODETOOL restart
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
;;
reboot)
## Restart the VM completely (uses heart to restart it)
$NODETOOL reboot
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
;;
ping)
## See if the VM is alive
$NODETOOL ping
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
+ exit $ES
+ fi
;;
attach)
# Make sure a node IS running
RES=`$NODETOOL ping`
- if [ "$RES" != "pong" ]; then
+ ES=$?
+ if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
- exit 1
+ exit $ES
fi
shift
- $ERTS_PATH/to_erl $PIPE_DIR
+ exec $ERTS_PATH/to_erl $PIPE_DIR
;;
console|console_clean)
@@ -130,7 +147,7 @@ case "$1" in
BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\\///'`
- CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -embedded -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
+ CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
export EMU
export ROOTDIR
export BINDIR
diff --git a/priv/templates/simplesrv.erl b/priv/templates/simplesrv.erl
index 8db932e..a4ab77a 100644
--- a/priv/templates/simplesrv.erl
+++ b/priv/templates/simplesrv.erl
@@ -12,36 +12,37 @@
%% gen_server Function Exports
%% ------------------------------------------------------------------
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------
start_link() ->
- gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
%% ------------------------------------------------------------------
%% gen_server Function Definitions
%% ------------------------------------------------------------------
init(Args) ->
- {ok, Args}.
+ {ok, Args}.
handle_call(_Request, _From, State) ->
- {noreply, ok, State}.
+ {noreply, ok, State}.
handle_cast(_Msg, State) ->
- {noreply, State}.
+ {noreply, State}.
handle_info(_Info, State) ->
- {noreply, State}.
+ {noreply, State}.
terminate(_Reason, _State) ->
- ok.
+ ok.
code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
+ {ok, State}.
%% ------------------------------------------------------------------
%% Internal Function Definitions