From 3f2de7e295576dc6b2be3b4371c858347dc665c4 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Tue, 25 Mar 2014 08:08:30 -0400 Subject: [PATCH] setopt/3: set options per process --- c_src/alcove.h | 4 ++-- c_src/alcove_call.c | 44 +++++++++++++++++++++++++++++++++++++++++ c_src/alcove_call.proto | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/c_src/alcove.h b/c_src/alcove.h index bd0e47c..bf9668b 100644 --- a/c_src/alcove.h +++ b/c_src/alcove.h @@ -35,8 +35,8 @@ #include "alcove_version.h" enum { - alcove_opt_daemonize = 1 << 0, /* Run the process as a daemon */ - alcove_opt_closeallfds = 1 << 1, /* Close fd's associated with the process */ + alcove_opt_exit_status = 1 << 0, /* Report child exit status */ + alcove_opt_termsig = 1 << 1, /* Report child termination signal */ }; typedef struct { diff --git a/c_src/alcove_call.c b/c_src/alcove_call.c index 5b0e164..05857e9 100644 --- a/c_src/alcove_call.c +++ b/c_src/alcove_call.c @@ -58,6 +58,50 @@ alcove_pid(alcove_state_t *ap, ETERM *arg) return t; } +/* Set port options. */ + ETERM * +alcove_setopt(alcove_state_t *ap, ETERM *arg) +{ + ETERM *hd = NULL; + char *opt = NULL; + int val = 0; + + /* opt */ + arg = alcove_list_head(&hd, arg); + if (!hd || !ERL_IS_ATOM(hd)) + goto BADARG; + + opt = ERL_ATOM_PTR(hd); + + /* val */ + arg = alcove_list_head(&hd, arg); + if (!hd || !ERL_IS_INTEGER(hd)) + goto BADARG; + + val = ERL_INT_VALUE(hd); + + if (!strncmp(opt, "verbose", 7)) { + ap->verbose = val; + } + else if (!strncmp(opt, "exit_status", 11)) { + ap->opt = val ? + ap->opt | alcove_opt_exit_status : + ap->opt & ~alcove_opt_exit_status; + } + else if (!strncmp(opt, "termsig", 7)) { + ap->opt = val ? + ap->opt | alcove_opt_termsig : + ap->opt & ~alcove_opt_termsig; + } + else + goto BADARG; + + return erl_mk_atom("ok"); + +BADARG: + return erl_mk_atom("badarg"); +} + /* * Utility functions */ diff --git a/c_src/alcove_call.proto b/c_src/alcove_call.proto index 2914dd1..560df3b 100644 --- a/c_src/alcove_call.proto +++ b/c_src/alcove_call.proto @@ -21,6 +21,7 @@ rlimit_define/1 setgid/1 sethostname/1 setns/1 +setopt/2 setrlimit/2 setuid/1 sigaction/2