From 5da88529fedbb19a336894d4c12f60d960d1c3fd Mon Sep 17 00:00:00 2001 From: Bharat Middha <5100938+bmiddha@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:44:28 +0000 Subject: [PATCH] cleanup --- tests/syscalls/open.cc | 90 ------------------------------------------ 1 file changed, 90 deletions(-) delete mode 100644 tests/syscalls/open.cc diff --git a/tests/syscalls/open.cc b/tests/syscalls/open.cc deleted file mode 100644 index 93be129..0000000 --- a/tests/syscalls/open.cc +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "src/trace_exec.cc" - -// int open(const char *pathname, int flags); -// int open(const char *pathname, int flags, mode_t mode); - -int demo_open_syscall() -{ - std::cout << "running syscall" << std::endl; - const char *pathname = "/tmp"; - int flags = O_RDONLY; - int mode = 0; - syscall(SYS_open, pathname, flags, mode); - std::cout << "syscall finished" << std::endl; - exit(EXIT_SUCCESS); -} - -int main() -{ - -} - -int main2() -{ - int pipefd[2]; - if (pipe(pipefd) == -1) - { - throw std::runtime_error("pipe() failed!"); - } - - // this is a modified version of trace_exec() which instead skips running execve() - // run tracer and forward fd3 to the pipe, so that we can verify the output - pid_t tracer_pid = fork(); - if (tracer_pid == 0) - { - std::cout << "running tracer" << std::endl; - close(pipefd[0]); - dup2(pipefd[1], 3); - close(pipefd[1]); - - pid_t tracee_pid = fork(); - if (tracee_pid == 0) - { - std::cout << "running tracee" << std::endl; - - if (prepare_tracee() != 0) - { - std::runtime_error("prepare_tracee() failed!"); - } - - demo_open_syscall(); - } - else - { - std::cout << "tracee_pid: " << tracee_pid << std::endl; - if (run_tracer(tracee_pid) != 0) - { - std::runtime_error("run_tracer() failed!"); - } - std::cout << "tracer finished" << std::endl; - exit(EXIT_SUCCESS); - } - } - else - { - std::cout << "tracer_pid: " << tracer_pid << std::endl; - std::array buffer; - std::string result; - close(pipefd[1]); - - ssize_t bytes_read; - std::cout << "reading from pipe" << std::endl; - while ((bytes_read = read(pipefd[0], buffer.data(), buffer.size())) > 0) - { - result.append(buffer.data(), bytes_read); - } - close(pipefd[0]); - - std::cout << "waiting for child to finish" << std::endl; - int status; - waitpid(tracer_pid, &status, 0); - std::cout << "status: " << status << std::endl; - std::cout << "result: " << std::endl << result << std::endl; - } -}