sbuild-run-parts.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
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 /* SBUILD_RUN_PARTS_H */
00207 
00208 /*
00209  * Local Variables:
00210  * mode:C++
00211  * End:
00212  */

Generated on Sun Mar 22 22:18:14 2009 for sbuild by  doxygen 1.5.8