summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c_src/sd_notify.c25
-rw-r--r--src/sd_notify.erl16
2 files changed, 28 insertions, 13 deletions
diff --git a/c_src/sd_notify.c b/c_src/sd_notify.c
index bf4e9df..7387963 100644
--- a/c_src/sd_notify.c
+++ b/c_src/sd_notify.c
@@ -24,20 +24,33 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "erl_nif.h"
#include <systemd/sd-daemon.h>
-static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM sd_pid_notify_with_fds_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
- int pid = 0;
+ ERL_NIF_TERM head, tail;
+ unsigned int length = 0;
+
+ pid_t 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[2], state, length, ERL_NIF_LATIN1);
- int result = sd_pid_notify(pid, unset_environment, state);
+
+ enif_get_list_length(env, argv[3], &length);
+ int* fds = (int*)enif_alloc(++length * sizeof(int));
+ ERL_NIF_TERM list = argv[3];
+ int i = 0;
+ while(enif_get_list_cell(env, list, &head, &tail)) {
+ enif_get_int(env, head, &fds[i]);
+ i++;
+ list = tail;
+ }
+ int result = sd_pid_notify_with_fds(pid, unset_environment, state, fds, length);
+
+ enif_free(fds);
enif_free(state);
return enif_make_int(env, result);
@@ -46,7 +59,7 @@ static ERL_NIF_TERM sd_pid_notify_nif(ErlNifEnv* env, int argc, const ERL_NIF_TE
static ErlNifFunc nif_funcs[] =
{
- {"sd_pid_notify", 3, sd_pid_notify_nif},
+ {"sd_pid_notify_with_fds", 4, sd_pid_notify_with_fds_nif},
};
diff --git a/src/sd_notify.erl b/src/sd_notify.erl
index 4610522..504c25f 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, sd_pid_notifyf/4]).
+-export([sd_notify/2, sd_notifyf/3, sd_pid_notify/3, sd_pid_notifyf/4, sd_pid_notify_with_fds/4]).
-on_load(init/0).
@@ -52,17 +52,19 @@ init() ->
erlang:load_nif(filename:join(PrivDir, ?MODULE) ++ "_drv", 0).
sd_notify(UnsetEnv, Data) ->
- sd_pid_notify(0, UnsetEnv, Data).
+ sd_pid_notify_with_fds(0, UnsetEnv, Data, []).
-sd_pid_notify(_, _, _) ->
- ?nif_stub.
+sd_pid_notify(Pid, UnsetEnv, Data) ->
+ sd_pid_notify_with_fds(Pid, UnsetEnv, Data, []).
sd_notifyf(UnsetEnv, Format, Data) ->
- sd_notify(UnsetEnv, lists:flatten(io_lib:format(Format, Data))).
-
+ sd_pid_notify_with_fds(0, 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))).
+ sd_pid_notify_with_fds(Pid, UnsetEnv, lists:flatten(io_lib:format(Format, Data)), []).
+
+sd_pid_notify_with_fds(_, _, _, _) ->
+ ?nif_stub.
%% ===================================================================
%% EUnit tests