Browse Source

angel: Add wrapper, env and copy-env to instance config

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent
commit
8ac057d3d5
  1. 3
      include/lighttpd/angel_server.h
  2. 108
      src/angel/angel_plugin_core.c
  3. 6
      src/angel/angel_server.c
  4. 8
      src/common/angel_connection.c
  5. 5
      src/main/server.c

3
include/lighttpd/angel_server.h

@ -22,6 +22,7 @@ struct liInstanceConf {
gint refcount;
gchar **cmd;
gchar **env;
GString *username;
uid_t uid;
gid_t gid;
@ -67,7 +68,7 @@ LI_API void li_instance_replace(liInstance *oldi, liInstance *newi);
LI_API void li_instance_set_state(liInstance *i, liInstanceState s);
LI_API void li_instance_state_reached(liInstance *i, liInstanceState s);
LI_API liInstanceConf* li_instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid);
LI_API liInstanceConf* li_instance_conf_new(gchar **cmd, gchar **env, GString *username, uid_t uid, gid_t gid);
LI_API void li_instance_conf_release(liInstanceConf *ic);
LI_API void li_instance_conf_acquire(liInstanceConf *ic);

108
src/angel/angel_plugin_core.c

@ -6,8 +6,8 @@
#include <grp.h>
static void core_instance_parse(liServer *srv, liPlugin *p, liValue **options) {
GPtrArray *cmd;
gchar **cmdarr;
GPtrArray *cmd, *env;
gchar **cmdarr, **envarr;
liPluginCoreConfig *config = (liPluginCoreConfig*) p->data;
uid_t uid = -1;
gid_t gid = -1;
@ -56,10 +56,86 @@ static void core_instance_parse(liServer *srv, liPlugin *p, liValue **options) {
return;
}
/* check types in lists */
if (options[6]) {
GPtrArray *wrapper_lst = options[6]->data.list;
guint i;
for (i = 0; i < wrapper_lst->len; i++) {
liValue *wi = g_ptr_array_index(wrapper_lst, i);
if (wi->type != LI_VALUE_STRING) {
ERROR(srv, "Entry %i in wrapper list is not a string", i);
config->load_failed = FALSE;
return;
}
}
}
if (options[7]) { /* env */
GPtrArray *env_lst = options[7]->data.list;
guint i;
for (i = 0; i < env_lst->len; i++) {
liValue *ei = g_ptr_array_index(env_lst, i);
if (ei->type != LI_VALUE_STRING) {
ERROR(srv, "Entry %i in env list is not a string", i);
config->load_failed = FALSE;
return;
}
}
}
if (options[8]) { /* copy-env */
GPtrArray *env_lst = options[8]->data.list;
guint i;
for (i = 0; i < env_lst->len; i++) {
liValue *ei = g_ptr_array_index(env_lst, i);
if (ei->type != LI_VALUE_STRING) {
ERROR(srv, "Entry %i in copy-env list is not a string", i);
config->load_failed = FALSE;
return;
}
}
}
env = g_ptr_array_new();
if (options[7]) { /* env */
GPtrArray *env_lst = options[7]->data.list;
guint i;
for (i = 0; i < env_lst->len; i++) {
liValue *ei = g_ptr_array_index(env_lst, i);
g_ptr_array_add(env, g_strndup(GSTR_LEN(ei->data.string)));
}
}
if (options[8]) { /* copy-env */
GPtrArray *env_lst = options[8]->data.list;
guint i;
for (i = 0; i < env_lst->len; i++) {
liValue *ei = g_ptr_array_index(env_lst, i);
const char *val = getenv(ei->data.string->str);
size_t vallen, keylen = ei->data.string->len;
gchar *entry;
if (!val) continue;
vallen = strlen(val);
entry = g_malloc(keylen + 1 /* "=" */ + vallen + 1 /* \0 */);
memcpy(entry, GSTR_LEN(ei->data.string));
entry[keylen] = '=';
memcpy(entry + keylen+1, val, vallen);
entry[keylen + vallen + 1] = '\0';
g_ptr_array_add(env, entry);
}
}
cmd = g_ptr_array_new();
#if 0
g_ptr_array_add(cmd, g_strndup(CONST_STR_LEN("/usr/bin/valgrind")));
#endif
if (options[6]) {
GPtrArray *wrapper_lst = options[6]->data.list;
guint i;
for (i = 0; i < wrapper_lst->len; i++) {
liValue *wi = g_ptr_array_index(wrapper_lst, i);
g_ptr_array_add(cmd, g_strndup(GSTR_LEN(wi->data.string)));
}
}
if (options[2]) {
g_ptr_array_add(cmd, g_strndup(GSTR_LEN(options[2]->data.string)));
} else {
@ -86,16 +162,20 @@ static void core_instance_parse(liServer *srv, liPlugin *p, liValue **options) {
g_ptr_array_add(cmd, NULL);
cmdarr = (gchar**) g_ptr_array_free(cmd, FALSE);
config->load_instconf = li_instance_conf_new(cmdarr, user, uid, gid);
envarr = (gchar**) g_ptr_array_free(env, FALSE);
config->load_instconf = li_instance_conf_new(cmdarr, envarr, user, uid, gid);
}
static const liPluginItemOption core_instance_options[] = {
{ "user", LI_VALUE_STRING, 0 },
{ "group", LI_VALUE_STRING, 0 },
{ "binary", LI_VALUE_STRING, 0 },
{ "config", LI_VALUE_STRING, 0 },
{ "luaconfig", LI_VALUE_STRING, 0 },
{ "modules", LI_VALUE_STRING, 0 },
/* 0 */ { "user", LI_VALUE_STRING, 0 },
/* 1 */ { "group", LI_VALUE_STRING, 0 },
/* 2 */ { "binary", LI_VALUE_STRING, 0 },
/* 3 */ { "config", LI_VALUE_STRING, 0 },
/* 4 */ { "luaconfig", LI_VALUE_STRING, 0 },
/* 5 */ { "modules", LI_VALUE_STRING, 0 },
/* 6 */ { "wrapper", LI_VALUE_LIST, 0 },
/* 7 */ { "env", LI_VALUE_LIST, 0 },
/* 8 */ { "copy-env", LI_VALUE_LIST, 0 },
{ NULL, 0, 0 }
};
@ -157,8 +237,8 @@ only_one_type:
}
static const liPluginItemOption core_listen_options[] = {
{ "ip", LI_VALUE_STRING, 0 },
{ "unix", LI_VALUE_STRING, 0 },
/* 0 */ { "ip", LI_VALUE_STRING, 0 },
/* 1 */ { "unix", LI_VALUE_STRING, 0 },
{ NULL, 0, 0 }
};

6
src/angel/angel_server.c

@ -177,7 +177,7 @@ static void instance_spawn(liInstance *i) {
li_fd_no_block(confd[1]);
i->acon = li_angel_connection_new(i->srv->loop, confd[0], i, instance_angel_call_cb, instance_angel_close_cb);
i->proc = li_proc_new(i->srv, i->ic->cmd, NULL, i->ic->uid, i->ic->gid, i->ic->username->str, instance_spawn_setup, confd);
i->proc = li_proc_new(i->srv, i->ic->cmd, i->ic->env, i->ic->uid, i->ic->gid, i->ic->username->str, instance_spawn_setup, confd);
if (!i->proc) return;
@ -350,10 +350,11 @@ void li_instance_acquire(liInstance *i) {
g_atomic_int_inc(&i->refcount);
}
liInstanceConf* li_instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid) {
liInstanceConf* li_instance_conf_new(gchar **cmd, gchar **env, GString *username, uid_t uid, gid_t gid) {
liInstanceConf *ic = g_slice_new0(liInstanceConf);
ic->refcount = 1;
ic->cmd = cmd;
ic->env = env;
if (username) {
ic->username = g_string_new_len(GSTR_LEN(username));
}
@ -367,6 +368,7 @@ void li_instance_conf_release(liInstanceConf *ic) {
assert(g_atomic_int_get(&ic->refcount) > 0);
if (!g_atomic_int_dec_and_test(&ic->refcount)) return;
g_strfreev(ic->cmd);
g_strfreev(ic->env);
g_slice_free(liInstanceConf, ic);
}

8
src/common/angel_connection.c

@ -202,6 +202,7 @@ static gboolean angel_dispatch(liAngelConnection *acon, GError **err) {
call = (liAngelCall*) g_ptr_array_index(acon->call_table, id);
g_ptr_array_index(acon->call_table, id) = NULL;
if (call) {
call->id = -1;
ev_timer_stop(acon->loop, &call->timeout_watcher);
ctx = call->context;
if (NULL == (cb = call->callback)) {
@ -456,6 +457,13 @@ void li_angel_connection_free(liAngelConnection *acon) {
}
g_queue_free(acon->out);
g_string_free(acon->in.data, TRUE);
g_string_free(acon->parse.mod, TRUE);
g_string_free(acon->parse.action, TRUE);
g_string_free(acon->parse.error, TRUE);
g_string_free(acon->parse.data, TRUE);
close_fd_array(acon->parse.fds);
g_array_free(acon->parse.fds, TRUE);
/* TODO */
g_slice_free(liAngelConnection, acon);

5
src/main/server.c

@ -167,6 +167,11 @@ void li_server_free(liServer* srv) {
g_array_free(srv->throttle_pools, TRUE);
}
if (srv->acon) {
li_angel_connection_free(srv->acon);
srv->acon = NULL;
}
/* free all workers */
{
guint i;

Loading…
Cancel
Save