[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: execvp searches in PATH too like popen, and returns if an error occurs, outputting the error string

git at icinga.org git at icinga.org
Fri Jul 16 16:05:52 CEST 2010

Module: icinga-core
Branch: mfriedrich/core
Commit: 67420d5ef3442b84818f6dd09e19af6316c406a8
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=67420d5ef3442b84818f6dd09e19af6316c406a8

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Fri Jul 16 16:05:23 2010 +0200

execvp searches in PATH too like popen, and returns if an error occurs, outputting the error string

revamped the previous attempt a bit. there might be discussions about
allowing PATH or not PATH env variables. But by completely breaking
compatibility this won't be nice.

the current attempt only checks if the first argument is set and then
calling execvp - this looks in $PATH if there is no trailing slash set
on the executable.
In case of an error, execvp returns -1 and this is where the error is
put into syslog, exiting with state unknown. (a further adaption would be
setting the output of the plugin like popen behaves)

if you consider not using the PATH for that, you can simply change execvp to
execv and recompile the code. The checks on executable/there are still valid,
except PATH lookups.

refs #436
refs #617


 Changelog     |    3 ++-
 base/checks.c |   21 +++++++--------------
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/Changelog b/Changelog
index 9de507c..59f6066 100644
--- a/Changelog
+++ b/Changelog
@@ -7,9 +7,9 @@ Icinga 1.0.x Change Log
-* core: check permissions before calling execv on a command
 * core: fix temp_path overwritten by check_result_path in base/config.c
 * core: modify execv to execvp, accepting 4096 cmd args, for both host and service checks with adapted error handling
+* core: execvp searches in PATH too like popen, and returns if error, outputting the errno string
 * classic ui: fix image urls ins stylesheets
@@ -17,6 +17,7 @@ FIXES
 * install: enable debuginfo in spec file
 * idoutils: adapt oracle-drop.sql for current schema
+* idoutils: fix binding null values to prepared statements in oracle
 1.0.2 - 30/06/2010
diff --git a/base/checks.c b/base/checks.c
index a510d15..2c1617f 100644
--- a/base/checks.c
+++ b/base/checks.c
@@ -226,24 +226,17 @@ static int run_check(char *processed_command,dbuf *checkresult_dbuf){
 			/* extract command args for execv */
-			if(!argv[0])
-				_exit(STATE_UNKNOWN);
-			/* check if plugin there/executable */
-			if (access(argv[0], R_OK) !=0 ) {
-				fprintf(stdout,"plugin %s does not exist or is not readable\n",argv[0]);
-				logit(NSLOG_RUNTIME_WARNING,TRUE,"plugin %s does not exists or is not readable\n",argv[0]);
+			if(!argv[0]){
+				logit(NSLOG_RUNTIME_WARNING,TRUE,"plugin command definition empty\n");
-			if (access(argv[0], X_OK) != 0  ) {
-				fprintf(stdout,"wrong execution permissions on plugin %s\n",argv[0]);
-				logit(NSLOG_RUNTIME_WARNING,TRUE,"wrong execution permissions on plugin %s\n",argv[0]);
+			log_debug_info(DEBUGL_CHECKS,0,"running command %s via execvp\n",processed_command);
+			if(execvp(argv[0], argv)<0){ /* execvp only returns in case of an error */
+				logit(NSLOG_RUNTIME_WARNING,TRUE,"error executing command '%s': %s. Make sure that the file actually exists (in PATH, if set) and is executable!\n",processed_command, strerror(errno));
-			log_debug_info(DEBUGL_CHECKS,0,"running process %s via execv\n",processed_command);
-			execvp(argv[0], argv); /* instead of execvp since we don't use path */
@@ -266,7 +259,7 @@ static int run_check(char *processed_command,dbuf *checkresult_dbuf){
-		log_debug_info(DEBUGL_CHECKS,0,"running process %s via popen\n",processed_command);
+		log_debug_info(DEBUGL_CHECKS,0,"running command %s via popen\n",processed_command);

More information about the icinga-checkins mailing list