diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-01-07 09:52:32 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-01-07 09:52:32 +0000 |
commit | 8fd59356efa9f746a16e9d59fd0dd1fcdd132823 (patch) | |
tree | db4047eb92e376bd031646dc3f11d52d267dcddf | |
parent | c5a3277d422550883efbc9484f96521fbc5776bc (diff) | |
download | lua-openrc-8fd59356efa9f746a16e9d59fd0dd1fcdd132823.tar.bz2 lua-openrc-8fd59356efa9f746a16e9d59fd0dd1fcdd132823.tar.xz |
implement services_in_runlevel()
-rw-r--r-- | rc.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -166,6 +166,25 @@ static int Pservice_status(lua_State *L) return n; } +/** services_in_runlevel(runlevel) - List the services in a runlevel */ +static int Pservices_in_runlevel(lua_State *L) +{ + int i = 1; + RC_STRING *item; + const char *runlevel = luaL_checkstring(L, 1); + RC_STRINGLIST *list = rc_services_in_runlevel(runlevel); + lua_newtable(L); + TAILQ_FOREACH(item, list, entries) { + if (item->value == NULL || item->value[0] == '\0') + continue; + lua_pushnumber(L, i++); + lua_pushstring(L, item->value); + lua_settable(L, -3); + } + rc_stringlist_free(list); + return 1; +} + static const luaL_reg R[] = { @@ -180,7 +199,8 @@ static const luaL_reg R[] = {"service_in_runlevel", Pservice_in_runlevel}, {"service_resolve", Pservice_resolve}, {"service_extra_commands", Pservice_extra_commands}, - {"service_status", Pservice_status}, + {"service_status", Pservice_status}, + {"services_in_runlevel",Pservices_in_runlevel}, {NULL, NULL} }; |