sbuild-session.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_SESSION_H
00021 #define SBUILD_SESSION_H
00022 
00023 #include <sbuild/sbuild-auth.h>
00024 #include <sbuild/sbuild-chroot-config.h>
00025 #include <sbuild/sbuild-custom-error.h>
00026 
00027 #include <string>
00028 
00029 #include <signal.h>
00030 #include <sys/types.h>
00031 
00032 namespace sbuild
00033 {
00034 
00046   class session : public auth
00047   {
00048   public:
00050     enum operation
00051       {
00052         OPERATION_AUTOMATIC, 
00053         OPERATION_BEGIN,     
00054         OPERATION_RECOVER,   
00055         OPERATION_END,       
00056         OPERATION_RUN        
00057       };
00058 
00060     enum error_code
00061       {
00062         CHDIR,          
00063         CHDIR_FB,       
00064         CHILD_CORE,     
00065         CHILD_FAIL,     
00066         CHILD_FORK,     
00067         CHILD_SIGNAL,   
00068         CHILD_WAIT,     
00069         CHROOT,         
00070         CHROOT_ALIAS,   
00071         CHROOT_LOCK,    
00072         CHROOT_SETUP,   
00073         CHROOT_UNKNOWN, 
00074         CHROOT_UNLOCK,  
00075         COMMAND_ABS,    
00076         EXEC,           
00077         GROUP_GET_SUP,  
00078         GROUP_GET_SUPC, 
00079         GROUP_SET,      
00080         GROUP_SET_SUP,  
00081         GROUP_UNKNOWN,  
00082         PAM,            
00083         ROOT_DROP,      
00084         SHELL,          
00085         SHELL_FB,       
00086         SIGHUP_CATCH,   
00087         SIGHUP_SET,     
00088         USER_SET,       
00089         USER_SWITCH     
00090       };
00091 
00093     typedef custom_error<error_code> error;
00094 
00096     typedef std::tr1::shared_ptr<chroot_config> config_ptr;
00097 
00099     typedef std::tr1::shared_ptr<session> ptr;
00100 
00109     session (std::string const& service,
00110              config_ptr&        config,
00111              operation          operation,
00112              string_list const& chroots);
00113 
00115     virtual ~session ();
00116 
00122     config_ptr const&
00123     get_config () const;
00124 
00130     void
00131     set_config (config_ptr& config);
00132 
00138     string_list const&
00139     get_chroots () const;
00140 
00146     void
00147     set_chroots (string_list const& chroots);
00148 
00154     operation
00155     get_operation () const;
00156 
00162     void
00163     set_operation (operation operation);
00164 
00171     std::string const&
00172     get_session_id () const;
00173 
00180     void
00181     set_session_id (std::string const& session_id);
00182 
00188     bool
00189     get_force () const;
00190 
00196     void
00197     set_force (bool force);
00198 
00205     int
00206     get_child_status () const;
00207 
00208   protected:
00214     virtual auth::status
00215     get_chroot_auth_status (auth::status status,
00216                             chroot::ptr const& chroot) const;
00217 
00218   public:
00224     virtual sbuild::auth::status
00225     get_auth_status () const;
00226 
00227   protected:
00235     virtual void
00236     run_impl ();
00237 
00244     virtual string_list
00245     get_login_directories () const;
00246 
00253     virtual string_list
00254     get_command_directories () const;
00255 
00263     virtual std::string
00264     get_shell () const;
00265 
00274     virtual void
00275     get_command (chroot::ptr& session_chroot,
00276                  std::string& file,
00277                  string_list& command) const;
00278 
00287     virtual void
00288     get_login_command (chroot::ptr& session_chroot,
00289                        std::string& file,
00290                        string_list& command) const;
00291 
00300     virtual void
00301     get_user_command (chroot::ptr& session_chroot,
00302                       std::string& file,
00303                       string_list& command) const;
00304 
00305   private:
00319     void
00320     setup_chroot (chroot::ptr&       session_chroot,
00321                   chroot::setup_type setup_type);
00322 
00331     void
00332     run_chroot (chroot::ptr& session_chroot);
00333 
00342     void
00343     run_child (chroot::ptr& session_chroot);
00344 
00353     void
00354     wait_for_child (pid_t pid,
00355                     int&  child_status);
00356 
00362     void
00363     set_sighup_handler ();
00364 
00368     void
00369     clear_sighup_handler ();
00370 
00372     config_ptr       config;
00374     string_list      chroots;
00376     int              chroot_status;
00378     int              child_status;
00380     operation        session_operation;
00382     std::string      session_id;
00384     bool             force;
00386     struct sigaction saved_signals;
00387 
00388   protected:
00390     std::string      cwd;
00391   };
00392 
00393 }
00394 
00395 #endif /* SBUILD_SESSION_H */
00396 
00397 /*
00398  * Local Variables:
00399  * mode:C++
00400  * End:
00401  */

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