sbuild-run-parts.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  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 2 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, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
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 /* SBUILD_RUN_PARTS_H */
00210 
00211 /*
00212  * Local Variables:
00213  * mode:C++
00214  * End:
00215  */

Generated on Sat Jan 27 16:11:03 2007 for schroot by  doxygen 1.5.1