- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# 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 #include <termios.h>
    00032 #include <unistd.h>
    00033
    00034 namespace sbuild
    00035 {
    00036
    00048   class session : public auth
    00049   {
    00050   public:
    00052     enum operation
    00053       {
    00054         OPERATION_AUTOMATIC,
    00055         OPERATION_BEGIN,
    00056         OPERATION_RECOVER,
    00057         OPERATION_END,
    00058         OPERATION_RUN
    00059       };
    00060
    00062     enum error_code
    00063       {
    00064         CHDIR,
    00065         CHDIR_FB,
    00066         CHILD_CORE,
    00067         CHILD_FAIL,
    00068         CHILD_FORK,
    00069         CHILD_SIGNAL,
    00070         CHILD_WAIT,
    00071         CHROOT,
    00072         CHROOT_ALIAS,
    00073         CHROOT_LOCK,
    00074         CHROOT_SETUP,
    00075         CHROOT_UNKNOWN,
    00076         CHROOT_UNLOCK,
    00077         COMMAND_ABS,
    00078         EXEC,
    00079         GROUP_GET_SUP,
    00080         GROUP_GET_SUPC,
    00081         GROUP_SET,
    00082         GROUP_SET_SUP,
    00083         GROUP_UNKNOWN,
    00084         PAM,
    00085         ROOT_DROP,
    00086         SHELL,
    00087         SHELL_FB,
    00088         SIGNAL_CATCH,
    00089         SIGNAL_SET,
    00090         USER_SET,
    00091         USER_SWITCH
    00092       };
    00093
    00095     typedef custom_error<error_code> error;
    00096
    00098     typedef std::tr1::shared_ptr<chroot_config> config_ptr;
    00099
    00101     typedef std::tr1::shared_ptr<session> ptr;
    00102
    00111     session (std::string const& service,
    00112              config_ptr&        config,
    00113              operation          operation,
    00114              string_list const& chroots);
    00115
    00117     virtual ~session ();
    00118
    00124     config_ptr const&
    00125     get_config () const;
    00126
    00132     void
    00133     set_config (config_ptr& config);
    00134
    00140     string_list const&
    00141     get_chroots () const;
    00142
    00148     void
    00149     set_chroots (string_list const& chroots);
    00150
    00156     operation
    00157     get_operation () const;
    00158
    00164     void
    00165     set_operation (operation operation);
    00166
    00173     std::string const&
    00174     get_session_id () const;
    00175
    00182     void
    00183     set_session_id (std::string const& session_id);
    00184
    00190     bool
    00191     get_force () const;
    00192
    00198     void
    00199     set_force (bool force);
    00200
    00204     void
    00205     save_termios ();
    00206
    00210     void
    00211     restore_termios ();
    00212
    00219     int
    00220     get_child_status () const;
    00221
    00222   protected:
    00228     virtual auth::status
    00229     get_chroot_auth_status (auth::status status,
    00230                             chroot::ptr const& chroot) const;
    00231
    00232   public:
    00238     virtual sbuild::auth::status
    00239     get_auth_status () const;
    00240
    00241   protected:
    00249     virtual void
    00250     run_impl ();
    00251
    00258     virtual string_list
    00259     get_login_directories () const;
    00260
    00267     virtual string_list
    00268     get_command_directories () const;
    00269
    00277     virtual std::string
    00278     get_shell () const;
    00279
    00288     virtual void
    00289     get_command (chroot::ptr& session_chroot,
    00290                  std::string& file,
    00291                  string_list& command) const;
    00292
    00301     virtual void
    00302     get_login_command (chroot::ptr& session_chroot,
    00303                        std::string& file,
    00304                        string_list& command) const;
    00305
    00314     virtual void
    00315     get_user_command (chroot::ptr& session_chroot,
    00316                       std::string& file,
    00317                       string_list& command) const;
    00318
    00319   private:
    00333     void
    00334     setup_chroot (chroot::ptr&       session_chroot,
    00335                   chroot::setup_type setup_type);
    00336
    00345     void
    00346     run_chroot (chroot::ptr& session_chroot);
    00347
    00356     void
    00357     run_child (chroot::ptr& session_chroot);
    00358
    00369     void
    00370     wait_for_child (pid_t pid,
    00371                     int&  child_status);
    00372
    00378     void
    00379     set_sighup_handler ();
    00380
    00384     void
    00385     clear_sighup_handler ();
    00386
    00392     void
    00393     set_sigterm_handler ();
    00394
    00398     void
    00399     clear_sigterm_handler ();
    00400
    00409     void
    00410     set_signal_handler (int                signal,
    00411                         struct sigaction  *saved_signal,
    00412                         void             (*handler)(int));
    00413
    00421     void
    00422     clear_signal_handler (int               signal,
    00423                           struct sigaction *saved_signal);
    00424
    00426     config_ptr       config;
    00428     string_list      chroots;
    00430     int              chroot_status;
    00432     int              child_status;
    00434     operation        session_operation;
    00436     std::string      session_id;
    00438     bool             force;
    00440     struct sigaction saved_sighup_signal;
    00442     struct sigaction saved_sigterm_signal;
    00444     struct termios saved_termios;
    00446     bool termios_ok;
    00447
    00448   protected:
    00450     std::string      cwd;
    00451   };
    00452
    00453 }
    00454
    00455 #endif /* SBUILD_SESSION_H */
    00456
    00457 /*
    00458  * Local Variables:
    00459  * mode:C++
    00460  * End:
    00461  */