summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohan Mars <code@rohanmars.com>2015-10-27 04:30:17 +0100
committerRohan Mars <code@rohanmars.com>2015-11-13 02:29:21 +0100
commit671ab30ae93760bb73301f4c29b65aa151b2987b (patch)
treeb91d79252ecc1a4422f402cc63208520b2b75bf3
parentMerge pull request #6316 from dillaman/wip-13494 (diff)
downloadceph-671ab30ae93760bb73301f4c29b65aa151b2987b.tar.xz
ceph-671ab30ae93760bb73301f4c29b65aa151b2987b.zip
stdin/stdout/stderr clash with standard definition, renamed to getter/setter
Signed-off-by: Rohan Mars <code@rohanmars.com>
-rw-r--r--src/common/SubProcess.h25
-rw-r--r--src/crush/CrushTester.cc4
-rw-r--r--src/test/test_subprocess.cc44
3 files changed, 37 insertions, 36 deletions
diff --git a/src/common/SubProcess.h b/src/common/SubProcess.h
index 18d6e92562c..8b8ffc7cc8d 100644
--- a/src/common/SubProcess.h
+++ b/src/common/SubProcess.h
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <signal.h>
#include <sstream>
#include <vector>
@@ -44,9 +45,9 @@
* std::cerr << "cat failed: " << cat.err() << std::endl;
* return false;
* }
- * write_to_fd(cat.stdout(), "hello world!\n");
+ * write_to_fd(cat.get_stdout(), "hello world!\n");
* cat.close_stdout();
- * read_from_fd(cat.stdin(), buf);
+ * read_from_fd(cat.get_stdin(), buf);
* if (cat.join() != 0) {
* std::cerr << cat.err() << std::endl;
* return false;
@@ -67,9 +68,9 @@ public:
bool is_spawned() const { return pid > 0; }
- int stdin() const;
- int stdout() const;
- int stderr() const;
+ int get_stdin() const;
+ int get_stdout() const;
+ int get_stderr() const;
void close_stdin();
void close_stdout();
@@ -113,12 +114,12 @@ private:
int sigkill;
};
-SubProcess::SubProcess(const char *cmd_, bool stdin, bool stdout, bool stderr) :
+SubProcess::SubProcess(const char *cmd_, bool use_stdin, bool use_stdout, bool use_stderr) :
cmd(cmd_),
cmd_args(),
- pipe_stdin(stdin),
- pipe_stdout(stdout),
- pipe_stderr(stderr),
+ pipe_stdin(use_stdin),
+ pipe_stdout(use_stdout),
+ pipe_stderr(use_stderr),
stdin_pipe_out_fd(-1),
stdout_pipe_in_fd(-1),
stderr_pipe_in_fd(-1),
@@ -152,21 +153,21 @@ void SubProcess::add_cmd_arg(const char *arg) {
cmd_args.push_back(arg);
}
-int SubProcess::stdin() const {
+int SubProcess::get_stdin() const {
assert(is_spawned());
assert(pipe_stdin);
return stdin_pipe_out_fd;
}
-int SubProcess::stdout() const {
+int SubProcess::get_stdout() const {
assert(is_spawned());
assert(pipe_stdout);
return stdout_pipe_in_fd;
}
-int SubProcess::stderr() const {
+int SubProcess::get_stderr() const {
assert(is_spawned());
assert(pipe_stderr);
diff --git a/src/crush/CrushTester.cc b/src/crush/CrushTester.cc
index 086383385b1..11b536c1877 100644
--- a/src/crush/CrushTester.cc
+++ b/src/crush/CrushTester.cc
@@ -381,10 +381,10 @@ int CrushTester::test_with_crushtool(const char *crushtool_cmd,
bufferlist bl;
::encode(crush, bl);
- bl.write_fd(crushtool.stdin());
+ bl.write_fd(crushtool.get_stdin());
crushtool.close_stdin();
bl.clear();
- ret = bl.read_fd(crushtool.stderr(), 100 * 1024);
+ ret = bl.read_fd(crushtool.get_stderr(), 100 * 1024);
if (ret < 0) {
err << "failed read from crushtool: " << cpp_strerror(-ret);
return ret;
diff --git a/src/test/test_subprocess.cc b/src/test/test_subprocess.cc
index c07538bfd8a..725d2a6e81e 100644
--- a/src/test/test_subprocess.cc
+++ b/src/test/test_subprocess.cc
@@ -54,7 +54,7 @@ TEST(SubProcess, NotFound)
SubProcess p("NOTEXISTENTBINARY", false, false, true);
ASSERT_EQ(p.spawn(), 0);
std::string buf;
- ASSERT_TRUE(read_from_fd(p.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(p.get_stderr(), buf));
std::cerr << "stderr: " << buf;
ASSERT_EQ(p.join(), 1);
std::cerr << "err: " << p.err() << std::endl;
@@ -68,7 +68,7 @@ TEST(SubProcess, Echo)
ASSERT_EQ(echo.spawn(), 0);
std::string buf;
- ASSERT_TRUE(read_from_fd(echo.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(echo.get_stdout(), buf));
std::cerr << "stdout: " << buf;
ASSERT_EQ(buf, "1 2 3\n");
ASSERT_EQ(echo.join(), 0);
@@ -81,14 +81,14 @@ TEST(SubProcess, Cat)
ASSERT_EQ(cat.spawn(), 0);
std::string msg("to my, trociny!");
- int n = write(cat.stdin(), msg.c_str(), msg.size());
+ int n = write(cat.get_stdin(), msg.c_str(), msg.size());
ASSERT_EQ(n, (int)msg.size());
cat.close_stdin();
std::string buf;
- ASSERT_TRUE(read_from_fd(cat.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stdout(), buf));
std::cerr << "stdout: " << buf << std::endl;
ASSERT_EQ(buf, msg);
- ASSERT_TRUE(read_from_fd(cat.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stderr(), buf));
ASSERT_EQ(buf, "");
ASSERT_EQ(cat.join(), 0);
ASSERT_TRUE(cat.err()[0] == '\0');
@@ -101,9 +101,9 @@ TEST(SubProcess, CatDevNull)
ASSERT_EQ(cat.spawn(), 0);
std::string buf;
- ASSERT_TRUE(read_from_fd(cat.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stdout(), buf));
ASSERT_EQ(buf, "");
- ASSERT_TRUE(read_from_fd(cat.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stderr(), buf));
ASSERT_EQ(buf, "");
ASSERT_EQ(cat.join(), 0);
ASSERT_TRUE(cat.err()[0] == '\0');
@@ -127,14 +127,14 @@ TEST(SubProcess, CatWithArgs)
ASSERT_EQ(cat.spawn(), 0);
std::string msg("Hello, Word!");
- int n = write(cat.stdin(), msg.c_str(), msg.size());
+ int n = write(cat.get_stdin(), msg.c_str(), msg.size());
ASSERT_EQ(n, (int)msg.size());
cat.close_stdin();
std::string buf;
- ASSERT_TRUE(read_from_fd(cat.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stdout(), buf));
std::cerr << "stdout: " << buf << std::endl;
ASSERT_EQ(buf, msg);
- ASSERT_TRUE(read_from_fd(cat.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stderr(), buf));
std::cerr << "stderr: " << buf;
ASSERT_FALSE(buf.empty());
ASSERT_EQ(cat.join(), 1);
@@ -152,14 +152,14 @@ TEST(SubProcess, Subshell)
"/bin/sh -c 'exit 13'", NULL);
ASSERT_EQ(sh.spawn(), 0);
std::string msg("hello via subshell");
- int n = write(sh.stdin(), msg.c_str(), msg.size());
+ int n = write(sh.get_stdin(), msg.c_str(), msg.size());
ASSERT_EQ(n, (int)msg.size());
sh.close_stdin();
std::string buf;
- ASSERT_TRUE(read_from_fd(sh.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stdout(), buf));
std::cerr << "stdout: " << buf << std::endl;
ASSERT_EQ(buf, msg);
- ASSERT_TRUE(read_from_fd(sh.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stderr(), buf));
std::cerr << "stderr: " << buf;
ASSERT_EQ(buf, "error from subshell\n");
ASSERT_EQ(sh.join(), 13);
@@ -192,9 +192,9 @@ TEST(SubProcessTimed, Killed)
ASSERT_EQ(cat.spawn(), 0);
cat.kill();
std::string buf;
- ASSERT_TRUE(read_from_fd(cat.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stdout(), buf));
ASSERT_TRUE(buf.empty());
- ASSERT_TRUE(read_from_fd(cat.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(cat.get_stderr(), buf));
ASSERT_TRUE(buf.empty());
ASSERT_EQ(cat.join(), 128 + SIGTERM);
std::cerr << "err: " << cat.err() << std::endl;
@@ -208,7 +208,7 @@ TEST(SubProcessTimed, SleepTimedout)
ASSERT_EQ(sleep.spawn(), 0);
std::string buf;
- ASSERT_TRUE(read_from_fd(sleep.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(sleep.get_stderr(), buf));
std::cerr << "stderr: " << buf;
ASSERT_FALSE(buf.empty());
ASSERT_EQ(sleep.join(), 128 + SIGKILL);
@@ -222,14 +222,14 @@ TEST(SubProcessTimed, SubshellNoTimeout)
sh.add_cmd_args("-c", "cat >&2", NULL);
ASSERT_EQ(sh.spawn(), 0);
std::string msg("the quick brown fox jumps over the lazy dog");
- int n = write(sh.stdin(), msg.c_str(), msg.size());
+ int n = write(sh.get_stdin(), msg.c_str(), msg.size());
ASSERT_EQ(n, (int)msg.size());
sh.close_stdin();
std::string buf;
- ASSERT_TRUE(read_from_fd(sh.stdout(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stdout(), buf));
std::cerr << "stdout: " << buf << std::endl;
ASSERT_TRUE(buf.empty());
- ASSERT_TRUE(read_from_fd(sh.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stderr(), buf));
std::cerr << "stderr: " << buf << std::endl;
ASSERT_EQ(buf, msg);
ASSERT_EQ(sh.join(), 0);
@@ -242,11 +242,11 @@ TEST(SubProcessTimed, SubshellKilled)
sh.add_cmd_args("-c", "sh -c cat", NULL);
ASSERT_EQ(sh.spawn(), 0);
std::string msg("etaoin shrdlu");
- int n = write(sh.stdin(), msg.c_str(), msg.size());
+ int n = write(sh.get_stdin(), msg.c_str(), msg.size());
ASSERT_EQ(n, (int)msg.size());
sh.kill();
std::string buf;
- ASSERT_TRUE(read_from_fd(sh.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stderr(), buf));
ASSERT_TRUE(buf.empty());
ASSERT_EQ(sh.join(), 128 + SIGTERM);
std::cerr << "err: " << sh.err() << std::endl;
@@ -259,7 +259,7 @@ TEST(SubProcessTimed, SubshellTimedout)
sh.add_cmd_args("-c", "sleep 1000& cat; NEVER REACHED", NULL);
ASSERT_EQ(sh.spawn(), 0);
std::string buf;
- ASSERT_TRUE(read_from_fd(sh.stderr(), buf));
+ ASSERT_TRUE(read_from_fd(sh.get_stderr(), buf));
std::cerr << "stderr: " << buf;
ASSERT_FALSE(buf.empty());
ASSERT_EQ(sh.join(), 128 + SIGTERM);