From 8c0fdbc0d966514f1ea9d65434367c46a60fae19 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Sun, 26 Jun 2016 20:54:13 +0200 Subject: added sd_pid_notify --- c_src/sd_notify.c | 30 +++++++++++++++++++++++++++--- src/sd_notify.erl | 6 +++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/c_src/sd_notify.c b/c_src/sd_notify.c index 98c89c8..6eed405 100644 --- a/c_src/sd_notify.c +++ b/c_src/sd_notify.c @@ -34,15 +34,39 @@ static ERL_NIF_TERM sd_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a char* state = (char*)enif_alloc(++length); enif_get_string(env, argv[1], state, length, ERL_NIF_LATIN1); - sd_notify(unset_environment, state); + int result = sd_notify(unset_environment, state); enif_free(state); - return enif_make_atom(env, "ok"); + return enif_make_int(env, result); } + +static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + int unset_environment_pid = 0; + enif_get_int(env, argv[0], &unset_environment_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(unset_environment_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); diff --git a/src/sd_notify.erl b/src/sd_notify.erl index 5053327..6b0f91e 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]). -on_load(init/0). @@ -54,6 +54,10 @@ 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))). -- cgit v1.2.1 From 204d5b3e0940cf8675d1223c2d76d33b94178cf4 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Sun, 26 Jun 2016 21:58:37 +0200 Subject: added sd_pid_notifyf --- c_src/sd_notify.c | 2 +- src/sd_notify.erl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/c_src/sd_notify.c b/c_src/sd_notify.c index 6eed405..7c5bd25 100644 --- a/c_src/sd_notify.c +++ b/c_src/sd_notify.c @@ -69,4 +69,4 @@ static ErlNifFunc nif_funcs[] = }; -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 6b0f91e..0a69442 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, sd_pid_notify/3]). +-export([sd_notify/2, sd_notifyf/3, sd_pid_notify/3, sd_pid_notifyf/4]). -on_load(init/0). @@ -61,6 +61,10 @@ sd_pid_notify(_, _, _) -> sd_notifyf(UnsetEnv, Format, Data) -> sd_notify(UnsetEnv, lists:flatten(io_lib:format(Format, Data))). + +sd_pid_notifyf(UnsetEnvPid, UnsetEnv, Format, Data) -> + sd_pid_notify(UnsetEnvPid, UnsetEnv, lists:flatten(io_lib:format(Format, Data))). + %% =================================================================== %% EUnit tests %% =================================================================== -- cgit v1.2.1 From fc50626299641802a30dfff04bfe0f55317680e5 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Tue, 28 Jun 2016 22:27:25 +0200 Subject: cosmetics --- c_src/sd_notify.c | 6 +++--- src/sd_notify.erl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/c_src/sd_notify.c b/c_src/sd_notify.c index 7c5bd25..d667fb2 100644 --- a/c_src/sd_notify.c +++ b/c_src/sd_notify.c @@ -43,8 +43,8 @@ static ERL_NIF_TERM sd_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { - int unset_environment_pid = 0; - enif_get_int(env, argv[0], &unset_environment_pid); + int pid = 0; + enif_get_int(env, argv[0], &pid); int unset_environment = 0; enif_get_int(env, argv[1], &unset_environment); @@ -55,7 +55,7 @@ static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TE char* state = (char*)enif_alloc(++length); enif_get_string(env, argv[1], state, length, ERL_NIF_LATIN1); - int result = sd_pid_notify(unset_environment_pid, unset_environment, state); + int result = sd_pid_notify(pid, unset_environment, state); enif_free(state); return enif_make_int(env, result); diff --git a/src/sd_notify.erl b/src/sd_notify.erl index 0a69442..b190655 100644 --- a/src/sd_notify.erl +++ b/src/sd_notify.erl @@ -62,8 +62,8 @@ sd_notifyf(UnsetEnv, Format, Data) -> sd_notify(UnsetEnv, lists:flatten(io_lib:format(Format, Data))). -sd_pid_notifyf(UnsetEnvPid, UnsetEnv, Format, Data) -> - sd_pid_notify(UnsetEnvPid, 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 -- cgit v1.2.1