20 namespace bf = std::filesystem;
26 if ((pid = fork()) < 0) {
32 execlp(
shell.c_str(),
"sh",
"-c",
script.c_str(),
static_cast<char const*
>(
nullptr));
33 std::cerr <<
"child failed becuase '" << strerror(errno) <<
"'\n";
36 while (waitpid(pid, &
status, 0) < 0) {
38 std::cerr <<
"child process failed " << strerror(errno) <<
"\n";
43 std::cerr <<
"child existed because of a signal " << WTERMSIG(
status) <<
"\n";
48 std::cerr <<
"child existed because of a signal " << WTERMSIG(
status) <<
"\n";
57 bf::path currentPath(bf::current_path().
string());
60 std::cout <<
"Usage: " <<
argv[0] <<
" shell subdir script1 script2 ... scriptN\n\n" 61 <<
"where shell is the path+shell (e.g., /bin/bash) intended to run the scripts\n" 62 <<
"and subdir is the subsystem/package/subdir in which the scripts are found\n" 63 <<
"(e.g., FWCore/Utilities/test)\n" 66 std::cout <<
"Current directory is: " << currentPath.string() <<
'\n';
69 for (
int i = 0;
env[
i] !=
nullptr; ++
i)
76 char const* goodDirectory =
"[A-Za-z0-9/_.-]+";
78 for (
int i = 0;
i <
argc; ++
i) {
85 std::cout <<
"Current directory is: " << currentPath.string() <<
'\n';
88 char const* topdir = std::getenv(
"SCRAMRT_LOCALRT");
90 topdir = std::getenv(
"LOCALRT");
93 std::cerr <<
"Invalid top directory '" << topdir <<
"'" << std::endl;
96 }
catch (std::runtime_error
const&
e) {
97 std::cerr <<
"Invalid top directory '" << topdir <<
"'" << std::endl;
102 char const*
arch = std::getenv(
"SCRAM_ARCH");
107 std::string maybe_arch = exepath.parent_path().filename().string();
109 if (setenv(
"SCRAM_ARCH", maybe_arch.c_str(), 1) != 0) {
110 std::cerr <<
"SCRAM_ARCH not set and attempt to set it failed\n";
113 arch = std::getenv(
"SCRAM_ARCH");
119 std::cerr <<
"Neither SCRAMRT_LOCALRT nor LOCALRT is defined" << std::endl;
125 std::cerr <<
"Invalid test directory '" <<
argv[2] <<
"'" << std::endl;
128 }
catch (std::runtime_error
const&
e) {
129 std::cerr <<
"Invalid test directory '" <<
argv[2] <<
"'" << std::endl;
144 std::cout <<
"topdir is: " << topdir <<
'\n';
145 std::cout <<
"testdir is: " << testdir <<
'\n';
146 std::cout <<
"tmpdir is: " << tmpdir <<
'\n';
147 std::cout <<
"testbin is: " << testbin <<
'\n';
149 if (setenv(
"LOCAL_TEST_DIR", testdir.c_str(), 1) != 0) {
150 std::cerr <<
"Could not set LOCAL_TEST_DIR to " << testdir << std::endl;
153 if (setenv(
"LOCAL_TMP_DIR", tmpdir.c_str(), 1) != 0) {
154 std::cerr <<
"Could not set LOCAL_TMP_DIR to " << tmpdir << std::endl;
157 if (setenv(
"LOCAL_TOP_DIR", topdir, 1) != 0) {
158 std::cerr <<
"Could not set LOCAL_TOP_DIR to " << topdir << std::endl;
161 if (setenv(
"LOCAL_TEST_BIN", testbin.c_str(), 1) != 0) {
162 std::cerr <<
"Could not set LOCAL_TEST_BIN to " << testbin << std::endl;
168 for (
int i = 3;
i <
argc && rc == 0; ++
i) {
170 scriptname +=
argv[
i];
171 std::cout <<
"Running script: " << scriptname << std::endl;
175 std::cout <<
"status = " << rc << std::endl;
176 return rc == 0 ? 0 : -1;
183 std::cerr <<
"Caught an edm::Exception in " <<
argv[0] <<
'\n' <<
x;
185 std::cerr <<
"Caught a cms::Exception in " <<
argv[0] <<
'\n' <<
x;
187 std::cerr <<
"Caught a std::exception in " <<
argv[0] <<
'\n' <<
x.what();
int do_work(int argc, char *argv[], char **env)
bool untaintString(char const *pattern, char const *regexp)
int run_script(std::string const &shell, std::string const &script)
int ptomaine(int argc, char *argv[], char **env)