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
00076 session (std::string const& service,
00077 config_ptr& config,
00078 operation operation,
00079 string_list chroots);
00080
00082 virtual ~session ();
00083
00089 config_ptr&
00090 get_config ();
00091
00097 void
00098 set_config (config_ptr& config);
00099
00105 string_list const&
00106 get_chroots () const;
00107
00113 void
00114 set_chroots (string_list const& chroots);
00115
00121 operation
00122 get_operation () const;
00123
00129 void
00130 set_operation (operation operation);
00131
00138 std::string const&
00139 get_session_id () const;
00140
00147 void
00148 set_session_id (std::string const& session_id);
00149
00155 bool
00156 get_force () const;
00157
00163 void
00164 set_force (bool force);
00165
00172 int
00173 get_child_status () const;
00174
00179 virtual sbuild::auth::status
00180 get_auth_status () const;
00181
00189 virtual void
00190 run_impl ();
00191
00192 private:
00203 int
00204 exec (std::string const& file,
00205 string_list const& command,
00206 environment const& env);
00220 void
00221 setup_chroot (chroot::ptr& session_chroot,
00222 chroot::setup_type setup_type);
00223
00232 void
00233 run_chroot (chroot::ptr& session_chroot);
00234
00243 void
00244 run_child (chroot::ptr& session_chroot);
00245
00254 void
00255 wait_for_child (int pid,
00256 int& child_status);
00257
00259 config_ptr config;
00261 string_list chroots;
00263 int child_status;
00265 operation session_operation;
00267 std::string session_id;
00269 bool force;
00270 };
00271
00272 }
00273
00274 #endif
00275
00276
00277
00278
00279
00280