sbuild  1.6.5
sbuild-run-parts.h
1 /* Copyright © 2005-2009 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/sbuild-custom-error.h>
23 #include <sbuild/sbuild-environment.h>
24 #include <sbuild/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 (std::string const& 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(string_list const& command,
121  environment const& 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  run_parts const& rhs)
135  {
136  if (!rhs.reverse)
137  {
138  for (program_set::const_iterator pos = rhs.programs.begin();
139  pos != rhs.programs.end();
140  ++pos)
141  stream << *pos << '\n';
142  }
143  else
144  {
145  for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
146  pos != rhs.programs.rend();
147  ++pos)
148  stream << *pos << '\n';
149  }
150  return stream;
151  }
152 
153  private:
163  int
164  run_child(std::string const& file,
165  string_list const& command,
166  environment const& env);
167 
176  void
177  wait_for_child (pid_t pid,
178  int& child_status);
179 
181  typedef std::set<std::string> program_set;
182 
184  bool lsb_mode;
188  mode_t umask;
190  bool verbose;
192  bool reverse;
194  std::string directory;
197  };
198 
199 }
200 
201 #endif /* SBUILD_RUN_PARTS_H */
202 
203 /*
204  * Local Variables:
205  * mode:C++
206  * End:
207  */