~ubuntu-branches/ubuntu/trusty/schroot/trusty

« back to all changes in this revision

Viewing changes to sbuild/sbuild-chroot.cc

  • Committer: Bazaar Package Importer
  • Author(s): Roger Leigh
  • Date: 2010-07-06 23:34:30 UTC
  • mfrom: (1.1.24 upstream) (2.2.9 sid)
  • Revision ID: james.westby@ubuntu.com-20100706233430-0xhzqj6105yuyvb1
* New upstream stable release.
* Use standards version 3.9.0.
* Correctly distribute profile conffiles (Closes: #588247).  Thanks
  to Mario Holbe.
* Update it and zh_CN translations.  Thanks to Vincenzo Campanella
  and Ji ZhengYu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#ifdef SBUILD_FEATURE_LVMSNAP
32
32
#include "sbuild-chroot-lvm-snapshot.h"
33
33
#endif // SBUILD_FEATURE_LVMSNAP
 
34
#ifdef SBUILD_FEATURE_BTRFSSNAP
 
35
#include "sbuild-chroot-btrfs-snapshot.h"
 
36
#endif // SBUILD_FEATURE_BTRFSSNAP
34
37
#include "sbuild-chroot-facet.h"
35
38
#include "sbuild-chroot-facet-personality.h"
36
39
#include "sbuild-chroot-facet-session.h"
63
66
   */
64
67
  emap init_errors[] =
65
68
    {
66
 
      emap(sbuild::chroot::CHROOT_CREATE,   N_("Chroot creation failed")),
67
 
      emap(sbuild::chroot::CHROOT_DEVICE,   N_("Device name not set")),
 
69
      emap(sbuild::chroot::CHROOT_CREATE,     N_("Chroot creation failed")),
 
70
      emap(sbuild::chroot::CHROOT_DEVICE,     N_("Device name not set")),
68
71
      // TRANSLATORS: %1% = chroot type name
69
 
      emap(sbuild::chroot::CHROOT_TYPE,     N_("Unknown chroot type '%1%'")),
70
 
      emap(sbuild::chroot::DEVICE_ABS,      N_("Device must have an absolute path")),
71
 
      emap(sbuild::chroot::DEVICE_LOCK,     N_("Failed to lock device")),
72
 
      emap(sbuild::chroot::DEVICE_NOTBLOCK, N_("File is not a block device")),
73
 
      emap(sbuild::chroot::DEVICE_UNLOCK,   N_("Failed to unlock device")),
74
 
      emap(sbuild::chroot::DIRECTORY_ABS,   N_("Directory must have an absolute path")),
75
 
      emap(sbuild::chroot::FACET_INVALID,   N_("Attempt to add object which is not a facet")),
76
 
      emap(sbuild::chroot::FACET_PRESENT,   N_("Attempt to add facet which is already in use")),
77
 
      emap(sbuild::chroot::FILE_ABS,        N_("File must have an absolute path")),
78
 
      emap(sbuild::chroot::FILE_LOCK,       N_("Failed to acquire file lock")),
79
 
      emap(sbuild::chroot::FILE_NOTREG,     N_("File is not a regular file")),
80
 
      emap(sbuild::chroot::FILE_OWNER,      N_("File is not owned by user root")),
81
 
      emap(sbuild::chroot::FILE_PERMS,      N_("File has write permissions for others")),
82
 
      emap(sbuild::chroot::FILE_UNLOCK,     N_("Failed to discard file lock")),
83
 
      emap(sbuild::chroot::LOCATION_ABS,    N_("Location must have an absolute path")),
 
72
      emap(sbuild::chroot::CHROOT_TYPE,       N_("Unknown chroot type '%1%'")),
 
73
      emap(sbuild::chroot::DEVICE_ABS,        N_("Device must have an absolute path")),
 
74
      emap(sbuild::chroot::DEVICE_LOCK,       N_("Failed to lock device")),
 
75
      emap(sbuild::chroot::DEVICE_NOTBLOCK,   N_("File is not a block device")),
 
76
      emap(sbuild::chroot::DEVICE_UNLOCK,     N_("Failed to unlock device")),
 
77
      emap(sbuild::chroot::DIRECTORY_ABS,     N_("Directory must have an absolute path")),
 
78
      emap(sbuild::chroot::FACET_INVALID,     N_("Attempt to add object which is not a facet")),
 
79
      emap(sbuild::chroot::FACET_PRESENT,     N_("Attempt to add facet which is already in use")),
 
80
      emap(sbuild::chroot::FILE_ABS,          N_("File must have an absolute path")),
 
81
      emap(sbuild::chroot::FILE_LOCK,         N_("Failed to acquire file lock")),
 
82
      emap(sbuild::chroot::FILE_NOTREG,       N_("File is not a regular file")),
 
83
      emap(sbuild::chroot::FILE_OWNER,        N_("File is not owned by user root")),
 
84
      emap(sbuild::chroot::FILE_PERMS,        N_("File has write permissions for others")),
 
85
      emap(sbuild::chroot::FILE_UNLOCK,       N_("Failed to discard file lock")),
 
86
      emap(sbuild::chroot::LOCATION_ABS,      N_("Location must have an absolute path")),
84
87
      // TRANSLATORS: unlink refers to the C function which removes a file
85
 
      emap(sbuild::chroot::SESSION_UNLINK,  N_("Failed to unlink session file")),
86
 
      emap(sbuild::chroot::SESSION_WRITE,   N_("Failed to write session file"))
 
88
      emap(sbuild::chroot::SESSION_UNLINK,    N_("Failed to unlink session file")),
 
89
      emap(sbuild::chroot::SESSION_WRITE,     N_("Failed to write session file")),
 
90
      emap(sbuild::chroot::VERBOSITY_INVALID, N_("Message verbosity is invalid"))
87
91
    };
88
92
 
89
93
}
104
108
  root_users(),
105
109
  root_groups(),
106
110
  aliases(),
 
111
  preserve_environment(false),
107
112
  environment_filter(SBUILD_DEFAULT_ENVIRONMENT_FILTER),
108
113
  mount_location(),
109
114
  original(true),
110
115
  run_setup_scripts(true),
111
116
  script_config("default/config"),
112
117
  command_prefix(),
 
118
  message_verbosity(VERBOSITY_NORMAL),
113
119
  facets()
114
120
{
115
121
  add_facet(sbuild::chroot_facet_personality::create());
126
132
  root_users(rhs.root_users),
127
133
  root_groups(rhs.root_groups),
128
134
  aliases(rhs.aliases),
 
135
  preserve_environment(rhs.preserve_environment),
129
136
  environment_filter(rhs.environment_filter),
130
137
  mount_location(rhs.mount_location),
131
138
  original(rhs.original),
132
139
  run_setup_scripts(rhs.run_setup_scripts),
133
140
  script_config(rhs.script_config),
134
141
  command_prefix(rhs.command_prefix),
 
142
  message_verbosity(rhs.message_verbosity),
135
143
  facets()
136
144
{
137
145
  /// @todo Use internal version of add_facet to add chroot pointer.
172
180
  else if (type == "lvm-snapshot")
173
181
    new_chroot = new chroot_lvm_snapshot();
174
182
#endif // SBUILD_FEATURE_LVMSNAP
 
183
#ifdef SBUILD_FEATURE_BTRFSSNAP
 
184
  else if (type == "btrfs-snapshot")
 
185
    new_chroot = new chroot_btrfs_snapshot();
 
186
#endif // SBUILD_FEATURE_BTRFSSNAP
175
187
  else
176
188
    throw error(type, CHROOT_TYPE);
177
189
 
314
326
  this->aliases = aliases;
315
327
}
316
328
 
 
329
bool
 
330
sbuild::chroot::get_preserve_environment () const
 
331
{
 
332
  return this->preserve_environment;
 
333
}
 
334
 
 
335
void
 
336
sbuild::chroot::set_preserve_environment (bool preserve_environment)
 
337
{
 
338
  this->preserve_environment = preserve_environment;
 
339
}
 
340
 
317
341
regex const&
318
342
sbuild::chroot::get_environment_filter () const
319
343
{
382
406
  this->command_prefix = command_prefix;
383
407
}
384
408
 
 
409
chroot::verbosity
 
410
chroot::get_verbosity () const
 
411
{
 
412
  return this->message_verbosity;
 
413
}
 
414
 
 
415
const char *
 
416
chroot::get_verbosity_string () const
 
417
{
 
418
  const char *verbosity = 0;
 
419
 
 
420
  switch (this->message_verbosity)
 
421
    {
 
422
    case chroot::VERBOSITY_QUIET:
 
423
      verbosity = "quiet";
 
424
      break;
 
425
    case chroot::VERBOSITY_NORMAL:
 
426
      verbosity = "normal";
 
427
      break;
 
428
    case chroot::VERBOSITY_VERBOSE:
 
429
      verbosity = "verbose";
 
430
      break;
 
431
    default:
 
432
      log_debug(DEBUG_CRITICAL) << format("Invalid verbosity level: %1%, falling back to 'normal'")
 
433
        % static_cast<int>(this->message_verbosity)
 
434
                                << std::endl;
 
435
      verbosity = "normal";
 
436
      break;
 
437
    }
 
438
 
 
439
  return verbosity;
 
440
}
 
441
 
 
442
void
 
443
chroot::set_verbosity (chroot::verbosity verbosity)
 
444
{
 
445
  this->message_verbosity = verbosity;
 
446
}
 
447
 
 
448
void
 
449
chroot::set_verbosity (std::string const& verbosity)
 
450
{
 
451
  if (verbosity == "quiet")
 
452
    this->message_verbosity = VERBOSITY_QUIET;
 
453
  else if (verbosity == "normal")
 
454
    this->message_verbosity = VERBOSITY_NORMAL;
 
455
  else if (verbosity == "verbose")
 
456
    this->message_verbosity = VERBOSITY_VERBOSE;
 
457
  else
 
458
    throw error(verbosity, VERBOSITY_INVALID);
 
459
}
 
460
 
385
461
string_list
386
462
sbuild::chroot::list_facets () const
387
463
{
420
496
  env.add("CHROOT_DESCRIPTION", chroot.get_description());
421
497
  env.add("CHROOT_MOUNT_LOCATION", chroot.get_mount_location());
422
498
  env.add("CHROOT_PATH", chroot.get_path());
423
 
  env.add("CHROOT_SCRIPT_CONFIG", normalname(std::string(PACKAGE_SYSCONF_DIR) +  '/' + chroot.get_script_config()));
 
499
  env.add("CHROOT_SCRIPT_CONFIG", normalname(std::string(SCHROOT_SYSCONF_DIR) +  '/' + chroot.get_script_config()));
424
500
  env.add("CHROOT_SESSION_CREATE",
425
501
          static_cast<bool>(chroot.get_session_flags() & SESSION_CREATE));
426
502
  env.add("CHROOT_SESSION_CLONE",
528
604
    .add(_("Description"), chroot.get_description())
529
605
    .add(_("Type"), chroot.get_chroot_type())
530
606
    .add(_("Priority"), chroot.get_priority())
 
607
    .add(_("Message Verbosity"), chroot.get_verbosity_string())
531
608
    .add(_("Users"), chroot.get_users())
532
609
    .add(_("Groups"), chroot.get_groups())
533
610
    .add(_("Root Users"), chroot.get_root_users())
534
611
    .add(_("Root Groups"), chroot.get_root_groups())
535
612
    .add(_("Aliases"), chroot.get_aliases())
 
613
    .add(_("Preserve Environment"), chroot.get_preserve_environment())
536
614
    .add(_("Environment Filter"), chroot.get_environment_filter())
537
615
    .add(_("Run Setup Scripts"), chroot.get_run_setup_scripts())
538
616
    .add(_("Script Configuration"), chroot.get_script_config())
637
715
                                 keyfile, chroot.get_keyfile_name(),
638
716
                                 "command-prefix");
639
717
 
 
718
  keyfile::set_object_value(chroot, &chroot::get_verbosity_string,
 
719
                            keyfile, chroot.get_keyfile_name(),
 
720
                            "message-verbosity");
 
721
 
 
722
  keyfile::set_object_value(chroot, &chroot::get_preserve_environment,
 
723
                            keyfile, chroot.get_keyfile_name(),
 
724
                            "preserve-environment");
640
725
}
641
726
 
642
727
void
777
862
                                 "command-prefix",
778
863
                                 keyfile::PRIORITY_OPTIONAL);
779
864
  used_keys.push_back("command-prefix");
 
865
 
 
866
  keyfile::get_object_value(chroot, &chroot::set_verbosity,
 
867
                            keyfile, chroot.get_keyfile_name(),
 
868
                            "message-verbosity",
 
869
                            keyfile::PRIORITY_OPTIONAL);
 
870
  used_keys.push_back("message-verbosity");
 
871
 
 
872
  keyfile::get_object_value(chroot, &chroot::set_preserve_environment,
 
873
                            keyfile, chroot.get_keyfile_name(),
 
874
                            "preserve-environment",
 
875
                            keyfile::PRIORITY_OPTIONAL);
 
876
  used_keys.push_back("preserve-environment");
780
877
}