00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_CHROOT_H
00021 #define SBUILD_CHROOT_H
00022
00023 #include <iomanip>
00024 #include <ostream>
00025 #include <string>
00026 #include <sstream>
00027 #include <vector>
00028
00029 #include "sbuild-error.h"
00030 #include "sbuild-keyfile.h"
00031 #include "sbuild-util.h"
00032
00033 namespace sbuild
00034 {
00035
00043 class Chroot
00044 {
00045 public:
00047 enum SetupType
00048 {
00049 SETUP_START,
00050 SETUP_RECOVER,
00051 SETUP_STOP,
00052 RUN_START,
00053 RUN_STOP
00054 };
00055
00057 enum SessionFlags
00058 {
00059 SESSION_CREATE = 1 << 0
00060 };
00061
00063 typedef runtime_error_custom<Chroot> error;
00064
00066 Chroot ();
00067
00074 Chroot (const keyfile& keyfile,
00075 const std::string& group);
00076
00078 virtual ~Chroot();
00079
00085 virtual Chroot *
00086 clone () const = 0;
00087
00093 const std::string&
00094 get_name () const;
00095
00101 void
00102 set_name (const std::string& name);
00103
00109 const std::string&
00110 get_description () const;
00111
00117 void
00118 set_description (const std::string& description);
00119
00125 virtual const std::string&
00126 get_mount_location () const;
00127
00133 void
00134 set_mount_location (const std::string& location);
00135
00141 virtual const std::string&
00142 get_mount_device () const;
00143
00149 void
00150 set_mount_device (const std::string& device);
00151
00158 unsigned int
00159 get_priority () const;
00160
00170 void
00171 set_priority (unsigned int priority);
00172
00178 const string_list&
00179 get_groups () const;
00180
00186 void
00187 set_groups (const string_list& groups);
00188
00196 const string_list&
00197 get_root_groups () const;
00198
00206 void
00207 set_root_groups (const string_list& groups);
00208
00215 const string_list&
00216 get_aliases () const;
00217
00224 void
00225 set_aliases (const string_list& aliases);
00226
00232 bool
00233 get_active () const;
00234
00240 void
00241 set_active (bool active);
00242
00248 bool
00249 get_run_setup_scripts () const;
00250
00257 void
00258 set_run_setup_scripts (bool run_setup_scripts);
00259
00265 bool
00266 get_run_session_scripts () const;
00267
00274 void
00275 set_run_session_scripts (bool run_session_scripts);
00276
00282 virtual const std::string&
00283 get_chroot_type () const = 0;
00284
00291 virtual void
00292 setup_env (env_list& env);
00293
00306 virtual void
00307 setup_lock (SetupType type,
00308 bool lock) = 0;
00309
00316 virtual SessionFlags
00317 get_session_flags () const = 0;
00318
00326 virtual void
00327 print_details (std::ostream& stream) const;
00328
00338 virtual void
00339 print_config (std::ostream& stream) const;
00340
00341 protected:
00348 void
00349 read_keyfile (const keyfile& keyfile,
00350 const std::string& group);
00351
00355 template<typename T>
00356 class format_detail
00357 {
00367 public:
00368 format_detail(std::string const& name,
00369 T const& value):
00370 name(name),
00371 value(value)
00372 {}
00373
00377 friend std::ostream& operator << (std::ostream& stream,
00378 const format_detail<T>& rhs)
00379 {
00380 return stream << " " << std::setw(22) << rhs.name
00381 << rhs.value << '\n';
00382 }
00383
00387 friend std::ostream& operator << (std::ostream& stream,
00388 const format_detail<bool>& rhs)
00389 {
00390 const char *desc = 0;
00391 if (rhs.value)
00392 desc = _("true");
00393 else
00394 desc = _("false");
00395 return stream << format_detail<std::string>(rhs.name, desc);
00396 }
00397
00402 friend std::ostream& operator << (std::ostream& stream,
00403 const format_detail<string_list>& rhs)
00404 {
00405 return stream <<
00406 format_detail<std::string>(rhs.name,
00407 string_list_to_string(rhs.value, " "));
00408 }
00409
00410 private:
00412 std::string const& name;
00414 T const& value;
00415 };
00416
00418 typedef format_detail<std::string> format_detail_string;
00420 typedef format_detail<int> format_detail_int;
00422 typedef format_detail<bool> format_detail_bool;
00424 typedef format_detail<string_list> format_detail_strv;
00425
00426 private:
00428 std::string name;
00430 std::string description;
00432 unsigned int priority;
00434 string_list groups;
00436 string_list root_groups;
00438 string_list aliases;
00440 std::string mount_location;
00442 std::string mount_device;
00444 bool active;
00446 bool run_setup_scripts;
00448 bool run_session_scripts;
00449 };
00450
00461 template<typename T>
00462 void
00463 setup_env_var(env_list& env,
00464 const std::string& name,
00465 const T& var)
00466 {
00467 std::ostringstream varstring;
00468 varstring << var;
00469 env.push_back(std::make_pair(name, varstring.str()));
00470 }
00471
00472 }
00473
00474 #endif
00475
00476
00477
00478
00479
00480