From: Joel Rosdahl Date: Sat, 20 Mar 2021 19:07:43 +0000 (+0100) Subject: Clean up slightly after ea433578 X-Git-Tag: v4.2.1~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bfb7813a9920471091d9b147f3614970a90b60ea;p=thirdparty%2Fccache.git Clean up slightly after ea433578 --- diff --git a/src/Win32Util.hpp b/src/Win32Util.hpp index 7e02a4b2a..d6fc57595 100644 --- a/src/Win32Util.hpp +++ b/src/Win32Util.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -29,9 +29,9 @@ namespace Win32Util { std::string add_exe_suffix(const std::string& program); // Recreate a Windows command line string based on `argv`. If `prefix` is -// non-empty, add it as the first argument. -// If escape_backslashes is true, emit additional backslash for each backslash -// which is not preceding '"' and is not at the end of argv[i] either. +// non-empty, add it as the first argument. If `escape_backslashes` is true, +// emit an additional backslash for each backslash that is not preceding '"' and +// is not at the end of `argv[i]` either. std::string argv_to_string(const char* const* argv, const std::string& prefix, bool escape_backslashes = false); diff --git a/src/ccache.cpp b/src/ccache.cpp index b4c039e35..7d39e5bbc 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -2326,7 +2326,7 @@ cache_compilation(int argc, const char* const* argv) saved_orig_args = std::move(ctx.orig_args); auto execv_argv = saved_orig_args.to_argv(); LOG("Executing {}", Util::format_argv_for_logging(execv_argv.data())); - // Run execute_noreturn below after ctx and finalizer have been + // Execute the original command below after ctx and finalizer have been // destructed. } } @@ -2336,8 +2336,7 @@ cache_compilation(int argc, const char* const* argv) umask(*original_umask); } auto execv_argv = saved_orig_args.to_argv(); - execute_noreturn(const_cast(execv_argv.data()), - saved_temp_dir); + execute_noreturn(execv_argv.data(), saved_temp_dir); throw Fatal( "execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno)); } diff --git a/src/execute.cpp b/src/execute.cpp index 326d17bce..ebcf2becb 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2002 Andrew Tridgell -// Copyright (C) 2011-2020 Joel Rosdahl and other contributors +// Copyright (C) 2011-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -30,6 +30,7 @@ #include "fmtmacros.hpp" #ifdef _WIN32 +# include "Finalizer.hpp" # include "Win32Util.hpp" #endif @@ -127,13 +128,20 @@ win32execute(const char* path, std::string args = Win32Util::argv_to_string(argv, sh); std::string full_path = Win32Util::add_exe_suffix(path); std::string tmp_file_path; + + Finalizer tmp_file_remover([&tmp_file_path] { + if (!tmp_file_path.empty()) { + Util::unlink_tmp(tmp_file_path); + } + }); + if (args.length() > 8192) { TemporaryFile tmp_file(FMT("{}/cmd_args", temp_dir)); args = Win32Util::argv_to_string(argv + 1, sh, true); Util::write_fd(*tmp_file.fd, args.data(), args.length()); args = FMT("{} @{}", full_path, tmp_file.path); tmp_file_path = tmp_file.path; - LOG("args from file {}", tmp_file.path); + LOG("Arguments from {}", tmp_file.path); } BOOL ret = CreateProcess(full_path.c_str(), const_cast(args.c_str()), @@ -155,17 +163,10 @@ win32execute(const char* path, full_path, Win32Util::error_message(error), error); - if (!tmp_file_path.empty()) { - Util::unlink_tmp(tmp_file_path); - } return -1; } WaitForSingleObject(pi.hProcess, INFINITE); - if (!tmp_file_path.empty()) { - Util::unlink_tmp(tmp_file_path); - } - DWORD exitcode; GetExitCodeProcess(pi.hProcess, &exitcode); CloseHandle(pi.hProcess); @@ -229,7 +230,7 @@ execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err) } void -execute_noreturn(const char* const* argv, const std::string& /* unused */) +execute_noreturn(const char* const* argv, const std::string& /*temp_dir*/) { execv(argv[0], const_cast(argv)); }