[Nagios-checkins] SF.net SVN: nagios:[2183] nagioscore/trunk/common/objects.c
Nagios network monitoring software is enterprise server monitoring
Brought to you by:
egalstad,
sawolf-nagios
From: <ag...@us...> - 2012-09-12 15:35:56
|
Revision: 2183 http://nagios.svn.sourceforge.net/nagios/?rev=2183&view=rev Author: ageric Date: 2012-09-12 15:35:49 +0000 (Wed, 12 Sep 2012) Log Message: ----------- common/objects: Make 'address' optional for hosts Many people put fully qualified dns names as host_names and don't really need or want to put in an extra 'address' field. We humor them with this patch, assigning the host_name to the address field in case address isn't set. While at it, we do the same for 'alias', which was previously copied (rather than assigned), and naturally make sure that all variables are free()'d safely or ignored correctly at cleanup time. Signed-off-by: Andreas Ericsson <ae...@op...> Modified Paths: -------------- nagioscore/trunk/common/objects.c Modified: nagioscore/trunk/common/objects.c =================================================================== --- nagioscore/trunk/common/objects.c 2012-09-11 01:13:42 UTC (rev 2182) +++ nagioscore/trunk/common/objects.c 2012-09-12 15:35:49 UTC (rev 2183) @@ -416,8 +416,8 @@ #endif /* make sure we have the data we need */ - if((name == NULL || !strcmp(name, "")) || (address == NULL || !strcmp(address, ""))) { - logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host name or address is NULL\n"); + if(name == NULL || !strcmp(name, "")) { + logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Host name is NULL\n"); return NULL; } @@ -457,19 +457,12 @@ /* duplicate string vars */ if((new_host->name = (char *)strdup(name)) == NULL) + return NULL; + new_host->display_name = display_name ? strdup(display_name) : new_host->name; + new_host->alias = alias ? strdup(alias) : new_host->name; + new_host->address = address ? strdup(address) : new_host->name; + if(!new_host->display_name || !new_host->alias || !new_host->address) result = ERROR; - if(display_name) { - if((new_host->display_name = (char *)strdup(display_name)) == NULL) - result = ERROR; - } - else { - new_host->display_name = new_host->name; - } - - if((new_host->alias = (char *)strdup((alias == NULL) ? name : alias)) == NULL) - result = ERROR; - if((new_host->address = (char *)strdup(address)) == NULL) - result = ERROR; new_host->check_period = check_tp ? check_tp->name : NULL; new_host->notification_period = notify_tp ? notify_tp->name : NULL; #ifndef NSCGI @@ -2616,9 +2609,11 @@ if(this_host->display_name != this_host->name) my_free(this_host->display_name); + if(this_host->alias != this_host->name) + my_free(this_host->alias); + if(this_host->address != this_host->name) + my_free(this_host->address); my_free(this_host->name); - my_free(this_host->alias); - my_free(this_host->address); #ifdef NSCORE my_free(this_host->plugin_output); my_free(this_host->long_plugin_output); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |