From: Petr Tesarik <ptesarik@suse.cz>
Subject: Remove unused features from class Process
References: FATE#318874, bsc#917747
Patch-mainline: never

Simplify class Process to limit the scope of backporting.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 kdumptool/CMakeLists.txt |   19 ---------
 kdumptool/process.cc     |   91 -----------------------------------------------
 kdumptool/process.h      |   69 -----------------------------------
 3 files changed, 1 insertion(+), 178 deletions(-)

--- a/kdumptool/CMakeLists.txt
+++ b/kdumptool/CMakeLists.txt
@@ -93,25 +93,6 @@ add_executable(kdumptool ${KDUMPTOOL_SRC
 target_link_libraries(kdumptool ${EXTRA_LIBS})
 install (TARGETS kdumptool DESTINATION sbin)
 
-SET(TESTIO_SRC
-    optionparser.cc
-    optionparser.h
-    process.h
-    process.cc
-    util.h
-    util.cc
-    stringutil.h
-    stringutil.cc
-    global.cc
-    global.h
-    debug.cc
-    debug.h
-    testio.cc
-)
-
-add_executable(testio ${TESTIO_SRC})
-target_link_libraries(testio ${EXTRA_LIBS})
-
 SET(TESTCONFIG_SRC
     configparser.cc
     configparser.h
--- a/kdumptool/process.cc
+++ b/kdumptool/process.cc
@@ -38,76 +38,14 @@ using std::max;
 // -----------------------------------------------------------------------------
 Process::Process()
     throw ()
-    : m_stdinFd(-1), m_stdoutFd(-1), m_stderrFd(-1),
-      m_needCloseStdin(false), m_needCloseStdout(false),
-      m_needCloseStderr(false),
-      m_stdinBuffer(NULL), m_stdoutBuffer(NULL), m_stderrBuffer(NULL)
+    : m_stdinBuffer(NULL), m_stdoutBuffer(NULL), m_stderrBuffer(NULL)
 {}
 
 // -----------------------------------------------------------------------------
-void Process::setStdinFd(int fd)
-    throw ()
-{
-    m_stdinFd = fd;
-    m_needCloseStdin = false;
-}
-
-// -----------------------------------------------------------------------------
-void Process::setStdoutFd(int fd)
-    throw ()
-{
-    m_stdoutFd = fd;
-    m_needCloseStdout = false;
-}
-
-// -----------------------------------------------------------------------------
-void Process::setStderrFd(int fd)
-    throw ()
-{
-    m_stderrFd = fd;
-    m_needCloseStderr = false;
-}
-
-// -----------------------------------------------------------------------------
-void Process::setStdinFile(const char *filename)
-    throw (KError)
-{
-    m_stdinFd = open(filename, O_RDONLY);
-    if (m_stdinFd < 0)
-        throw KSystemError("Opening " + string(filename) + " failed.", errno);
-
-    m_needCloseStdin = true;
-}
-
-// -----------------------------------------------------------------------------
-void Process::setStdoutFile(const char *filename)
-    throw (KError)
-{
-    m_stdoutFd = open(filename, O_WRONLY | O_CREAT, 0644);
-    if (m_stdoutFd < 0)
-        throw KSystemError("Opening " + string(filename) + " failed.", errno);
-
-    m_needCloseStdout = true;
-}
-
-// -----------------------------------------------------------------------------
-void Process::setStderrFile(const char *filename)
-    throw (KError)
-{
-    m_stderrFd = open(filename, O_WRONLY | O_CREAT, 0644);
-    if (m_stderrFd < 0)
-        throw KSystemError("Opening " + string(filename) + " failed.", errno);
-
-    m_needCloseStderr = true;
-}
-
-// -----------------------------------------------------------------------------
 void Process::setStdinBuffer(ByteVector *buffer)
     throw ()
 {
     m_stdinBuffer = buffer;
-    m_needCloseStdin = false;
-    m_stdinFd = -1;
 }
 
 // -----------------------------------------------------------------------------
@@ -115,8 +53,6 @@ void Process::setStdoutBuffer(ByteVector
     throw ()
 {
     m_stdoutBuffer = buffer;
-    m_needCloseStdout = false;
-    m_stdoutFd = -1;
 }
 
 // -----------------------------------------------------------------------------
@@ -124,8 +60,6 @@ void Process::setStderrBuffer(ByteVector
     throw ()
 {
     m_stderrBuffer = buffer;
-    m_needCloseStderr = false;
-    m_stderrFd = -1;
 }
 
 // -----------------------------------------------------------------------------
@@ -318,27 +252,18 @@ uint8_t Process::execute(const string &n
         if (stdin_pipes[1]) {
             close(stdin_pipes[1]); // write end of stdin
             dup2(stdin_pipes[0], STDIN_FILENO); // read end of stdin
-        } else if (m_stdinFd > 0) {
-            close(STDIN_FILENO);
-            dup2(m_stdinFd, STDIN_FILENO);
         }
 
         // stdout
         if (stdout_pipes[0]) {
             close(stdout_pipes[0]); // read end of stdout
             dup2(stdout_pipes[1], STDOUT_FILENO); // write end of stdout
-        } else if (m_stdoutFd > 0) {
-            close(STDOUT_FILENO);
-            dup2(m_stdoutFd, STDOUT_FILENO);
         }
 
         // stderr
         if (stderr_pipes[0]) {
             close(stderr_pipes[0]); // read end of stderr
             dup2(stderr_pipes[1], STDERR_FILENO); // write end of stderr
-        } else if (m_stderrFd > 0) {
-            close(STDERR_FILENO);
-            dup2(m_stderrFd, STDERR_FILENO);
         }
 
         executeProcess(name, args);
@@ -358,20 +283,6 @@ void Process::closeFds()
     throw ()
 {
     Debug::debug()->trace("Process::closeFds()");
-
-    // cleanup
-    if (m_needCloseStdin) {
-        close(m_stdinFd);
-        m_stdinFd = -1;
-    }
-    if (m_needCloseStdout) {
-        close(m_stdoutFd);
-        m_stdoutFd = -1;
-    }
-    if (m_needCloseStderr) {
-        close(m_stderrFd);
-        m_stderrFd = -1;
-    }
 }
 
 // -----------------------------------------------------------------------------
--- a/kdumptool/process.h
+++ b/kdumptool/process.h
@@ -60,69 +60,6 @@ class Process {
         throw (KError);
 
         /**
-         * Sets a file descriptor for stdin which will be used for the process
-         * executed in Process::execute().
-         *
-         * @param[in] fd the file descriptor
-         */
-        void setStdinFd(int fd)
-        throw ();
-
-        /**
-         * Sets a file descriptor for stdout which will be used for the process
-         * executed in Process::execute().
-         *
-         * @param[in] fd the file descriptor
-         */
-        void setStdoutFd(int fd)
-        throw ();
-
-        /**
-         * Sets a file descriptor for stderr which will be used for the process
-         * executed in Process::execute().
-         *
-         * @param[in] fd the file descriptor
-         */
-        void setStderrFd(int fd)
-        throw ();
-
-        /**
-         * Sets a file name for stdin which will be used for the process
-         * executed in Process::execute(). Calling Process::setStdinFd()
-         * overwrites Process::setStdinFile() and vice versa.
-         *
-         * @param[in] filename the filename of the file. This file will be
-         *            opened readonly.
-         * @throw KError if opening the specified @p filename failed
-         */
-        void setStdinFile(const char *filename)
-        throw (KError);
-
-        /**
-         * Sets a file name for stdout which will be used for the process
-         * executed in Process::executable(). Calling Process::setStdoutFd()
-         * overwrites Process::setStdoutFile() and vice versa.
-         *
-         * @param[in] filename the filename of the file. This file will be
-         *            opened writeonly.
-         * @throw KError if opening the specified @p filename failed
-         */
-        void setStdoutFile(const char *filename)
-        throw (KError);
-
-        /**
-         * Sets a file name for stderr which will be used for the process
-         * executed in Process::executable(). Calling Process::setStderrFd()
-         * overwrites Process::setStderrFile() and vice versa.
-         *
-         * @param[in] filename the filename of the file. This file will be
-         *            opened writeonly.
-         * @throw KError if opening the specified @p filename failed
-         */
-        void setStderrFile(const char *filename)
-        throw (KError);
-
-        /**
          * Sets the buffer where the bytes from stdin are read from to
          * @p buffer. This function overwrites the Process::setStdinFd()
          * and Process::setStdinFile().
@@ -160,12 +97,6 @@ class Process {
         throw ();
 
     private:
-        int m_stdinFd;
-        int m_stdoutFd;
-        int m_stderrFd;
-        bool m_needCloseStdin;
-        bool m_needCloseStdout;
-        bool m_needCloseStderr;
         ByteVector *m_stdinBuffer;
         ByteVector *m_stdoutBuffer;
         ByteVector *m_stderrBuffer;
