[Pkg-nagios-changes] [SCM] Debian packaging for mod gearman. branch, upstream, updated. upstream/1.0.6-34-gd3fb2ec
Sven Nierlein
sven at nierlein.de
Wed Aug 24 09:22:02 UTC 2011
The following commit has been merged in the upstream branch:
commit 91bcf22aad488dc34fc46f0a4a5ccff1e92f32b6
Author: Sven Nierlein <sven at nierlein.de>
Date: Mon Aug 15 18:16:49 2011 +0200
check server definition for duplicates
diff --git a/Changes b/Changes
index 92d5103..712ed67 100644
--- a/Changes
+++ b/Changes
@@ -6,6 +6,7 @@ This file documents the revision history for mod_gearman.
- added optional workaround for plugins exiting with rc 25 because
of duplicate execution
- removed version output to stderr while reloading/starting the core
+ - check server definition for duplicates
1.0.8 Fri Jul 22 22:21:34 CEST 2011
- use identifier for error messages if set
diff --git a/common/utils.c b/common/utils.c
index ead2aaf..ab8b976 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -290,7 +290,6 @@ int parse_yes_or_no(char*value, int dfl) {
int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
char *key;
char *value;
- char temp_buffer[GM_BUFFERSIZE];
gm_log( GM_LOG_TRACE, "parse_args_line(%s, %d)\n", arg, recursion_level);
@@ -570,16 +569,9 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
else if ( !strcmp( key, "server" ) ) {
char *servername;
while ( (servername = strsep( &value, "," )) != NULL ) {
- servername = trim(servername);
- if ( strcmp( servername, "" ) ) {
- if(strcspn(servername, ":") == 0) {
- temp_buffer[0]='\x0';
- snprintf( temp_buffer,sizeof( temp_buffer )-1, "localhost%s", servername);
- temp_buffer[sizeof( temp_buffer )-1]='\x0';
- opt->server_list[opt->server_num] = strdup(temp_buffer);
- } else {
- opt->server_list[opt->server_num] = strdup(servername);
- }
+ char * new_server = get_param_server(servername, opt->server_list, opt->server_num);
+ if(new_server != NULL) {
+ opt->server_list[opt->server_num] = new_server;
opt->server_num++;
}
}
@@ -589,9 +581,9 @@ int parse_args_line(mod_gm_opt_t *opt, char * arg, int recursion_level) {
else if ( !strcmp( key, "dupserver" ) ) {
char *servername;
while ( (servername = strsep( &value, "," )) != NULL ) {
- servername = trim(servername);
- if ( strcmp( servername, "" ) ) {
- opt->dupserver_list[opt->dupserver_num] = strdup(servername);
+ char * new_server = get_param_server(servername, opt->dupserver_list, opt->dupserver_num);
+ if(new_server != NULL) {
+ opt->dupserver_list[opt->dupserver_num] = new_server;
opt->dupserver_num++;
}
}
@@ -1817,3 +1809,35 @@ void gm_log( int lvl, const char *text, ... ) {
return;
}
+
+/* extract server from string and check for duplicates */
+char * get_param_server(char * servername, char * server_list[GM_LISTSIZE], int server_num) {
+ char temp_buffer[GM_BUFFERSIZE];
+ char * new_server;
+ int i;
+ servername = trim(servername);
+
+ if ( ! strcmp( servername, "" ) ) {
+ return NULL;
+ }
+
+ if(strcspn(servername, ":") == 0) {
+ temp_buffer[0]='\x0';
+ snprintf( temp_buffer,sizeof( temp_buffer )-1, "localhost%s", servername);
+ temp_buffer[sizeof( temp_buffer )-1]='\x0';
+ new_server = strdup(temp_buffer);
+ } else {
+ new_server = strdup(servername);
+ }
+
+ // check for duplicates
+ for(i=0;i<server_num;i++) {
+ if ( ! strcmp( new_server, server_list[i] ) ) {
+ gm_log( GM_LOG_ERROR, "duplicate definition of server: %s\n", new_server);
+ free(new_server);
+ return NULL;
+ }
+ }
+
+ return new_server;
+}
diff --git a/include/utils.h b/include/utils.h
index 008d6ce..e19a945 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -468,7 +468,10 @@ char * eventtype2str(int i);
*/
void gm_log( int lvl, const char *text, ... );
-/** write log line with core logger
+/**
+ * write_core_log
+ *
+ * write log line with core logger
*
* @param[in] data - log message
*
@@ -476,6 +479,20 @@ void gm_log( int lvl, const char *text, ... );
*/
void write_core_log(char *data);
+
+/**
+ * get_param_server
+ *
+ * return string of new server or NULL on duplicate
+ *
+ * @param[in] servername - server name to parse
+ * @param[in] server_list - list of servers to check for duplicates
+ * @param[in] server_num - number of server in this list
+ *
+ * @returns the new server name or NULL
+ */
+char * get_param_server(char * servername, char * server_list[GM_LISTSIZE], int server_num);
+
/**
* @}
*/
diff --git a/t/01-utils.c b/t/01-utils.c
index 3e0aa63..5ba1dc8 100644
--- a/t/01-utils.c
+++ b/t/01-utils.c
@@ -17,8 +17,18 @@ void printf_hex(char* text, int length) {
return;
}
+mod_gm_opt_t * renew_opts(void);
+mod_gm_opt_t * renew_opts() {
+ mod_gm_opt_t *mod_gm_opt;
+
+ mod_gm_opt = malloc(sizeof(mod_gm_opt_t));
+ set_default_options(mod_gm_opt);
+
+ return mod_gm_opt;
+}
+
int main(void) {
- plan(48);
+ plan(55);
/* lowercase */
char test[100];
@@ -57,8 +67,7 @@ int main(void) {
strcpy(test, " test "); like(trim(test), "test", "trim(' test ')");
/* reading keys */
- mod_gm_opt_t *mod_gm_opt;
- mod_gm_opt = malloc(sizeof(mod_gm_opt_t));
+ mod_gm_opt_t *mod_gm_opt = renew_opts();
int rc = set_default_options(mod_gm_opt);
ok(rc == 0, "setting default options");
mod_gm_opt->keyfile = strdup("t/data/test1.key");
@@ -153,13 +162,36 @@ int main(void) {
ok(t.tv_usec == 0, "string2timeval 8");
/* command line parsing */
+ mod_gm_free_opt(mod_gm_opt);
+ mod_gm_opt = renew_opts();
strcpy(test, "server=host:4730");
parse_args_line(mod_gm_opt, test, 0);
like(mod_gm_opt->server_list[0], "host:4730", "server=host:4730");
+ ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num);
+ mod_gm_free_opt(mod_gm_opt);
+ mod_gm_opt = renew_opts();
strcpy(test, "server=:4730");
parse_args_line(mod_gm_opt, test, 0);
- like(mod_gm_opt->server_list[1], "localhost:4730", "server=:4730");
+ like(mod_gm_opt->server_list[0], "localhost:4730", "server=:4730");
+ ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num);
+
+ mod_gm_free_opt(mod_gm_opt);
+ mod_gm_opt = renew_opts();
+ strcpy(test, "server=localhost:4730");
+ parse_args_line(mod_gm_opt, test, 0);
+ strcpy(test, "server=localhost:4730");
+ parse_args_line(mod_gm_opt, test, 0);
+ like(mod_gm_opt->server_list[0], "localhost:4730", "duplicate server");
+ ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num);
+
+ mod_gm_free_opt(mod_gm_opt);
+ mod_gm_opt = renew_opts();
+ strcpy(test, "server=localhost:4730,localhost:4730,:4730,host:4730,");
+ parse_args_line(mod_gm_opt, test, 0);
+ like(mod_gm_opt->server_list[0], "localhost:4730", "duplicate server");
+ like(mod_gm_opt->server_list[1], "host:4730", "duplicate server");
+ ok(mod_gm_opt->server_num == 2, "server_number = %d", mod_gm_opt->server_num);
mod_gm_free_opt(mod_gm_opt);
@@ -171,3 +203,4 @@ void write_core_log(char *data) {
printf("core logger is not available for tests: %s", data);
return;
}
+
--
Debian packaging for mod gearman.
More information about the Pkg-nagios-changes
mailing list