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-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<Config> config_ptr;
00067
00076 Session (const std::string& 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 const string_list&
00106 get_chroots () const;
00107
00113 void
00114 set_chroots (const string_list& chroots);
00115
00121 Operation
00122 get_operation () const;
00123
00129 void
00130 set_operation (Operation operation);
00131
00138 const std::string&
00139 get_session_id () const;
00140
00147 void
00148 set_session_id (const std::string& 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 (const std::string& file,
00205 const string_list& command,
00206 const env_list& env);
00220 void
00221 setup_chroot (Chroot& session_chroot,
00222 Chroot::SetupType setup_type);
00223
00232 void
00233 run_chroot (Chroot& session_chroot);
00234
00243 void
00244 run_child (Chroot& session_chroot);
00245
00254 void
00255 wait_for_child (int pid,
00256 int& child_status);
00257
00259 config_ptr config;
00261 string_list chroots;
00264 int child_status;
00266 Operation operation;
00268 std::string session_id;
00270 bool force;
00271 };
00272
00273 }
00274
00275 #endif
00276
00277
00278
00279
00280
00281