00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SBUILD_RUN_PARTS_H
00020 #define SBUILD_RUN_PARTS_H
00021
00022 #include <sbuild/sbuild-custom-error.h>
00023 #include <sbuild/sbuild-environment.h>
00024 #include <sbuild/sbuild-types.h>
00025
00026 #include <set>
00027 #include <string>
00028
00029 #include <sys/types.h>
00030 #include <sys/stat.h>
00031
00032 namespace sbuild
00033 {
00034
00038 class run_parts
00039 {
00040 public:
00042 enum error_code
00043 {
00044 CHILD_FORK,
00045 CHILD_WAIT,
00046 EXEC
00047 };
00048
00050 typedef custom_error<error_code> error;
00051
00066 run_parts (std::string const& directory,
00067 bool lsb_mode = true,
00068 bool abort_on_error = true,
00069 mode_t umask = 022);
00070
00072 ~run_parts ();
00073
00079 bool
00080 get_verbose () const;
00081
00087 void
00088 set_verbose (bool verbose);
00089
00095 bool
00096 get_reverse () const;
00097
00103 void
00104 set_reverse (bool reverse);
00105
00115 int
00116 run(string_list const& command,
00117 environment const& env);
00118
00126 template <class charT, class traits>
00127 friend
00128 std::basic_ostream<charT,traits>&
00129 operator << (std::basic_ostream<charT,traits>& stream,
00130 run_parts const& rhs)
00131 {
00132 if (!rhs.reverse)
00133 {
00134 for (program_set::const_iterator pos = rhs.programs.begin();
00135 pos != rhs.programs.end();
00136 ++pos)
00137 stream << *pos << '\n';
00138 }
00139 else
00140 {
00141 for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
00142 pos != rhs.programs.rend();
00143 ++pos)
00144 stream << *pos << '\n';
00145 }
00146 return stream;
00147 }
00148
00149 private:
00159 int
00160 run_child(std::string const& file,
00161 string_list const& command,
00162 environment const& env);
00163
00172 void
00173 wait_for_child (pid_t pid,
00174 int& child_status);
00175
00182 bool
00183 check_filename (std::string const& name);
00184
00186 typedef std::set<std::string> program_set;
00187
00189 bool lsb_mode;
00191 bool abort_on_error;
00193 mode_t umask;
00195 bool verbose;
00197 bool reverse;
00199 std::string directory;
00201 program_set programs;
00202 };
00203
00204 }
00205
00206 #endif
00207
00208
00209
00210
00211
00212