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 PIPE,
00048 DUP,
00049 POLL,
00050 READ
00051 };
00052
00054 typedef custom_error<error_code> error;
00055
00070 run_parts (std::string const& directory,
00071 bool lsb_mode = true,
00072 bool abort_on_error = true,
00073 mode_t umask = 022);
00074
00076 ~run_parts ();
00077
00083 bool
00084 get_verbose () const;
00085
00091 void
00092 set_verbose (bool verbose);
00093
00099 bool
00100 get_reverse () const;
00101
00107 void
00108 set_reverse (bool reverse);
00109
00119 int
00120 run(string_list const& command,
00121 environment const& env);
00122
00130 template <class charT, class traits>
00131 friend
00132 std::basic_ostream<charT,traits>&
00133 operator << (std::basic_ostream<charT,traits>& stream,
00134 run_parts const& rhs)
00135 {
00136 if (!rhs.reverse)
00137 {
00138 for (program_set::const_iterator pos = rhs.programs.begin();
00139 pos != rhs.programs.end();
00140 ++pos)
00141 stream << *pos << '\n';
00142 }
00143 else
00144 {
00145 for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
00146 pos != rhs.programs.rend();
00147 ++pos)
00148 stream << *pos << '\n';
00149 }
00150 return stream;
00151 }
00152
00153 private:
00163 int
00164 run_child(std::string const& file,
00165 string_list const& command,
00166 environment const& env);
00167
00176 void
00177 wait_for_child (pid_t pid,
00178 int& child_status);
00179
00181 typedef std::set<std::string> program_set;
00182
00184 bool lsb_mode;
00186 bool abort_on_error;
00188 mode_t umask;
00190 bool verbose;
00192 bool reverse;
00194 std::string directory;
00196 program_set programs;
00197 };
00198
00199 }
00200
00201 #endif
00202
00203
00204
00205
00206
00207