Merge "Solve the newtons method problem simultaneously when possible"
diff --git a/aos/util/BUILD b/aos/util/BUILD
index daacba1..a612438 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -35,33 +35,6 @@
)
cc_library(
- name = "run_command",
- srcs = [
- "run_command.cc",
- ],
- hdrs = [
- "run_command.h",
- ],
- target_compatible_with = ["@platforms//os:linux"],
- deps = [
- "//aos/logging",
- ],
-)
-
-cc_test(
- name = "run_command_test",
- srcs = [
- "run_command_test.cc",
- ],
- target_compatible_with = ["@platforms//os:linux"],
- deps = [
- ":run_command",
- "//aos/logging",
- "//aos/testing:googletest",
- ],
-)
-
-cc_library(
name = "math",
hdrs = ["math.h"],
target_compatible_with = ["@platforms//os:linux"],
diff --git a/aos/util/run_command.cc b/aos/util/run_command.cc
deleted file mode 100644
index 2711e8b..0000000
--- a/aos/util/run_command.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "aos/util/run_command.h"
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <csignal>
-
-#include "aos/logging/logging.h"
-
-namespace aos {
-namespace util {
-namespace {
-
-// RAII class to block SIGCHLD and then restore it on destruction.
-class BlockSIGCHLD {
- public:
- BlockSIGCHLD() {
- sigset_t to_block;
- sigemptyset(&to_block);
- sigaddset(&to_block, SIGCHLD);
- if (sigprocmask(SIG_BLOCK, &to_block, &original_blocked_) == -1) {
- AOS_PLOG(FATAL, "sigprocmask(SIG_BLOCK, %p, %p) failed", &to_block,
- &original_blocked_);
- }
- }
- ~BlockSIGCHLD() {
- if (sigprocmask(SIG_SETMASK, &original_blocked_, nullptr) == -1) {
- AOS_PLOG(FATAL, "sigprocmask(SIG_SETMASK, %p, nullptr) failed",
- &original_blocked_);
- }
- }
-
- private:
- sigset_t original_blocked_;
-};
-
-} // namespace
-
-int RunCommand(const char *command) {
- BlockSIGCHLD blocker;
- const pid_t pid = fork();
- switch (pid) {
- case 0: // in child
- {
- int new_stdin = open("/dev/null", O_RDONLY);
- if (new_stdin == -1) _exit(127);
- int new_stdout = open("/dev/null", O_WRONLY);
- if (new_stdout == -1) _exit(127);
- int new_stderr = open("/dev/null", O_WRONLY);
- if (new_stderr == -1) _exit(127);
- if (dup2(new_stdin, 0) != 0) _exit(127);
- if (dup2(new_stdout, 1) != 1) _exit(127);
- if (dup2(new_stderr, 2) != 2) _exit(127);
- execl("/bin/sh", "sh", "-c", command, nullptr);
- _exit(127);
- }
- case -1:
- return -1;
- default:
- int stat;
- while (waitpid(pid, &stat, 0) == -1) {
- if (errno != EINTR) {
- return -1;
- }
- }
- return stat;
- }
-}
-
-} // namespace util
-} // namespace aos
diff --git a/aos/util/run_command.h b/aos/util/run_command.h
deleted file mode 100644
index 02c6785..0000000
--- a/aos/util/run_command.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef AOS_UTIL_RUN_COMMAND_H_
-#define AOS_UTIL_RUN_COMMAND_H_
-
-namespace aos {
-namespace util {
-
-// Improved replacement for system(3). Doesn't block signals like system(3) and
-// is thread-safe. Also makes sure all 3 standard streams are /dev/null.
-//
-// This means that it passes command to `/bin/sh -c` and returns -1 or a status
-// like from wait(2).
-int RunCommand(const char *command);
-
-} // namespace util
-} // namespace aos
-
-#endif // AOS_UTIL_RUN_COMMAND_H_
diff --git a/aos/util/run_command_test.cc b/aos/util/run_command_test.cc
deleted file mode 100644
index 400d2f9..0000000
--- a/aos/util/run_command_test.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "aos/util/run_command.h"
-#include "gtest/gtest.h"
-#include <thread>
-
-namespace aos {
-namespace util {
-namespace testing {
-
-TEST(RunCommandTest, True) {
- int result = RunCommand("true");
- ASSERT_NE(-1, result);
- ASSERT_TRUE(WIFEXITED(result));
- EXPECT_EQ(0, WEXITSTATUS(result));
-}
-
-TEST(RunCommandTest, False) {
- int result = RunCommand("false");
- ASSERT_NE(-1, result);
- ASSERT_TRUE(WIFEXITED(result));
- EXPECT_EQ(1, WEXITSTATUS(result));
-}
-
-TEST(RunCommandTest, CommandNotFound) {
- int result = RunCommand("ajflkjasdlfa");
- ASSERT_NE(-1, result);
- ASSERT_TRUE(WIFEXITED(result));
- EXPECT_EQ(127, WEXITSTATUS(result));
-}
-
-TEST(RunCommandTest, KilledBySignal) {
- int result = RunCommand("kill -QUIT $$");
- ASSERT_NE(-1, result);
- ASSERT_TRUE(WIFSIGNALED(result));
- EXPECT_EQ(SIGQUIT, WTERMSIG(result));
-}
-
-TEST(RunCommandTest, MultipleThreads) {
- int result1, result2;
- std::thread t1([&result1]() {
- result1 = RunCommand("true");
- });
- std::thread t2([&result2]() {
- result2 = RunCommand("true");
- });
- t1.join();
- t2.join();
- ASSERT_NE(-1, result1);
- ASSERT_NE(-1, result2);
- ASSERT_TRUE(WIFEXITED(result1));
- ASSERT_TRUE(WIFEXITED(result2));
- EXPECT_EQ(0, WEXITSTATUS(result1));
- EXPECT_EQ(0, WEXITSTATUS(result2));
-}
-
-} // namespace testing
-} // namespace util
-} // namespace aos