sbuild  1.7.1
run-parts.h
1 /* Copyright © 2005-2013 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 SBUILD_RUN_PARTS_H
20 #define SBUILD_RUN_PARTS_H
21 
22 #include <sbuild/custom-error.h>
23 #include <sbuild/environment.h>
24 #include <sbuild/types.h>
25 
26 #include <set>
27 #include <string>
28 
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 
32 namespace sbuild
33 {
34 
38  class run_parts
39  {
40  public:
43  {
46  EXEC,
47  PIPE,
48  DUP,
49  POLL,
51  };
52 
55 
70  run_parts (const std::string& directory,
71  bool lsb_mode = true,
72  bool abort_on_error = true,
73  mode_t umask = 022);
74 
76  ~run_parts ();
77 
83  bool
84  get_verbose () const;
85 
91  void
92  set_verbose (bool verbose);
93 
99  bool
100  get_reverse () const;
101 
107  void
108  set_reverse (bool reverse);
109 
119  int
120  run(const string_list& command,
121  const environment& env);
122 
130  template <class charT, class traits>
131  friend
132  std::basic_ostream<charT,traits>&
133  operator << (std::basic_ostream<charT,traits>& stream,
134  const run_parts& rhs)
135  {
136  if (!rhs.reverse)
137  {
138  for (const auto& program : rhs.programs)
139  stream << program << '\n';
140  }
141  else
142  {
143  for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
144  pos != rhs.programs.rend();
145  ++pos)
146  stream << *pos << '\n';
147  }
148  return stream;
149  }
150 
151  private:
161  int
162  run_child(const std::string& file,
163  const string_list& command,
164  const environment& env);
165 
174  void
175  wait_for_child (pid_t pid,
176  int& child_status);
177 
179  typedef std::set<std::string> program_set;
180 
182  bool lsb_mode;
186  mode_t umask;
188  bool verbose;
190  bool reverse;
192  std::string directory;
195  };
196 
197 }
198 
199 #endif /* SBUILD_RUN_PARTS_H */
200 
201 /*
202  * Local Variables:
203  * mode:C++
204  * End:
205  */