citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 766b1869141bb3450fa8bb47a2badf46956c9cf1
parent 73bd011960a38989305e3850b9565ae38b3be684
Author: Kyle Milz <kyle@0x30.net>
Date:   Sun,  7 Aug 2016 16:13:05 -0600

src: add some checking if we're run as citrun-inst

Diffstat:
Msrc/inst_main.cc | 14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -63,6 +63,7 @@ private: llvm::raw_fd_ostream m_log; pid_t m_pid; std::string m_pfx; + bool m_is_citruninst; }; CitrunInst::CitrunInst(int argc, char *argv[]) : @@ -70,7 +71,8 @@ CitrunInst::CitrunInst(int argc, char *argv[]) : m_ec(), m_log("citrun.log", m_ec, llvm::sys::fs::F_Append), m_pid(getpid()), - m_pfx(std::to_string(m_pid) + ": ") + m_pfx(std::to_string(m_pid) + ": "), + m_is_citruninst(false) { if (m_ec.value()) warnx("citrun.log: %s", m_ec.message().c_str()); @@ -95,6 +97,11 @@ CitrunInst::CitrunInst(int argc, char *argv[]) : m_args[0] = base_name; } + if (std::strcmp(m_args[0], "citrun-inst") == 0) { + m_log << m_pfx << "citrun-inst called directly.\n"; + m_is_citruninst = true; + } + setprogname("citrun-inst"); } @@ -333,6 +340,11 @@ CitrunInst::exec_compiler() { m_log.close(); + if (m_is_citruninst) { + m_log << m_pfx << "Running as citrun-inst, not re-exec()'ing\n"; + exit(0); + } + m_args.push_back(NULL); if (execvp(m_args[0], &m_args[0])) err(1, "execvp");