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
00054 run_parts (std::string const& directory,
00055 bool lsb_mode = true,
00056 bool abort_on_error = true,
00057 mode_t umask = 022);
00058
00060 ~run_parts ();
00061
00067 bool
00068 get_verbose () const;
00069
00075 void
00076 set_verbose (bool verbose);
00077
00083 bool
00084 get_reverse () const;
00085
00091 void
00092 set_reverse (bool reverse);
00093
00094 int
00095 run(string_list const& command,
00096 environment const& env);
00097
00098
00106 template <class charT, class traits>
00107 friend
00108 std::basic_ostream<charT,traits>&
00109 operator << (std::basic_ostream<charT,traits>& stream,
00110 run_parts const& rhs)
00111 {
00112 if (!rhs.reverse)
00113 {
00114 for (program_set::const_iterator pos = rhs.programs.begin();
00115 pos != rhs.programs.end();
00116 ++pos)
00117 stream << *pos << '\n';
00118 }
00119 else
00120 {
00121 for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
00122 pos != rhs.programs.rend();
00123 ++pos)
00124 stream << *pos << '\n';
00125 }
00126 return stream;
00127 }
00128
00129 private:
00130 int
00131 run_child(std::string const& file,
00132 string_list const& command,
00133 environment const& env);
00134
00135 void
00136 wait_for_child (pid_t pid,
00137 int& child_status);
00138
00139 bool
00140 check_filename (std::string const& name);
00141
00142 typedef std::set<std::string> program_set;
00143
00144 bool lsb_mode;
00145 bool abort_on_error;
00146 mode_t umask;
00147 bool verbose;
00148 bool reverse;
00149
00150 std::string directory;
00151 program_set programs;
00152 };
00153
00154 }
00155
00156 #endif
00157
00158
00159
00160
00161
00162