From f20831db9c5e1c73f3a4b9b9e3922ebe9668572b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 17 Sep 2015 02:28:57 +0200 Subject: added debug option made command socket optional --- src/dropnroll.c | 16 ++++++++++------ src/options.c | 14 +++++++++++++- src/options.h | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/dropnroll.c b/src/dropnroll.c index f629414..a3f16e5 100644 --- a/src/dropnroll.c +++ b/src/dropnroll.c @@ -368,7 +368,8 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt) fd_set readfds, tmpfds; FD_ZERO(&readfds); - FD_SET(cmd_listen_fd, &readfds); + if(cmd_listen_fd > 0) + FD_SET(cmd_listen_fd, &readfds); FD_SET(inotify_fd, &readfds); int max_fd = (cmd_listen_fd < inotify_fd) ? inotify_fd : cmd_listen_fd; client_t* client_lst = NULL; @@ -561,11 +562,14 @@ int main(int argc, char* argv[]) fclose(pid_file); } - int cmd_listen_fd = init_command_socket(opt.command_sock_); - if(cmd_listen_fd < 0) { - options_clear(&opt); - log_close(); - exit(-1); + int cmd_listen_fd = -1; + if(opt.command_sock_) { + cmd_listen_fd = init_command_socket(opt.command_sock_); + if(cmd_listen_fd < 0) { + options_clear(&opt); + log_close(); + exit(-1); + } } int inotify_fd = create_inotify(); diff --git a/src/options.c b/src/options.c index f74445b..c531070 100644 --- a/src/options.c +++ b/src/options.c @@ -172,6 +172,7 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_PARAM("-C","--chroot", opt->chroot_dir_) PARSE_STRING_PARAM("-P","--write-pid", opt->pid_file_) PARSE_STRING_LIST("-L","--log", opt->log_targets_) + PARSE_BOOL_PARAM("-U", "--debug", opt->debug_) PARSE_STRING_PARAM("-s","--command-sock", opt->command_sock_) PARSE_STRING_PARAM("-x","--script", opt->script_) PARSE_INT_PARAM("-m","--max-children", opt->max_children_) @@ -180,6 +181,14 @@ int options_parse(options_t* opt, int argc, char* argv[]) return i; } + if(opt->debug_) { + string_list_add(&opt->log_targets_, "stdout:5"); + opt->daemonize_ = 0; + } + + if(!opt->dirs_.first_ && !opt->command_sock_) + opt->command_sock_ = strdup("/var/run/dropnroll/cmd.sock"); + return 0; } @@ -212,8 +221,9 @@ void options_default(options_t* opt) opt->chroot_dir_ = NULL; opt->pid_file_ = NULL; string_list_init(&opt->log_targets_); + opt->debug_ = 0; - opt->command_sock_ = strdup("/var/run/dropnroll/cmd.sock"); + opt->command_sock_ = NULL; opt->script_ = strdup("newfile.sh"); opt->max_children_ = 8; string_list_init(&opt->dirs_); @@ -255,6 +265,7 @@ void options_print_usage() printf(" [-P|--write-pid] write pid to this file\n"); printf(" [-L|--log] :[,[,..]]\n"); printf(" add a log target, can be invoked several times\n"); + printf(" [-U|--debug] don't daemonize and log to stdout with maximum log level\n"); printf(" [-s|--command-sock] the command socket e.g. /var/run/dropnroll/cmd.sock\n"); printf(" [-x|--script]