1 | /* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org> |
---|
2 | * |
---|
3 | * schroot is free software: you can redistribute it and/or modify it |
---|
4 | * under the terms of the GNU General Public License as published by |
---|
5 | * the Free Software Foundation, either version 3 of the License, or |
---|
6 | * (at your option) any later version. |
---|
7 | * |
---|
8 | * schroot is distributed in the hope that it will be useful, but |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | * General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU General Public License |
---|
14 | * along with this program. If not, see |
---|
15 | * <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | *********************************************************************/ |
---|
18 | |
---|
19 | #ifndef SCHROOT_MOUNT_MAIN_H |
---|
20 | #define SCHROOT_MOUNT_MAIN_H |
---|
21 | |
---|
22 | #include <schroot-base/schroot-base-main.h> |
---|
23 | |
---|
24 | #include <schroot-mount/schroot-mount-options.h> |
---|
25 | |
---|
26 | #include <sbuild/sbuild-custom-error.h> |
---|
27 | |
---|
28 | namespace schroot_mount |
---|
29 | { |
---|
30 | |
---|
31 | /** |
---|
32 | * Frontend for schroot-mount. This class is used to "run" schroot-mount. |
---|
33 | */ |
---|
34 | class main : public schroot_base::main |
---|
35 | { |
---|
36 | public: |
---|
37 | /// Error codes. |
---|
38 | enum error_code |
---|
39 | { |
---|
40 | CHILD_FORK, ///< Failed to fork child. |
---|
41 | CHILD_WAIT, ///< Wait for child failed. |
---|
42 | EXEC ///< Failed to execute. |
---|
43 | }; |
---|
44 | |
---|
45 | /// Exception type. |
---|
46 | typedef sbuild::custom_error<error_code> error; |
---|
47 | |
---|
48 | /** |
---|
49 | * The constructor. |
---|
50 | * |
---|
51 | * @param options the command-line options to use. |
---|
52 | */ |
---|
53 | main (options::ptr& options); |
---|
54 | |
---|
55 | /// The destructor. |
---|
56 | virtual ~main (); |
---|
57 | |
---|
58 | private: |
---|
59 | /** |
---|
60 | * Mount filesystems. |
---|
61 | */ |
---|
62 | virtual void |
---|
63 | action_mount (); |
---|
64 | |
---|
65 | /** |
---|
66 | * Run the command specified by file (an absolute pathname), using |
---|
67 | * command and env as the argv and environment, respectively. |
---|
68 | * |
---|
69 | * @param file the program to execute. |
---|
70 | * @param command the arguments to pass to the executable. |
---|
71 | * @param env the environment. |
---|
72 | * @returns the return value of the execve system call on failure. |
---|
73 | */ |
---|
74 | int |
---|
75 | run_child(std::string const& file, |
---|
76 | sbuild::string_list const& command, |
---|
77 | sbuild::environment const& env); |
---|
78 | |
---|
79 | /** |
---|
80 | * Wait for a child process to complete, and check its exit status. |
---|
81 | * |
---|
82 | * An error will be thrown on failure. |
---|
83 | * |
---|
84 | * @param pid the pid to wait for. |
---|
85 | * @param child_status the place to store the child exit status. |
---|
86 | */ |
---|
87 | void |
---|
88 | wait_for_child (pid_t pid, |
---|
89 | int& child_status); |
---|
90 | |
---|
91 | protected: |
---|
92 | /** |
---|
93 | * Run the program. |
---|
94 | * |
---|
95 | * @returns 0 on success, 1 on failure or the exit status of the |
---|
96 | * chroot command. |
---|
97 | */ |
---|
98 | virtual int |
---|
99 | run_impl (); |
---|
100 | |
---|
101 | private: |
---|
102 | /// The program options. |
---|
103 | options::ptr opts; |
---|
104 | }; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | #endif /* SCHROOT_MOUNT_MAIN_H */ |
---|
109 | |
---|
110 | /* |
---|
111 | * Local Variables: |
---|
112 | * mode:C++ |
---|
113 | * End: |
---|
114 | */ |
---|