setopt/3: set options per process

This commit is contained in:
Michael Santos
2014-03-25 08:08:30 -04:00
parent 0fbd6ce289
commit 3f2de7e295
3 changed files with 47 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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
*/

View File

@@ -21,6 +21,7 @@ rlimit_define/1
setgid/1
sethostname/1
setns/1
setopt/2
setrlimit/2
setuid/1
sigaction/2