diff options
Diffstat (limited to 'options.c')
-rw-r--r-- | options.c | 78 |
1 files changed, 78 insertions, 0 deletions
@@ -198,6 +198,9 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_INT_PARAM("-t","--timeout", opt->timeout_) PARSE_STRING_PARAM("-l","--led", opt->led_filename_) #endif +#ifdef OPT_LUACLIENT + PARSE_STRING_PARAM("-f","--lua-file", opt->lua_file_) +#endif else return i; } @@ -299,6 +302,9 @@ void options_default(options_t* opt) #ifdef OPT_HEARTBEATCLIENT opt->progname_ = strdup("heartbeatclient"); #endif +#ifdef OPT_LUACLIENT + opt->progname_ = strdup("luaclient"); +#endif /* common */ opt->daemonize_ = 1; @@ -327,8 +333,69 @@ void options_default(options_t* opt) /* heartbeatclient only */ opt->timeout_ = 15; opt->led_filename_ = NULL; + +/* luaclient only */ + opt->lua_file_ = strdup("/usr/share/rhctl/mode-leds.lua"); +} + +#ifdef OPT_LUACLIENT +void options_lua_push_string(lua_State* L, const int tidx, const char* key, const char* value) +{ + lua_pushstring(L, key); + lua_pushstring(L, value); + lua_settable(L, tidx); +} + +void options_lua_push_int(lua_State* L, const int tidx, const char* key, const u_int32_t value) +{ + lua_pushstring(L, key); + lua_pushinteger(L, value); + lua_settable(L, tidx); } +void options_lua_push_boolean(lua_State* L, const int tidx, const char* key, const u_int32_t value) +{ + lua_pushstring(L, key); + lua_pushboolean(L, value); + lua_settable(L, tidx); +} + +void options_lua_push_string_list(lua_State* L, const int tidx, string_list_t* lst) +{ + if(!lst) + return; + + string_list_element_t* tmp = lst->first_; + if(tmp) { + lua_pushstring(L, "log_targets"); + lua_newtable(L); + int i = 1; + while(tmp) { + lua_pushinteger(L, i++); + lua_pushstring(L, tmp->string_); + lua_settable(L, -3); + tmp = tmp->next_; + } + lua_settable(L, tidx); + } +} + +void options_lua_push(options_t* opt, lua_State* L) +{ + lua_newtable(L); + + options_lua_push_string(L, -3, "progname", opt->progname_); + options_lua_push_boolean(L, -3, "daemonize", opt->daemonize_); + options_lua_push_string(L, -3, "username", opt->username_); + options_lua_push_string(L, -3, "groupname", opt->groupname_); + options_lua_push_string(L, -3, "chroot_dir", opt->chroot_dir_); + options_lua_push_string(L, -3, "pid_file", opt->pid_file_); + options_lua_push_string_list(L, -3, &(opt->log_targets_)); + options_lua_push_string(L, -3, "command_sock", opt->command_sock_); + options_lua_push_string(L, -3, "lua_file", opt->lua_file_); +} +#endif + void options_clear(options_t* opt) { if(!opt) @@ -368,6 +435,10 @@ void options_clear(options_t* opt) /* heartbeatcleint only */ if(opt->led_filename_) free(opt->led_filename_); + +/* luacleint only */ + if(opt->lua_file_) + free(opt->lua_file_); } void options_print_usage() @@ -414,6 +485,9 @@ void options_print_usage() printf(" [-t|--timeout] <timeout> heartbeat timeout in tenths of a second e.g. 15 -> 1.5s\n"); printf(" [-l|--led] <led filename> sysfs filename of led device to blink\n"); #endif +#ifdef OPT_LUACLIENT + printf(" [-f|--lua-file] <file> the configuration file e.g. /usr/share/rhctl/mode-leds.lua\n"); +#endif } void options_print(options_t* opt) @@ -469,4 +543,8 @@ void options_print(options_t* opt) printf("timeout: %d\n", opt->timeout_); printf("led_filename: '%s'\n", opt->led_filename_); #endif + +#ifdef OPT_LUACLIENT + printf("lua_file: '%s'\n", opt->lua_file_); +#endif } |