Creates the shell script on disk and returns the path to it.
()
| 66 | |
| 67 | /// Creates the shell script on disk and returns the path to it. |
| 68 | fn create_run_script() -> anyhow::Result<TempPath> { |
| 69 | // The command is wrapped in a shell script, which executes it in a |
| 70 | // subprocess and then writes the exit code to a file. The process will |
| 71 | // always exit with status code 0, unless valgrind fails. |
| 72 | // |
| 73 | // Args: |
| 74 | // 1. The command to execute |
| 75 | // 2. The path to the file where the exit code will be written |
| 76 | const WRAPPER_SCRIPT: &str = r#"#!/usr/bin/env bash |
| 77 | bash -c "$1" |
| 78 | status=$? |
| 79 | echo -n "$status" > "$2" |
| 80 | "#; |
| 81 | |
| 82 | let rwx = std::fs::Permissions::from_mode(0o777); |
| 83 | let mut script_file = tempfile::Builder::new() |
| 84 | .suffix(".sh") |
| 85 | .permissions(rwx) |
| 86 | .tempfile()?; |
| 87 | script_file.write_all(WRAPPER_SCRIPT.as_bytes())?; |
| 88 | |
| 89 | // Note: We have to convert the file to a path to be able to execute it. |
| 90 | // Otherwise this will fail with 'File is busy' error. |
| 91 | Ok(script_file.into_temp_path()) |
| 92 | } |
| 93 | |
| 94 | /// Dumps every per-process `valgrind.<pid>.log` in the folder to help debug a failure. |
| 95 | fn dump_valgrind_logs(profile_folder: &Path) { |