summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-17 02:28:57 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-09-17 02:28:57 +0200
commitf20831db9c5e1c73f3a4b9b9e3922ebe9668572b (patch)
tree70a0091fd3dd72075bf06f6b38d6ced07f0ceb5d
parentfinally add manpage (diff)
added debug option
made command socket optional
-rw-r--r--src/dropnroll.c16
-rw-r--r--src/options.c14
-rw-r--r--src/options.h1
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] <path> write pid to this file\n");
printf(" [-L|--log] <target>:<level>[,<param1>[,<param2>..]]\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] <unix sock> the command socket e.g. /var/run/dropnroll/cmd.sock\n");
printf(" [-x|--script] <script> the command socket e.g. newfile.sh\n");
printf(" [-m|--max-children] <#of children> limit of children to be started e.g. 8\n");
@@ -274,6 +285,7 @@ void options_print(options_t* opt)
printf("pid_file: '%s'\n", opt->pid_file_);
printf("log_targets: \n");
string_list_print(&opt->log_targets_, " '", "'\n");
+ printf("debug: %s\n", !opt->debug_ ? "false" : "true");
printf("command_sock: '%s'\n", opt->command_sock_);
printf("script: '%s'\n", opt->script_);
diff --git a/src/options.h b/src/options.h
index d98983a..0e95532 100644
--- a/src/options.h
+++ b/src/options.h
@@ -32,6 +32,7 @@ struct options_struct {
char* chroot_dir_;
char* pid_file_;
string_list_t log_targets_;
+ int debug_;
char* command_sock_;
char* script_;