00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_RUN_PARTS_H
00021 #define SBUILD_RUN_PARTS_H
00022
00023 #include <sbuild/sbuild-custom-error.h>
00024 #include <sbuild/sbuild-environment.h>
00025 #include <sbuild/sbuild-types.h>
00026
00027 #include <set>
00028 #include <string>
00029
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032
00033 namespace sbuild
00034 {
00035
00039 class run_parts
00040 {
00041 public:
00043 enum error_code
00044 {
00045 CHILD_FORK,
00046 CHILD_WAIT,
00047 EXEC
00048 };
00049
00051 typedef custom_error<error_code> error;
00052
00067 run_parts (std::string const& directory,
00068 bool lsb_mode = true,
00069 bool abort_on_error = true,
00070 mode_t umask = 022);
00071
00073 ~run_parts ();
00074
00080 bool
00081 get_verbose () const;
00082
00088 void
00089 set_verbose (bool verbose);
00090
00096 bool
00097 get_reverse () const;
00098
00104 void
00105 set_reverse (bool reverse);
00106
00116 int
00117 run(string_list const& command,
00118 environment const& env);
00119
00127 template <class charT, class traits>
00128 friend
00129 std::basic_ostream<charT,traits>&
00130 operator << (std::basic_ostream<charT,traits>& stream,
00131 run_parts const& rhs)
00132 {
00133 if (!rhs.reverse)
00134 {
00135 for (program_set::const_iterator pos = rhs.programs.begin();
00136 pos != rhs.programs.end();
00137 ++pos)
00138 stream << *pos << '\n';
00139 }
00140 else
00141 {
00142 for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
00143 pos != rhs.programs.rend();
00144 ++pos)
00145 stream << *pos << '\n';
00146 }
00147 return stream;
00148 }
00149
00150 private:
00160 int
00161 run_child(std::string const& file,
00162 string_list const& command,
00163 environment const& env);
00164
00175 void
00176 wait_for_child (pid_t pid,
00177 int& child_status);
00178
00185 bool
00186 check_filename (std::string const& name);
00187
00189 typedef std::set<std::string> program_set;
00190
00192 bool lsb_mode;
00194 bool abort_on_error;
00196 mode_t umask;
00198 bool verbose;
00200 bool reverse;
00202 std::string directory;
00204 program_set programs;
00205 };
00206
00207 }
00208
00209 #endif
00210
00211
00212
00213
00214
00215