sbuild  1.6.10
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;
196  program_set programs;
197  };
198 
199 }
200 
201 #endif /* SBUILD_RUN_PARTS_H */
202 
203 /*
204  * Local Variables:
205  * mode:C++
206  * End:
207  */
void wait_for_child(pid_t pid, int &child_status)
Wait for a child process to complete, and check its exit status.
Definition: sbuild-run-parts.cc:366
Debian source builder components.
Definition: sbuild-auth-null.h:24
int run(string_list const &command, environment const &env)
Run all scripts in the specified directory.
Definition: sbuild-run-parts.cc:129
program_set programs
The list of scripts to run.
Definition: sbuild-run-parts.h:196
Wait for child failed.
Definition: sbuild-run-parts.h:45
bool abort_on_error
Whether to abort on script execution error.
Definition: sbuild-run-parts.h:186
Container of environment variables.
Definition: sbuild-environment.h:38
bool get_verbose() const
Get the verbosity level.
Definition: sbuild-run-parts.cc:105
run_parts(std::string const &directory, bool lsb_mode=true, bool abort_on_error=true, mode_t umask=022)
The constructor.
Definition: sbuild-run-parts.cc:66
bool lsb_mode
The LSB mode for allowed filenames.
Definition: sbuild-run-parts.h:184
error_code
Error codes.
Definition: sbuild-run-parts.h:42
int run_child(std::string const &file, string_list const &command, environment const &env)
Run the command specified by file (an absolute pathname), using command and env as the argv and envir...
Definition: sbuild-run-parts.cc:177
Failed to create pipe.
Definition: sbuild-run-parts.h:47
Failed to poll file descriptor.
Definition: sbuild-run-parts.h:49
~run_parts()
The destructor.
Definition: sbuild-run-parts.cc:100
bool verbose
Verbose logging.
Definition: sbuild-run-parts.h:190
std::vector< std::string > string_list
A string vector.
Definition: sbuild-types.h:38
Custom error.
Definition: sbuild-custom-error.h:32
Failed to execute.
Definition: sbuild-run-parts.h:46
Failed to read file descriptor.
Definition: sbuild-run-parts.h:50
void set_reverse(bool reverse)
Set the script execution order.
Definition: sbuild-run-parts.cc:123
custom_error< error_code > error
Exception type.
Definition: sbuild-run-parts.h:54
mode_t umask
The umask to run scripts with.
Definition: sbuild-run-parts.h:188
Run all scripts or programs within a directory.
Definition: sbuild-run-parts.h:38
bool reverse
Execute scripts in reverse order.
Definition: sbuild-run-parts.h:192
Failed to duplicate file descriptor.
Definition: sbuild-run-parts.h:48
std::string directory
The directory to run scripts from.
Definition: sbuild-run-parts.h:194
std::set< std::string > program_set
A sorted set of filenames to use.
Definition: sbuild-run-parts.h:181
bool get_reverse() const
Get the script execution order.
Definition: sbuild-run-parts.cc:117
Failed to fork child.
Definition: sbuild-run-parts.h:44
void set_verbose(bool verbose)
Set the verbosity level.
Definition: sbuild-run-parts.cc:111