Fix pkg_initdb tool to check backend execution result
[platform/core/appfw/app-installers.git] / src / common / utils / subprocess.h
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_UTILS_SUBPROCESS_H_
6 #define COMMON_UTILS_SUBPROCESS_H_
7
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 namespace common_installer {
13
14 class Subprocess {
15  public:
16   explicit Subprocess(const std::string& program);
17
18   template<typename ...Args> bool Run(Args&&... args) {
19     std::vector<std::string> argv{std::forward<Args>(args)...};
20     return RunWithArgs(argv);
21   }
22
23   bool RunWithArgs(
24       const std::vector<std::string>& args = std::vector<std::string>());
25   bool Wait();
26
27   void set_uid(int uid) {
28     uid_ = uid;
29   }
30
31   void Kill();
32
33  private:
34   std::string program_;
35   int pid_;
36   bool started_;
37   int uid_;
38 };
39
40 }  // namespace common_installer
41
42 #endif  // COMMON_UTILS_SUBPROCESS_H_