Change to handle logic subprocess's Wait() 18/254018/4
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 22 Feb 2021 06:16:23 +0000 (15:16 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Mon, 22 Feb 2021 07:57:32 +0000 (16:57 +0900)
Change-Id: I7d02a2c2920cd00c1608b84bbbdab8f1fa68fd3e
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/utils/subprocess.cc
src/common/utils/subprocess.h
src/pkg_initdb/init_pkg_db.cc

index d5ca6d2..3c0b7a5 100644 (file)
@@ -53,17 +53,14 @@ bool Subprocess::RunWithArgs(const std::vector<std::string>& args) {
   }
 }
 
-bool Subprocess::Wait() {
+int Subprocess::Wait() {
   if (!started_) {
     LOG(WARNING) << "Process is not started. Cannot wait";
-    return false;
+    return -1;
   }
   int status;
   waitpid(pid_, &status, 0);
-  if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
-    return false;
-
-  return true;
+  return status;
 }
 
 void Subprocess::Kill() {
index 8807a29..42527ee 100644 (file)
@@ -22,7 +22,7 @@ class Subprocess {
 
   bool RunWithArgs(
       const std::vector<std::string>& args = std::vector<std::string>());
-  bool Wait();
+  int Wait();
 
   void set_uid(int uid) {
     uid_ = uid;
index 26b363b..a4d4d4e 100644 (file)
@@ -78,9 +78,13 @@ bool InitPkgDB::RunBackend(const std::string& pkgid,
     params.emplace_back("--preload");
   }
 
-  backend.RunWithArgs(params);
-  if (!backend.Wait()) {
-    std::cerr << "Failed to run backend" << std::endl;
+  if (!backend.RunWithArgs(params)) {
+    std::cerr << "Failed to start backend" << std::endl;
+    return false;
+  }
+  int status = backend.Wait();
+  if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) {
+    std::cerr << "Backend operation failed" << std::endl;
     return false;
   }