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 
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     //    bool        restricted;
00150     std::string directory;
00151     program_set programs;
00152   };
00153 
00154 }
00155 
00156 #endif /* SBUILD_RUN_PARTS_H */
00157 
00158 /*
00159  * Local Variables:
00160  * mode:C++
00161  * End:
00162  */

Generated on Thu Jul 6 19:21:41 2006 for schroot by  doxygen 1.4.7