mirror of
https://github.com/uselessd/alcove.git
synced 2026-04-15 09:15:19 +00:00
setopt/3: set options per process
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ rlimit_define/1
|
||||
setgid/1
|
||||
sethostname/1
|
||||
setns/1
|
||||
setopt/2
|
||||
setrlimit/2
|
||||
setuid/1
|
||||
sigaction/2
|
||||
|
||||
Reference in New Issue
Block a user