From ad66c13417df44074f4fac737192b3943e22ce01 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 17 Jul 2026 14:11:04 -0700 Subject: [PATCH] Always perform exec in command. This avoids the shell process between the parent and the actual command when running without the fork server. Otherwise when running without fork server but in persistent mode, cleaning up the execution may end up getting the exit status of the shell process instead of the command process. PiperOrigin-RevId: 949754461 --- centipede/command.cc | 4 ++-- centipede/command_test.cc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/centipede/command.cc b/centipede/command.cc index 06cc79f0f..972a05627 100644 --- a/centipede/command.cc +++ b/centipede/command.cc @@ -205,7 +205,7 @@ std::string Command::ToString() const { ss.reserve(/*env*/ 1 + options_.env_diff.size() + /*path*/ 1 + /*args*/ options_.args.size() + /*out/err*/ 2); // env. - ss.push_back("env"); + ss.push_back("exec env"); std::vector env_to_set; env_to_set.reserve(options_.env_diff.size()); // Arguments that unset environment variables must appear first. @@ -285,7 +285,7 @@ bool Command::StartForkServer(std::string_view temp_dir_path, { CENTIPEDE_FORK_SERVER_FIFO0="%s" \ CENTIPEDE_FORK_SERVER_FIFO1="%s" \ - exec %s + %s } & printf "%%s" $! > "%s" )sh"; diff --git a/centipede/command_test.cc b/centipede/command_test.cc index 4e638b4b2..48f4d0730 100644 --- a/centipede/command_test.cc +++ b/centipede/command_test.cc @@ -39,18 +39,18 @@ namespace { using ::testing::Optional; TEST(CommandTest, ToString) { - EXPECT_EQ(Command{"x"}.ToString(), "env \\\nx"); + EXPECT_EQ(Command{"x"}.ToString(), "exec env \\\nx"); { Command::Options cmd_options; cmd_options.args = {"arg1", "arg2"}; EXPECT_EQ((Command{"path", std::move(cmd_options)}.ToString()), - "env \\\npath \\\narg1 \\\narg2"); + "exec env \\\npath \\\narg1 \\\narg2"); } { Command::Options cmd_options; cmd_options.env_diff = {"K1=V1", "K2=V2", "-K3"}; EXPECT_EQ((Command{"x", std::move(cmd_options)}.ToString()), - "env \\\n-u K3 \\\nK1=V1 \\\nK2=V2 \\\nx"); + "exec env \\\n-u K3 \\\nK1=V1 \\\nK2=V2 \\\nx"); } } @@ -80,7 +80,7 @@ TEST(CommandTest, InputFileWildCard) { Command::Options cmd_options; cmd_options.temp_file_path = "TEMP_FILE"; Command cmd{"foo bar @@ baz", std::move(cmd_options)}; - EXPECT_EQ(cmd.ToString(), "env \\\nfoo bar TEMP_FILE baz"); + EXPECT_EQ(cmd.ToString(), "exec env \\\nfoo bar TEMP_FILE baz"); } TEST(CommandTest, ForkServer) {