From a5f70c621a932e52c493152ab459bd87bba96767 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 7 Jan 2010 12:26:07 +0000 Subject: implement sys() and service_states() sys() returns system type (i.e vserver, uml, etc) service_states() returns a list of all service states. --- rc.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/rc.c b/rc.c index 19c41af..fbbf5d6 100644 --- a/rc.c +++ b/rc.c @@ -130,11 +130,12 @@ static struct statestr states[] = { { RC_SERVICE_INACTIVE, "inactive" }, { RC_SERVICE_HOTPLUGGED, "hotplugged" }, { RC_SERVICE_FAILED, "failed" }, - { RC_SERVICE_SCHEDULED, "sceduled" }, - { RC_SERVICE_WASINACTIVE, "was inactive" }, + { RC_SERVICE_SCHEDULED, "scheduled" }, + { RC_SERVICE_WASINACTIVE, "wasinactive" }, { 0, NULL }, }; + static RC_SERVICE get_rcstate(const char *str) { int i; @@ -144,6 +145,19 @@ static RC_SERVICE get_rcstate(const char *str) return 0; } +/** service_states() - List all available states */ +static int Pservice_states(lua_State *L) +{ + int i; + lua_newtable(L); + for (i = 0; states[i].state != 0; i++) { + lua_pushnumber(L, i+1); + lua_pushstring(L, states[i].str); + lua_settable(L, -3); + } + return 1; +} + /** service_status(service, [state]) - Return current state the service is in or test service against given state*/ static int Pservice_status(lua_State *L) { @@ -217,6 +231,13 @@ static int Pservice_daemons_crashed(lua_State *L) return 1; } +/** sys() - name system type (i.e VSERVER, OPENVZ, UML...) */ +static int Psys(lua_State *L) +{ + lua_pushstring(L, rc_sys()); + return 1; +} + static const luaL_reg R[] = { {"runlevel_get", Prunlevel_get}, @@ -230,12 +251,14 @@ static const luaL_reg R[] = {"service_in_runlevel", Pservice_in_runlevel}, {"service_resolve", Pservice_resolve}, {"service_extra_commands", Pservice_extra_commands}, + {"service_states", Pservice_states}, {"service_status", Pservice_status}, {"services_in_runlevel",Pservices_in_runlevel}, {"services_in_runlevel_stacked",Pservices_in_runlevel_stacked}, {"services_in_state", Pservices_in_state}, {"services_scheduled", Pservices_scheduled}, {"service_daemons_crashed", Pservice_daemons_crashed}, + {"sys", Psys}, {NULL, NULL} }; -- cgit v1.2.3