summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-17 02:55:32 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-09-17 02:55:32 +0200
commitb4a3e18879becbfaeaee4ba15f8d71344064f8a4 (patch)
tree4ee5e2528151749d9b88ad9c2953765ee5b6a551
parentadded debug option (diff)
added option for children policy
-rw-r--r--src/datatypes.h2
-rw-r--r--src/dropnroll.c40
-rw-r--r--src/options.c25
-rw-r--r--src/options.h2
4 files changed, 50 insertions, 19 deletions
diff --git a/src/datatypes.h b/src/datatypes.h
index 3220758..a94c5ae 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -46,4 +46,6 @@ struct read_buffer_struct {
};
typedef struct read_buffer_struct read_buffer_t;
+typedef enum { DEFER, DROP, KILL_OLDEST } children_policy_t;
+
#endif
diff --git a/src/dropnroll.c b/src/dropnroll.c
index a3f16e5..210a416 100644
--- a/src/dropnroll.c
+++ b/src/dropnroll.c
@@ -484,8 +484,11 @@ int main(int argc, char* argv[])
if(ret == -2) {
fprintf(stderr, "memory error on options_parse, exiting\n");
}
+ if(ret == -3) {
+ fprintf(stderr, "invalid children policy\n");
+ }
- if(ret != -2)
+ if(ret != -2 && ret != -3)
options_print_usage();
options_clear(&opt);
@@ -493,26 +496,21 @@ int main(int argc, char* argv[])
exit(ret);
}
string_list_element_t* tmp = opt.log_targets_.first_;
- if(!tmp) {
- log_add_target("syslog:3,dropnroll,daemon");
- }
- else {
- while(tmp) {
- ret = log_add_target(tmp->string_);
- if(ret) {
- switch(ret) {
- case -2: fprintf(stderr, "memory error on log_add_target, exitting\n"); break;
- case -3: fprintf(stderr, "unknown log target: '%s', exitting\n", tmp->string_); break;
- case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
- default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
- }
-
- options_clear(&opt);
- log_close();
- exit(ret);
+ while(tmp) {
+ ret = log_add_target(tmp->string_);
+ if(ret) {
+ switch(ret) {
+ case -2: fprintf(stderr, "memory error on log_add_target, exitting\n"); break;
+ case -3: fprintf(stderr, "unknown log target: '%s', exitting\n", tmp->string_); break;
+ case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
+ default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
}
- tmp = tmp->next_;
+
+ options_clear(&opt);
+ log_close();
+ exit(ret);
}
+ tmp = tmp->next_;
}
log_printf(NOTICE, "just started...");
if(options_parse_post(&opt)) {
@@ -521,6 +519,10 @@ int main(int argc, char* argv[])
exit(-1);
}
+ if(opt.debug_) {
+ options_print(&opt);
+ }
+
priv_info_t priv;
if(opt.username_)
if(priv_init(&priv, opt.username_, opt.groupname_)) {
diff --git a/src/options.c b/src/options.c
index c531070..d3824a9 100644
--- a/src/options.c
+++ b/src/options.c
@@ -158,6 +158,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
argc--;
+ char* children_policy = NULL;
int i;
for(i=1; argc > 0; ++i)
{
@@ -176,6 +177,7 @@ int options_parse(options_t* opt, int argc, char* argv[])
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_)
+ PARSE_STRING_PARAM("-p","--children-policy", children_policy)
PARSE_STRING_LIST("-d","--dir", opt->dirs_)
else
return i;
@@ -186,6 +188,20 @@ int options_parse(options_t* opt, int argc, char* argv[])
opt->daemonize_ = 0;
}
+ if(children_policy) {
+ if(!strcmp(children_policy, "defer"))
+ opt->children_policy_ = DEFER;
+ else if(!strcmp(children_policy, "drop"))
+ opt->children_policy_ = DROP;
+ else if(!strcmp(children_policy, "kill-oldest"))
+ opt->children_policy_ = KILL_OLDEST;
+ else
+ return -3;
+ }
+
+ if(!opt->log_targets_.first_)
+ string_list_add(&opt->log_targets_, "syslog:3,dropnroll,daemon");
+
if(!opt->dirs_.first_ && !opt->command_sock_)
opt->command_sock_ = strdup("/var/run/dropnroll/cmd.sock");
@@ -226,6 +242,7 @@ void options_default(options_t* opt)
opt->command_sock_ = NULL;
opt->script_ = strdup("newfile.sh");
opt->max_children_ = 8;
+ opt->children_policy_ = DEFER;
string_list_init(&opt->dirs_);
}
@@ -269,6 +286,8 @@ void options_print_usage()
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");
+ printf(" [-p|--children-policy] (defer,drop,kill-oldest)\n");
+ printf(" what to do when children limit exceeds\n");
printf(" [-d|--dir] <path> add a path to the watch list, can be invoked several times\n");
}
@@ -290,5 +309,11 @@ void options_print(options_t* opt)
printf("command_sock: '%s'\n", opt->command_sock_);
printf("script: '%s'\n", opt->script_);
printf("max_children: %d\n", opt->max_children_);
+ printf("children_policy: ");
+ switch(opt->children_policy_) {
+ case DEFER: printf("defer execution\n"); break;
+ case DROP: printf("drop\n"); break;
+ case KILL_OLDEST: printf("kill oldest\n"); break;
+ }
string_list_print(&opt->dirs_, " '", "'\n");
}
diff --git a/src/options.h b/src/options.h
index 0e95532..005a397 100644
--- a/src/options.h
+++ b/src/options.h
@@ -22,6 +22,7 @@
#ifndef DROPNROLL_options_h_INCLUDED
#define DROPNROLL_options_h_INCLUDED
+#include "datatypes.h"
#include "string_list.h"
struct options_struct {
@@ -37,6 +38,7 @@ struct options_struct {
char* command_sock_;
char* script_;
int max_children_;
+ children_policy_t children_policy_;
string_list_t dirs_;
};
typedef struct options_struct options_t;