24 #include <baseapp/init_options.h> 25 #include <baseapp/run.h> 26 #include <utils/system/argparser.h> 54 __basename = strdup(basename);
55 __default_plugin = strdup(
"default");
56 __has_net_tcp_port =
false;
58 __has_loggers =
false;
61 __has_net_service_name =
false;
62 __net_service_name = NULL;
63 __has_username =
false;
65 __has_groupname =
false;
69 __daemon_pid_file = NULL;
70 __daemonize_kill =
false;
71 __daemonize_status =
false;
74 __default_signal_handlers =
true;
75 __init_plugin_cache =
true;
76 __has_load_plugin_list =
false;
77 __load_plugin_list = NULL;
87 __basename = strdup(options.__basename);
88 __default_plugin = strdup(options.__default_plugin);
90 __has_net_tcp_port = options.__has_net_tcp_port;
91 if (__has_net_tcp_port) {
92 __net_tcp_port = options.__net_tcp_port;
95 __has_loggers = options.__has_loggers;
97 __loggers = strdup(options.__loggers);
100 __log_level = options.__log_level;
102 __net_service_name = NULL;
103 __has_net_service_name = options.__has_net_service_name;
104 if (__has_net_service_name) {
105 __net_service_name = strdup(options.__net_service_name);
109 __has_username = options.__has_username;
110 if (__has_username) {
111 __username = strdup(options.__username);
114 __has_groupname = options.__has_groupname;
115 if (__has_groupname) {
116 __groupname = strdup(options.__groupname);
119 __config_file = NULL;
120 if (options.__config_file) {
121 __config_file = strdup(options.__config_file);
123 __daemonize = options.__daemonize;
124 __daemon_pid_file = NULL;
125 if (__daemonize && options.__daemon_pid_file) {
126 __daemon_pid_file = strdup(options.__daemon_pid_file);
128 __daemonize_kill = options.__daemonize_kill;
129 __daemonize_status = options.__daemonize_status;
130 __show_help = options.__show_help;
131 __bb_cleanup = options.__bb_cleanup;
132 __default_signal_handlers = options.__default_signal_handlers;
133 __init_plugin_cache = options.__init_plugin_cache;
134 __load_plugin_list = NULL;
135 __has_load_plugin_list = options.__has_load_plugin_list;
136 if (__has_load_plugin_list) {
137 __load_plugin_list = strdup(options.__load_plugin_list);
140 __plugin_module_flags = options.__plugin_module_flags;
152 option long_options[] = {
153 {
"net-service-name", 1, 0, 0},
157 fawkes::runtime::argument_parser =
159 "hCc:dq::l:L:p:P:u:g:D::ks",
165 __default_plugin = strdup(
"default");
167 __has_net_tcp_port = argp->
has_arg(
"P");
168 if (__has_net_tcp_port) {
171 __has_loggers = argp->
has_arg(
"L");
173 __loggers = strdup(argp->
arg(
"L"));
180 }
else if ( argp->
has_arg(
"q") ) {
182 if ( (tmp = argp->
arg(
"q")) != NULL ) {
183 for (
unsigned int i = 0; i < strlen(tmp); ++i) {
184 if ( tmp[i] ==
'q' ) {
185 switch (__log_level) {
194 }
else if ( (tmp = argp->
arg(
"l")) != NULL ) {
195 if ( strcmp(tmp,
"debug") == 0 ) {
197 }
else if ( strcmp(tmp,
"info") == 0 ) {
199 }
else if ( strcmp(tmp,
"warn") == 0 ) {
201 }
else if ( strcmp(tmp,
"error") == 0 ) {
203 }
else if ( strcmp(tmp,
"none") == 0 ) {
208 __has_net_service_name = argp->
has_arg(
"net-service-name");
209 if (__has_net_service_name) {
210 __net_service_name = strdup(argp->
arg(
"net-service-name"));
212 __net_service_name = NULL;
215 __has_username = argp->
has_arg(
"u");
216 if (__has_username) {
217 __username = strdup(argp->
arg(
"u"));
222 __has_groupname = argp->
has_arg(
"u");
223 if (__has_groupname) {
224 __groupname = strdup(argp->
arg(
"u"));
230 __config_file = NULL;
231 if (argp->
arg(
"c")) {
232 __config_file = strdup(argp->
arg(
"c"));
235 __daemonize = argp->
has_arg(
"D");
236 __daemonize_kill = __daemonize && argp->
has_arg(
"k");
237 __daemonize_status = __daemonize && argp->
has_arg(
"s");
238 __daemon_pid_file = NULL;
239 if (__daemonize && argp->
arg(
"D")) {
240 __daemon_pid_file = strdup(argp->
arg(
"D"));
242 __daemon_pid_file = NULL;
244 __show_help = argp->
has_arg(
"h");
245 __bb_cleanup = argp->
has_arg(
"C");
248 if (__has_load_plugin_list) {
250 for (uint i = 0; i < argp->
items().size(); i++) {
251 len += strlen(argp->
items()[i]);
254 len += strlen(argp->
arg(
"p") + 1);
256 char res[len + argp->
items().size()];
258 sprintf(res,
"%s,%s,", argp->
arg(
"p"), argp->
items()[0]);
259 }
else if (argp->
has_arg(
"p")) {
260 sprintf(res,
"%s", argp->
arg(
"p"));
262 sprintf(res,
"%s", argp->
items()[0]);
264 for (uint i = 1; i < argp->
items().size(); i++) {
265 char *tmp = strdup(res);
266 sprintf(res,
"%s,%s", tmp, argp->
items()[i]);
269 __load_plugin_list = strdup(res);
271 __load_plugin_list = NULL;
274 __init_plugin_cache =
true;
276 __default_signal_handlers =
true;
284 free(__default_plugin);
285 if (__has_loggers) free(__loggers);
286 if (__has_net_service_name) free(__net_service_name);
287 if (__has_username) free(__username);
288 if (__has_groupname) free(__groupname);
289 if (__has_load_plugin_list) free(__load_plugin_list);
290 if (__config_file) free(__config_file);
291 if (__daemon_pid_file) free(__daemon_pid_file);
303 __basename = strdup(options.__basename);
304 free(__default_plugin);
305 __default_plugin = strdup(options.__default_plugin);
307 __has_net_tcp_port = options.__has_net_tcp_port;
308 if (__has_net_tcp_port) {
309 __net_tcp_port = options.__net_tcp_port;
312 __has_loggers =
false;
316 __has_loggers = options.__has_loggers;
318 __loggers = strdup(options.__loggers);
321 __log_level = options.__log_level;
323 if (__has_net_service_name) {
324 __has_net_service_name =
false;
325 free(__net_service_name);
326 __net_service_name = NULL;
328 __has_net_service_name = options.__has_net_service_name;
329 if (__has_net_service_name) {
330 __net_service_name = strdup(options.__net_service_name);
333 if (__has_username) {
334 __has_username =
false;
338 __has_username = options.__has_username;
339 if (__has_username) {
340 __username = strdup(options.__username);
343 if (__has_groupname) {
344 __has_groupname =
false;
349 __has_groupname = options.__has_groupname;
350 if (__has_groupname) {
351 __groupname = strdup(options.__groupname);
356 __config_file = NULL;
358 if (options.__config_file) {
359 __config_file = strdup(options.__config_file);
362 __daemonize = options.__daemonize;
363 if (__daemon_pid_file) {
364 free(__daemon_pid_file);
365 __daemon_pid_file = NULL;
367 if (__daemonize && options.__daemon_pid_file) {
368 __daemon_pid_file = strdup(options.__daemon_pid_file);
370 __daemonize_kill = options.__daemonize_kill;
371 __daemonize_status = options.__daemonize_status;
372 __show_help = options.__show_help;
373 __bb_cleanup = options.__bb_cleanup;
375 if (__load_plugin_list) {
376 free(__load_plugin_list);
377 __load_plugin_list = NULL;
379 __has_load_plugin_list = options.__has_load_plugin_list;
380 if (__has_load_plugin_list) {
381 __load_plugin_list = strdup(options.__load_plugin_list);
384 __init_plugin_cache = options.__init_plugin_cache;
385 __plugin_module_flags = options.__plugin_module_flags;
386 __default_signal_handlers = options.__default_signal_handlers;
399 free(__default_plugin);
400 __default_plugin = strdup(default_plugin_);
412 __has_net_tcp_port =
true;
413 __net_tcp_port = port;
424 if (__has_net_service_name) {
425 __has_net_service_name =
false;
426 free(__net_service_name);
429 __has_net_service_name =
true;
430 __net_service_name = strdup(service_name);
444 const char *pid_file)
447 __daemonize_kill = daemonize && kill;
448 __daemonize_status = daemonize && status;
449 if (daemonize && pid_file) {
450 __daemon_pid_file = strdup(pid_file);
463 __has_loggers =
false;
467 __has_loggers =
true;
468 __loggers = strdup(loggers);
503 __init_plugin_cache = init_cache;
514 if (__has_username) {
515 __has_username =
false;
519 __has_username =
true;
520 __username = strdup(username);
533 if (__has_load_plugin_list) {
534 __has_load_plugin_list =
false;
535 free(__load_plugin_list);
536 __load_plugin_list = NULL;
539 __has_load_plugin_list =
true;
540 __load_plugin_list = strdup(plugin_list);
553 if (__has_groupname) {
554 __has_groupname =
false;
558 __has_groupname =
true;
559 __groupname = strdup(groupname);
573 __config_file = NULL;
576 __config_file = strdup(config_file);
600 __plugin_module_flags = flags;
614 __default_signal_handlers = enable;
639 return __default_plugin;
649 return __has_net_tcp_port;
658 return __net_tcp_port;
667 return __has_net_service_name;
676 return __net_service_name;
685 return __has_load_plugin_list;
694 return __load_plugin_list;
703 return __has_loggers;
749 return __init_plugin_cache;
759 return __default_signal_handlers;
777 return __daemonize_kill;
786 return __daemonize_status;
796 return __daemon_pid_file;
806 return __has_username;
825 return __has_groupname;
844 return __config_file;
854 return __plugin_module_flags;
bool daemonize() const
Check if daemonization has been requested.
const char * program_name() const
Get name of program.
bool has_groupname() const
Check if group name has been passed.
informational output about normal procedures
const char * arg(const char *argn)
Get argument value.
bool has_load_plugin_list() const
Check if plugin load list has been set.
const std::vector< const char *> & items() const
Get non-option items.
Fawkes library namespace.
bool bb_cleanup() const
Check if blackboard cleanup has been requested.
const char * groupname() const
Get group name to run as.
const char * net_service_name() const
Get network service name.
warning, should be investigated but software still functions, an example is that something was reques...
Parse command line arguments.
InitOptions & load_plugins(const char *plugin_list)
Set list of plugins to load during startup.
bool has_loggers() const
Check if logger string has been passed.
~InitOptions()
Destructor.
Logger::LogLevel log_level() const
Get log level.
bool daemonize_status() const
Check if status of daemon has been requested.
const char * default_plugin() const
Get name of default plugin.
InitOptions & operator=(const InitOptions &options)
Assignment operator.
ModuleFlags
Flags for the loading process.
long int parse_int(const char *argn)
Parse argument as integer.
std::vector< const char *>::size_type num_items() const
Get number of non-option items.
error, may be recoverable (software still running) or not (software has to terminate).
bool has_net_service_name() const
Check if network service name has been passed.
bool has_username() const
Check if user name has been passed.
Initialization options class.
unsigned short int net_tcp_port() const
Get Fawkes network TCP port.
InitOptions & user(const char *username)
Set user name to run as.
const char * daemon_pid_file() const
Get daemon PID file.
debug output, relevant only when tracking down problems
bool default_signal_handlers() const
Check if default signal handlers should be enabled.
bool has_net_tcp_port() const
Check if TCP port has been passed.
const char * config_file() const
Get config file path.
const char * load_plugin_list() const
Get plugin load list.
bool show_help() const
Check if help has been requested.
InitOptions(const char *basename)
Constructor.
Module::ModuleFlags plugin_module_flags() const
Get plugin module flags.
const char * username() const
Get user name to run as.
bool has_arg(const char *argn)
Check if argument has been supplied.
const char * basename() const
Get program basename.
InitOptions & group(const char *groupname)
Set group name to run as.
Default flags, these are MODULE_BIND_GLOBAL, MODULE_BIND_NOW and MODULE_BIND_DEEP.
bool daemonize_kill() const
Check if killing of daemon has been requested.
bool init_plugin_cache() const
Check if plugin cache initialization has been requested.
const char * loggers() const
Get logger string.
use this to disable log output