summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriele Santomaggio <G.santomaggio@gmail.com>2016-07-01 07:35:02 +0200
committerGitHub <noreply@github.com>2016-07-01 07:35:02 +0200
commit5adb78edb7cc92f515c838ea663b0a0547304cc7 (patch)
tree91e773fa7b06957c6e299b4bd9aeea1437b0f0ef
parent62e61802625964be64c1b11c80cdf29ef32de9d6 (diff)
parentfc50626299641802a30dfff04bfe0f55317680e5 (diff)
downloaderlang-sd_notify-5adb78edb7cc92f515c838ea663b0a0547304cc7.tar.gz
Merge pull request #8 from systemd/erlang-sd_notify-2
Added sd_pid_notify/sd_pid_notifyf
-rw-r--r--c_src/sd_notify.c28
-rw-r--r--src/sd_notify.erl10
2 files changed, 35 insertions, 3 deletions
diff --git a/c_src/sd_notify.c b/c_src/sd_notify.c
index 4776327..d667fb2 100644
--- a/c_src/sd_notify.c
+++ b/c_src/sd_notify.c
@@ -40,9 +40,33 @@ static ERL_NIF_TERM sd_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a
return enif_make_int(env, result);
}
+
+static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ int pid = 0;
+ enif_get_int(env, argv[0], &pid);
+
+ int unset_environment = 0;
+ enif_get_int(env, argv[1], &unset_environment);
+
+ unsigned int length = 0;
+ enif_get_list_length(env, argv[2], &length);
+
+
+ char* state = (char*)enif_alloc(++length);
+ enif_get_string(env, argv[1], state, length, ERL_NIF_LATIN1);
+ int result = sd_pid_notify(pid, unset_environment, state);
+ enif_free(state);
+
+ return enif_make_int(env, result);
+}
+
+
static ErlNifFunc nif_funcs[] =
{
- {"sd_notify", 2, sd_notify_nif}
+ {"sd_notify", 2, sd_notify_nif},
+ {"sd_pid_notify", 3, sd_pid_notify_nif},
+
};
-ERL_NIF_INIT(sd_notify, nif_funcs, NULL, NULL, NULL, NULL);
+ERL_NIF_INIT(sd_notify, nif_funcs, NULL, NULL, NULL, NULL); \ No newline at end of file
diff --git a/src/sd_notify.erl b/src/sd_notify.erl
index 5053327..b190655 100644
--- a/src/sd_notify.erl
+++ b/src/sd_notify.erl
@@ -27,7 +27,7 @@
-module(sd_notify).
--export([sd_notify/2, sd_notifyf/3]).
+-export([sd_notify/2, sd_notifyf/3, sd_pid_notify/3, sd_pid_notifyf/4]).
-on_load(init/0).
@@ -54,9 +54,17 @@ init() ->
sd_notify(_, _) ->
?nif_stub.
+sd_pid_notify(_, _, _) ->
+ ?nif_stub.
+
+
sd_notifyf(UnsetEnv, Format, Data) ->
sd_notify(UnsetEnv, lists:flatten(io_lib:format(Format, Data))).
+
+sd_pid_notifyf(Pid, UnsetEnv, Format, Data) ->
+ sd_pid_notify(Pid, UnsetEnv, lists:flatten(io_lib:format(Format, Data))).
+
%% ===================================================================
%% EUnit tests
%% ===================================================================