diff options
-rw-r--r-- | c_src/sd_notify.c | 30 | ||||
-rw-r--r-- | 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))). |