00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_SESSION_H
00021 #define SBUILD_SESSION_H
00022
00023 #include <string>
00024
00025 #include <sys/types.h>
00026 #include <sys/wait.h>
00027 #include <grp.h>
00028 #include <pwd.h>
00029 #include <unistd.h>
00030
00031 #include "sbuild-auth.h"
00032 #include "sbuild-chroot-config.h"
00033 #include "sbuild-error.h"
00034
00035 namespace sbuild
00036 {
00037
00049 class session : public auth
00050 {
00051 public:
00053 enum operation
00054 {
00055 OPERATION_AUTOMATIC,
00056 OPERATION_BEGIN,
00057 OPERATION_RECOVER,
00058 OPERATION_END,
00059 OPERATION_RUN
00060 };
00061
00063 typedef runtime_error_custom<session> error;
00064
00066 typedef std::tr1::shared_ptr<chroot_config> config_ptr;
00067
00069 typedef std::tr1::shared_ptr<session> ptr;
00070
00079 session (std::string const& service,
00080 config_ptr& config,
00081 operation operation,
00082 string_list const& chroots);
00083
00085 virtual ~session ();
00086
00092 config_ptr&
00093 get_config ();
00094
00100 void
00101 set_config (config_ptr& config);
00102
00108 string_list const&
00109 get_chroots () const;
00110
00116 void
00117 set_chroots (string_list const& chroots);
00118
00124 operation
00125 get_operation () const;
00126
00132 void
00133 set_operation (operation operation);
00134
00141 std::string const&
00142 get_session_id () const;
00143
00150 void
00151 set_session_id (std::string const& session_id);
00152
00158 bool
00159 get_force () const;
00160
00166 void
00167 set_force (bool force);
00168
00175 int
00176 get_child_status () const;
00177
00182 virtual sbuild::auth::status
00183 get_auth_status () const;
00184
00192 virtual void
00193 run_impl ();
00194
00195 private:
00206 int
00207 exec (std::string const& file,
00208 string_list const& command,
00209 environment const& env);
00223 void
00224 setup_chroot (chroot::ptr& session_chroot,
00225 chroot::setup_type setup_type);
00226
00235 void
00236 run_chroot (chroot::ptr& session_chroot);
00237
00246 void
00247 run_child (chroot::ptr& session_chroot);
00248
00257 void
00258 wait_for_child (int pid,
00259 int& child_status);
00260
00266 void
00267 set_sighup_handler ();
00268
00272 void
00273 clear_sighup_handler ();
00274
00276 config_ptr config;
00278 string_list chroots;
00280 int chroot_status;
00282 int child_status;
00284 operation session_operation;
00286 std::string session_id;
00288 bool force;
00290 struct sigaction saved_signals;
00291 };
00292
00293 }
00294
00295 #endif
00296
00297
00298
00299
00300
00301