diff --git a/doc/kcov.1 b/doc/kcov.1 index e8591959..d456cc4c 100644 --- a/doc/kcov.1 +++ b/doc/kcov.1 @@ -107,7 +107,7 @@ Set the python parser to use for Python programs (the default is python). Can be run with Python 3 on systems where Python 2 is the default. .TP \fB\-\-bash\-parser\fP=\fIPARSER\fP -Set the bash parser to use for shell scripts (the default is /bin/bash). +Set the bash parser to use for shell scripts (the default is bash). .TP \fB\-\-bash\-method\fP=\fIMETHOD\fP Use collection method \fIMETHOD\fP for bash scripts. The method can be either PS4, for use of diff --git a/src/configuration.cc b/src/configuration.cc index d81126f1..7429e684 100644 --- a/src/configuration.cc +++ b/src/configuration.cc @@ -572,7 +572,7 @@ class Configuration : public IConfiguration #ifdef __FreeBSD__ setKey("bash-command", "/usr/local/bin/bash"); #else - setKey("bash-command", "/bin/bash"); + setKey("bash-command", "bash"); #endif setKey("kernel-coverage-path", "/sys/kernel/debug/kprobe-coverage"); setKey("path-strip-level", 2); diff --git a/src/engines/bash-engine.cc b/src/engines/bash-engine.cc index 693171f2..a4e8125e 100644 --- a/src/engines/bash-engine.cc +++ b/src/engines/bash-engine.cc @@ -78,6 +78,14 @@ class BashEngine : public ScriptEngineBase return false; } + const std::string command = conf.keyAsString("bash-command"); + if (!executable_exists_in_path(command)) + { + error("Cannot find Bash parser '%s'", command.c_str()); + + return false; + } + m_bashSupportsXtraceFd = bashCanHandleXtraceFd(); std::string helperPath = IOutputHandler::getInstance().getBaseDirectory() + "bash-helper.sh"; @@ -165,7 +173,6 @@ class BashEngine : public ScriptEngineBase xtraceFd = rlim.rlim_cur / 4; #endif } - const std::string command = conf.keyAsString("bash-command"); bool usePS4 = conf.keyAsInt("bash-use-ps4"); // Revert to stderr if this bash version can't handle BASH_XTRACE @@ -228,13 +235,13 @@ class BashEngine : public ScriptEngineBase char **vec; int argcStart = 1; vec = (char **) xmalloc(sizeof(char *) * (argc + 3)); - vec[0] = xstrdup(conf.keyAsString("bash-command").c_str()); + vec[0] = xstrdup(command.c_str()); for (unsigned i = 0; i < argc; i++) vec[argcStart + i] = xstrdup(argv[i]); /* Execute the script */ - if (execv(vec[0], vec)) + if (execvp(vec[0], vec)) { perror("Failed to execute script"); diff --git a/src/engines/bash-execve-redirector.c b/src/engines/bash-execve-redirector.c index 8a2b444b..26ca01de 100644 --- a/src/engines/bash-execve-redirector.c +++ b/src/engines/bash-execve-redirector.c @@ -53,6 +53,7 @@ int execve(const char *filename, char * const argv[], char * const envp[]) && (strstr(startBytes, "/bin/sh") != NULL || strstr(startBytes, "/bin/bash") != NULL || strstr(startBytes, "/bin/ash") != NULL || strstr(startBytes, "/bin/dash") != NULL )) { + char *bashExec = "/bin/bash"; char **replacementArgv; unsigned i = 0; @@ -63,7 +64,7 @@ int execve(const char *filename, char * const argv[], char * const envp[]) unsigned arg = 0; replacementArgv = malloc(sizeof(char*) * (i + 4)); - replacementArgv[arg++] = strdup(kcovBash); + replacementArgv[arg++] = strdup(bashExec); if (!kcovUseDebugTrap) replacementArgv[arg++] = strdup(bashArg); replacementArgv[arg++] = strdup(filename); @@ -71,7 +72,7 @@ int execve(const char *filename, char * const argv[], char * const envp[]) replacementArgv[i + arg] = strdup(argv[i]); replacementArgv[i + arg] = NULL; - filename = strdup(kcovBash); + filename = strdup(bashExec); argv = replacementArgv; }