From 24b575bb93d0229eb4ef231e1e644118e363808e Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Wed, 19 Jun 2019 16:57:40 +0300 Subject: [PATCH] Print error if child process cannot access monitor script file --- server/core/externcmd.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/core/externcmd.cc b/server/core/externcmd.cc index 69e888299..b23dfc7eb 100644 --- a/server/core/externcmd.cc +++ b/server/core/externcmd.cc @@ -108,7 +108,7 @@ std::unique_ptr ExternalCmd::create(const string& argstr, int timeo } else { - MXS_ERROR("Cannot execute file '%s'. Missing execution permissions.", cmdname); + MXS_ERROR("Cannot execute file '%s'. Missing execution permission.", cmdname); } } else @@ -239,8 +239,21 @@ int ExternalCmd::externcmd_execute() // Execute the command execvp(cmdname, argvec); - // Close the write end of the pipe and exit - close(fd[1]); + // This is only reached if execvp failed to start the command. Print to the standard error stream. + // The message will be caught by the parent process. + int error = errno; + if (error == EACCES) + { + // This is the most likely error, handle separately. + fprintf(stderr, "error: Cannot execute file. File cannot be accessed or it is missing " + "execution permission."); + } + else + { + fprintf(stderr, "error: Cannot execute file. 'execvp' error: '%s'", strerror(error)); + } + fflush(stderr); + // Exit with error. The write end of the pipe should close by itself. _exit(1); } else