diff options
author | Roger Leigh <rleigh@debian.org> | 2013-05-04 22:50:21 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-05-04 22:50:21 +0100 |
commit | 4ec183f4fa454c8ddbe41e306ab9ba12e098e098 (patch) | |
tree | 4d959cd9ea4502c2b5a2eb5be4c315b781e1f5f5 | |
parent | d630103fc2fce03441f1776805004614f01b5cee (diff) | |
download | schroot-4ec183f4fa454c8ddbe41e306ab9ba12e098e098.tar.gz |
libexec: Sources use namespace scoping
Enclose in namespace as for sbuild sources.
-rw-r--r-- | bin/dchroot-dsa/main.cc | 46 | ||||
-rw-r--r-- | bin/dchroot-dsa/options.cc | 140 | ||||
-rw-r--r-- | bin/dchroot-dsa/session.cc | 140 | ||||
-rw-r--r-- | bin/dchroot/dchroot.cc | 1 | ||||
-rw-r--r-- | bin/dchroot/main.cc | 44 | ||||
-rw-r--r-- | bin/dchroot/options.cc | 150 | ||||
-rw-r--r-- | bin/dchroot/session.cc | 162 | ||||
-rw-r--r-- | bin/schroot/main.cc | 66 | ||||
-rw-r--r-- | bin/schroot/options.cc | 224 | ||||
-rw-r--r-- | bin/schroot/schroot.cc | 1 | ||||
-rw-r--r-- | libexec/listmounts/listmounts.cc | 6 | ||||
-rw-r--r-- | libexec/listmounts/main.cc | 140 | ||||
-rw-r--r-- | libexec/listmounts/options.cc | 92 | ||||
-rw-r--r-- | libexec/mount/main.cc | 484 | ||||
-rw-r--r-- | libexec/mount/mount.cc | 6 | ||||
-rw-r--r-- | libexec/mount/options.cc | 118 |
16 files changed, 931 insertions, 889 deletions
diff --git a/bin/dchroot-dsa/main.cc b/bin/dchroot-dsa/main.cc index 410af234..0a92ae91 100644 --- a/bin/dchroot-dsa/main.cc +++ b/bin/dchroot-dsa/main.cc @@ -35,29 +35,33 @@ using std::endl; using sbuild::_; using boost::format; -using namespace dchroot_dsa; - -main::main (schroot_common::options::ptr& options): - dchroot_common::main("dchroot-dsa", - // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-' - // is an em-dash. - _("[OPTION…] chroot [COMMAND] — run command or shell in a chroot"), - options) -{ -} -main::~main () +namespace dchroot_dsa { -} -void -main::create_session(sbuild::session::operation sess_op) -{ - sbuild::log_debug(sbuild::DEBUG_INFO) - << "Creating dchroot-dsa session" << endl; + main::main (schroot_common::options::ptr& options): + dchroot_common::main("dchroot-dsa", + // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-' + // is an em-dash. + _("[OPTION…] chroot [COMMAND] — run command or shell in a chroot"), + options) + { + } + + main::~main () + { + } + + void + main::create_session(sbuild::session::operation sess_op) + { + sbuild::log_debug(sbuild::DEBUG_INFO) + << "Creating dchroot-dsa session" << endl; + + this->session = sbuild::session::ptr + (new dchroot_dsa::session("schroot", + sess_op, + this->chroot_objects)); + } - this->session = sbuild::session::ptr - (new dchroot_dsa::session("schroot", - sess_op, - this->chroot_objects)); } diff --git a/bin/dchroot-dsa/options.cc b/bin/dchroot-dsa/options.cc index eba4eaba..90ab178b 100644 --- a/bin/dchroot-dsa/options.cc +++ b/bin/dchroot-dsa/options.cc @@ -32,76 +32,80 @@ using std::endl; using sbuild::_; using boost::format; namespace opt = boost::program_options; -using namespace dchroot_dsa; -options::options (): - schroot_common::options() +namespace dchroot_dsa { -} - -options::~options () -{ -} - -void -options::add_options () -{ - // Chain up to add general schroot options. - schroot_common::options::add_options(); - - actions.add_options() - ("listpaths,p", - _("Print paths to available chroots")); - chroot.add_options() - ("all,a", - _("Select all chroots")); + options::options (): + schroot_common::options() + { + } + + options::~options () + { + } + + void + options::add_options () + { + // Chain up to add general schroot options. + schroot_common::options::add_options(); + + actions.add_options() + ("listpaths,p", + _("Print paths to available chroots")); + + chroot.add_options() + ("all,a", + _("Select all chroots")); + + chrootenv.add_options() + ("directory,d", opt::value<std::string>(&this->directory), + _("Directory to use")); + } + + void + options::check_options () + { + // Chain up to check general schroot options. + schroot_common::options::check_options(); + + if (vm.count("listpaths")) + this->action = ACTION_LOCATION; + + if (vm.count("all")) + { + this->all = false; + this->all_chroots = true; + this->all_sessions = false; + } + + // Always preserve environment. + this->preserve = true; + + // If no chroots specified, use the first non-option. + if (this->chroots.empty() && !this->command.empty()) + { + this->chroots.push_back(this->command[0]); + this->command.erase(this->command.begin()); + } + + // dchroot-dsa only allows one command. + if (this->command.size() > 1) + throw error(_("Only one command may be specified")); + + if (!this->command.empty() && + !sbuild::is_absname(this->command[0])) + throw error(_("Command must have an absolute path")); + + if (this->chroots.empty() && !all_used() && + (this->action != ACTION_CONFIG && + this->action != ACTION_INFO && + this->action != ACTION_LIST && + this->action != ACTION_LOCATION && + this->action != ACTION_HELP && + this->action != ACTION_VERSION)) + throw error(_("No chroot specified")); + } - chrootenv.add_options() - ("directory,d", opt::value<std::string>(&this->directory), - _("Directory to use")); -} - -void -options::check_options () -{ - // Chain up to check general schroot options. - schroot_common::options::check_options(); - - if (vm.count("listpaths")) - this->action = ACTION_LOCATION; - - if (vm.count("all")) - { - this->all = false; - this->all_chroots = true; - this->all_sessions = false; - } - - // Always preserve environment. - this->preserve = true; - - // If no chroots specified, use the first non-option. - if (this->chroots.empty() && !this->command.empty()) - { - this->chroots.push_back(this->command[0]); - this->command.erase(this->command.begin()); - } - - // dchroot-dsa only allows one command. - if (this->command.size() > 1) - throw error(_("Only one command may be specified")); - - if (!this->command.empty() && - !sbuild::is_absname(this->command[0])) - throw error(_("Command must have an absolute path")); - - if (this->chroots.empty() && !all_used() && - (this->action != ACTION_CONFIG && - this->action != ACTION_INFO && - this->action != ACTION_LIST && - this->action != ACTION_LOCATION && - this->action != ACTION_HELP && - this->action != ACTION_VERSION)) - throw error(_("No chroot specified")); } diff --git a/bin/dchroot-dsa/session.cc b/bin/dchroot-dsa/session.cc index 855515a3..0e003749 100644 --- a/bin/dchroot-dsa/session.cc +++ b/bin/dchroot-dsa/session.cc @@ -37,76 +37,80 @@ using std::cout; using std::endl; using sbuild::_; using boost::format; -using namespace dchroot_dsa; -session::session (std::string const& service, - operation operation, - sbuild::session::chroot_list const& chroots): - dchroot_common::session(service, operation, chroots) +namespace dchroot_dsa { -} -session::~session () -{ -} + session::session (std::string const& service, + operation operation, + sbuild::session::chroot_list const& chroots): + dchroot_common::session(service, operation, chroots) + { + } + + session::~session () + { + } + + sbuild::string_list + session::get_login_directories (sbuild::chroot::chroot::ptr& session_chroot, + sbuild::environment const& env) const + { + sbuild::string_list ret; + + std::string const& wd(get_auth()->get_wd()); + if (!wd.empty()) + { + // Set specified working directory. + ret.push_back(wd); + } + else + { + ret.push_back(get_auth()->get_home()); + + // Final fallback to root. + if (std::find(ret.begin(), ret.end(), "/") == ret.end()) + ret.push_back("/"); + } + + return ret; + } + + void + session::get_user_command (sbuild::chroot::chroot::ptr& session_chroot, + std::string& file, + sbuild::string_list& command, + sbuild::environment const& env) const + { + std::string programstring = command[0]; + file = programstring; + + if (!sbuild::is_absname(file)) + throw error(file, COMMAND_ABS); + + std::string commandstring = sbuild::string_list_to_string(command, " "); + sbuild::log_debug(sbuild::DEBUG_NOTICE) + << format("Running command: %1%") % commandstring << endl; + if (get_auth()->get_uid() == 0 || + get_auth()->get_ruid() != get_auth()->get_uid()) + syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"", + session_chroot->get_name().c_str(), + get_auth()->get_ruser().c_str(), + get_auth()->get_user().c_str(), + commandstring.c_str()); + + if (session_chroot->get_verbosity() != sbuild::chroot::chroot::VERBOSITY_QUIET) + { + std::string format_string; + // TRANSLATORS: %1% = chroot name + // TRANSLATORS: %2% = command + format_string = (_("[%1% chroot] Running command: “%2%”")); + + format fmt(format_string); + fmt % session_chroot->get_name() + % programstring; + sbuild::log_info() << fmt << endl; + } + } -sbuild::string_list -session::get_login_directories (sbuild::chroot::chroot::ptr& session_chroot, - sbuild::environment const& env) const -{ - sbuild::string_list ret; - - std::string const& wd(get_auth()->get_wd()); - if (!wd.empty()) - { - // Set specified working directory. - ret.push_back(wd); - } - else - { - ret.push_back(get_auth()->get_home()); - - // Final fallback to root. - if (std::find(ret.begin(), ret.end(), "/") == ret.end()) - ret.push_back("/"); - } - - return ret; -} - -void -session::get_user_command (sbuild::chroot::chroot::ptr& session_chroot, - std::string& file, - sbuild::string_list& command, - sbuild::environment const& env) const -{ - std::string programstring = command[0]; - file = programstring; - - if (!sbuild::is_absname(file)) - throw error(file, COMMAND_ABS); - - std::string commandstring = sbuild::string_list_to_string(command, " "); - sbuild::log_debug(sbuild::DEBUG_NOTICE) - << format("Running command: %1%") % commandstring << endl; - if (get_auth()->get_uid() == 0 || - get_auth()->get_ruid() != get_auth()->get_uid()) - syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"", - session_chroot->get_name().c_str(), - get_auth()->get_ruser().c_str(), - get_auth()->get_user().c_str(), - commandstring.c_str()); - - if (session_chroot->get_verbosity() != sbuild::chroot::chroot::VERBOSITY_QUIET) - { - std::string format_string; - // TRANSLATORS: %1% = chroot name - // TRANSLATORS: %2% = command - format_string = (_("[%1% chroot] Running command: “%2%”")); - - format fmt(format_string); - fmt % session_chroot->get_name() - % programstring; - sbuild::log_info() << fmt << endl; - } } diff --git a/bin/dchroot/dchroot.cc b/bin/dchroot/dchroot.cc index f4a31a31..658e2650 100644 --- a/bin/dchroot/dchroot.cc +++ b/bin/dchroot/dchroot.cc @@ -25,7 +25,6 @@ using std::endl; using boost::format; -using namespace dchroot; /** * Main routine. diff --git a/bin/dchroot/main.cc b/bin/dchroot/main.cc index 9bdf0485..3f30f093 100644 --- a/bin/dchroot/main.cc +++ b/bin/dchroot/main.cc @@ -35,28 +35,32 @@ using std::endl; using sbuild::_; using boost::format; -using namespace dchroot; - -main::main (schroot_common::options::ptr& options): - dchroot_common::main("dchroot", - // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-' - // is an em-dash. - _("[OPTION…] [COMMAND] — run command or shell in a chroot"), - options) -{ -} -main::~main () +namespace dchroot { -} -void -main::create_session (sbuild::session::operation sess_op) -{ - sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating dchroot session" << endl; + main::main (schroot_common::options::ptr& options): + dchroot_common::main("dchroot", + // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-' + // is an em-dash. + _("[OPTION…] [COMMAND] — run command or shell in a chroot"), + options) + { + } + + main::~main () + { + } + + void + main::create_session (sbuild::session::operation sess_op) + { + sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating dchroot session" << endl; + + this->session = sbuild::session::ptr + (new dchroot::session("schroot", + sess_op, + this->chroot_objects)); + } - this->session = sbuild::session::ptr - (new dchroot::session("schroot", - sess_op, - this->chroot_objects)); } diff --git a/bin/dchroot/options.cc b/bin/dchroot/options.cc index b91b330b..a817f176 100644 --- a/bin/dchroot/options.cc +++ b/bin/dchroot/options.cc @@ -30,81 +30,85 @@ using std::endl; using sbuild::_; using boost::format; namespace opt = boost::program_options; -using namespace dchroot; -options::options (): - schroot_common::options() +namespace dchroot { -} -options::~options () -{ -} + options::options (): + schroot_common::options() + { + } + + options::~options () + { + } + + void + options::add_options () + { + // Chain up to add general schroot options. + schroot_common::options::add_options(); + + actions.add_options() + ("path,p", opt::value<std::string>(&this->chroot_path), + _("Print path to selected chroot")); + + chroot.add_options() + ("all,a", + _("Select all chroots")); + + chrootenv.add_options() + ("directory", opt::value<std::string>(&this->directory), + _("Directory to use")) + ("preserve-environment,d", + _("Preserve user environment")); + } + + void + options::check_options () + { + // Chain up to check general schroot options. + schroot_common::options::check_options(); + + if (vm.count("path")) + { + this->action = ACTION_LOCATION; + this->chroots.clear(); + this->chroots.push_back(this->chroot_path); + } + + if (vm.count("all")) + { + this->all = false; + this->all_chroots = true; + this->all_sessions = false; + } + + if (vm.count("preserve-environment")) + this->preserve = true; + + if (this->quiet && this->verbose) + { + sbuild::log_warning() + << _("--quiet and --verbose may not be used at the same time") + << endl; + sbuild::log_info() << _("Using verbose output") << endl; + } + + if (!this->chroots.empty() && all_used()) + { + sbuild::log_warning() + << _("--chroot and --all may not be used at the same time") + << endl; + sbuild::log_info() << _("Using --chroots only") << endl; + this->all = this->all_chroots = this->all_sessions = false; + } + + if (this->all == true) + { + this->all_chroots = true; + this->all_sessions = true; + } + } -void -options::add_options () -{ - // Chain up to add general schroot options. - schroot_common::options::add_options(); - - actions.add_options() - ("path,p", opt::value<std::string>(&this->chroot_path), - _("Print path to selected chroot")); - - chroot.add_options() - ("all,a", - _("Select all chroots")); - - chrootenv.add_options() - ("directory", opt::value<std::string>(&this->directory), - _("Directory to use")) - ("preserve-environment,d", - _("Preserve user environment")); -} - -void -options::check_options () -{ - // Chain up to check general schroot options. - schroot_common::options::check_options(); - - if (vm.count("path")) - { - this->action = ACTION_LOCATION; - this->chroots.clear(); - this->chroots.push_back(this->chroot_path); - } - - if (vm.count("all")) - { - this->all = false; - this->all_chroots = true; - this->all_sessions = false; - } - - if (vm.count("preserve-environment")) - this->preserve = true; - - if (this->quiet && this->verbose) - { - sbuild::log_warning() - << _("--quiet and --verbose may not be used at the same time") - << endl; - sbuild::log_info() << _("Using verbose output") << endl; - } - - if (!this->chroots.empty() && all_used()) - { - sbuild::log_warning() - << _("--chroot and --all may not be used at the same time") - << endl; - sbuild::log_info() << _("Using --chroots only") << endl; - this->all = this->all_chroots = this->all_sessions = false; - } - - if (this->all == true) - { - this->all_chroots = true; - this->all_sessions = true; - } } diff --git a/bin/dchroot/session.cc b/bin/dchroot/session.cc index 21a6e00f..03938846 100644 --- a/bin/dchroot/session.cc +++ b/bin/dchroot/session.cc @@ -37,87 +37,91 @@ using std::cout; using std::endl; using sbuild::_; using boost::format; -using namespace dchroot; -session::session (std::string const& service, - operation operation, - sbuild::session::chroot_list const& chroots): - dchroot_common::session(service, operation, chroots) +namespace dchroot { -} -session::~session () -{ -} + session::session (std::string const& service, + operation operation, + sbuild::session::chroot_list const& chroots): + dchroot_common::session(service, operation, chroots) + { + } + + session::~session () + { + } + + sbuild::string_list + session::get_login_directories (sbuild::chroot::chroot::ptr& session_chroot, + sbuild::environment const& env) const + { + sbuild::string_list ret; + + std::string const& wd(get_auth()->get_wd()); + if (!wd.empty()) + { + // Set specified working directory. + ret.push_back(wd); + } + else + { + // Set current working directory only if preserving environment. + // Only change to home if not preserving the environment. + if (get_preserve_environment() || + session_chroot->get_preserve_environment()) + ret.push_back(this->sbuild::session::cwd); + else + ret.push_back(get_auth()->get_home()); + + // Final fallback to root. + if (std::find(ret.begin(), ret.end(), "/") == ret.end()) + ret.push_back("/"); + } + + return ret; + } + + void + session::get_user_command (sbuild::chroot::chroot::ptr& session_chroot, + std::string& file, + sbuild::string_list& command, + sbuild::environment const& env) const + { + std::string programstring = sbuild::string_list_to_string(command, " "); + + command.clear(); + command.push_back("/bin/sh"); + command.push_back("-c"); + command.push_back(programstring); + + file = command[0]; + + sbuild::log_debug(sbuild::DEBUG_NOTICE) << "file=" << file << endl; + + std::string commandstring = sbuild::string_list_to_string(command, " "); + sbuild::log_debug(sbuild::DEBUG_NOTICE) + << format("Running command: %1%") % commandstring << endl; + if (get_auth()->get_uid() == 0 || + get_auth()->get_ruid() != get_auth()->get_uid()) + syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"", + session_chroot->get_name().c_str(), + get_auth()->get_ruser().c_str(), + get_auth()->get_user().c_str(), + commandstring.c_str()); + + if (session_chroot->get_verbosity() != sbuild::chroot::chroot::VERBOSITY_QUIET) + { + std::string format_string; + // TRANSLATORS: %1% = chroot name + // TRANSLATORS: %2% = command + format_string = (_("[%1% chroot] Running command: “%2%”")); + + format fmt(format_string); + fmt % session_chroot->get_name() + % programstring; + sbuild::log_info() << fmt << endl; + } + } -sbuild::string_list -session::get_login_directories (sbuild::chroot::chroot::ptr& session_chroot, - sbuild::environment const& env) const -{ - sbuild::string_list ret; - - std::string const& wd(get_auth()->get_wd()); - if (!wd.empty()) - { - // Set specified working directory. - ret.push_back(wd); - } - else - { - // Set current working directory only if preserving environment. - // Only change to home if not preserving the environment. - if (get_preserve_environment() || - session_chroot->get_preserve_environment()) - ret.push_back(this->sbuild::session::cwd); - else - ret.push_back(get_auth()->get_home()); - - // Final fallback to root. - if (std::find(ret.begin(), ret.end(), "/") == ret.end()) - ret.push_back("/"); - } - - return ret; -} - -void -session::get_user_command (sbuild::chroot::chroot::ptr& session_chroot, - std::string& file, - sbuild::string_list& command, - sbuild::environment const& env) const -{ - std::string programstring = sbuild::string_list_to_string(command, " "); - - command.clear(); - command.push_back("/bin/sh"); - command.push_back("-c"); - command.push_back(programstring); - - file = command[0]; - - sbuild::log_debug(sbuild::DEBUG_NOTICE) << "file=" << file << endl; - - std::string commandstring = sbuild::string_list_to_string(command, " "); - sbuild::log_debug(sbuild::DEBUG_NOTICE) - << format("Running command: %1%") % commandstring << endl; - if (get_auth()->get_uid() == 0 || - get_auth()->get_ruid() != get_auth()->get_uid()) - syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"", - session_chroot->get_name().c_str(), - get_auth()->get_ruser().c_str(), - get_auth()->get_user().c_str(), - commandstring.c_str()); - - if (session_chroot->get_verbosity() != sbuild::chroot::chroot::VERBOSITY_QUIET) - { - std::string format_string; - // TRANSLATORS: %1% = chroot name - // TRANSLATORS: %2% = command - format_string = (_("[%1% chroot] Running command: “%2%”")); - - format fmt(format_string); - fmt % session_chroot->get_name() - % programstring; - sbuild::log_info() << fmt << endl; - } } diff --git a/bin/schroot/main.cc b/bin/schroot/main.cc index 79d5cd53..aab79ac0 100644 --- a/bin/schroot/main.cc +++ b/bin/schroot/main.cc @@ -35,43 +35,47 @@ using std::endl; using boost::format; using sbuild::_; -using namespace schroot; -main::main (schroot_common::options::ptr& options): - schroot_common::main("schroot", - _("[OPTION…] [COMMAND] — run command or shell in a chroot"), - options, - true) +namespace schroot { -} -main::~main () -{ -} + main::main (schroot_common::options::ptr& options): + schroot_common::main("schroot", + _("[OPTION…] [COMMAND] — run command or shell in a chroot"), + options, + true) + { + } -void -main::action_list () -{ - // This list is pre-validated. - for (const auto& chroot : this->chroot_names) - std::cout << chroot << '\n'; - std::cout << std::flush; -} + main::~main () + { + } -void -main::create_session(sbuild::session::operation sess_op) -{ - sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating schroot session" << endl; + void + main::action_list () + { + // This list is pre-validated. + for (const auto& chroot : this->chroot_names) + std::cout << chroot << '\n'; + std::cout << std::flush; + } - this->session = sbuild::session::ptr - (new sbuild::session("schroot", sess_op, this->chroot_objects)); -} + void + main::create_session(sbuild::session::operation sess_op) + { + sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating schroot session" << endl; -void -main::add_session_auth () -{ - schroot_common::main::add_session_auth(); + this->session = sbuild::session::ptr + (new sbuild::session("schroot", sess_op, this->chroot_objects)); + } + + void + main::add_session_auth () + { + schroot_common::main::add_session_auth(); + + if (!this->options->user.empty()) + this->session->get_auth()->set_user(this->options->user); + } - if (!this->options->user.empty()) - this->session->get_auth()->set_user(this->options->user); } diff --git a/bin/schroot/options.cc b/bin/schroot/options.cc index 48f1416c..19a1bd86 100644 --- a/bin/schroot/options.cc +++ b/bin/schroot/options.cc @@ -30,120 +30,124 @@ using std::endl; using boost::format; using sbuild::_; namespace opt = boost::program_options; -using namespace schroot; -options::options (): - schroot_common::options() +namespace schroot { -} - -options::~options () -{ -} - -void -options::add_options () -{ - // Chain up to add general schroot options. - schroot_common::options::add_options(); - - actions.add_options() - ("location", - _("Print location of selected chroots")); - - chroot.add_options() - ("all,a", - _("Select all chroots and active sessions")) - ("all-chroots", - _("Select all chroots")) - ("all-sessions", - _("Select all active sessions")) - ("all-source-chroots", - _("Select all source chroots")) - ("exclude-aliases", - _("Do not include aliases")); - - chrootenv.add_options() - ("directory,d", opt::value<std::string>(&this->directory), - _("Directory to use")) - ("shell,s", opt::value<std::string>(&this->shell), - _("Shell to use as login shell")) - ("user,u", opt::value<std::string>(&this->user), - _("Username (default current user)")) - ("preserve-environment,p", - _("Preserve user environment")) - ("option,o", opt::value<sbuild::string_list>(&this->useroptions), - _("Set option")); - - session_actions.add_options() - ("automatic-session", - _("Begin, run and end a session automatically (default)")) - ("begin-session,b", - _("Begin a session; returns a session ID")) - ("recover-session", - _("Recover an existing session")) - ("run-session,r", - _("Run an existing session")) - ("end-session,e", - _("End an existing session")); - - session_options.add_options() - ("session-name,n", opt::value<std::string>(&this->session_name), - _("Session name (defaults to an automatically generated name)")) - ("force,f", - _("Force operation, even if it fails")); -} - -void -options::check_options () -{ - // Chain up to check general schroot options. - schroot_common::options::check_options(); - - if (vm.count("location")) - this->action = ACTION_LOCATION; - - if (vm.count("all")) - this->all = true; - if (vm.count("all-chroots")) - this->all_chroots = true; - if (vm.count("all-sessions")) - this->all_sessions = true; - if (vm.count("all-source-chroots")) - this->all_source_chroots = true; - if (vm.count("exclude-aliases")) - this->exclude_aliases = true; - - if (vm.count("preserve-environment")) - this->preserve = true; - - if (vm.count("automatic-session")) - this->action = ACTION_SESSION_AUTO; - if (vm.count("begin-session")) - this->action = ACTION_SESSION_BEGIN; - if (vm.count("recover-session")) - this->action = ACTION_SESSION_RECOVER; - if (vm.count("run-session")) - this->action = ACTION_SESSION_RUN; - if (vm.count("end-session")) - this->action = ACTION_SESSION_END; - if (vm.count("force")) - this->session_force = true; - - if (this->all == true) - { + options::options (): + schroot_common::options() + { + } + + options::~options () + { + } + + void + options::add_options () + { + // Chain up to add general schroot options. + schroot_common::options::add_options(); + + actions.add_options() + ("location", + _("Print location of selected chroots")); + + chroot.add_options() + ("all,a", + _("Select all chroots and active sessions")) + ("all-chroots", + _("Select all chroots")) + ("all-sessions", + _("Select all active sessions")) + ("all-source-chroots", + _("Select all source chroots")) + ("exclude-aliases", + _("Do not include aliases")); + + chrootenv.add_options() + ("directory,d", opt::value<std::string>(&this->directory), + _("Directory to use")) + ("shell,s", opt::value<std::string>(&this->shell), + _("Shell to use as login shell")) + ("user,u", opt::value<std::string>(&this->user), + _("Username (default current user)")) + ("preserve-environment,p", + _("Preserve user environment")) + ("option,o", opt::value<sbuild::string_list>(&this->useroptions), + _("Set option")); + + session_actions.add_options() + ("automatic-session", + _("Begin, run and end a session automatically (default)")) + ("begin-session,b", + _("Begin a session; returns a session ID")) + ("recover-session", + _("Recover an existing session")) + ("run-session,r", + _("Run an existing session")) + ("end-session,e", + _("End an existing session")); + + session_options.add_options() + ("session-name,n", opt::value<std::string>(&this->session_name), + _("Session name (defaults to an automatically generated name)")) + ("force,f", + _("Force operation, even if it fails")); + } + + + void + options::check_options () + { + // Chain up to check general schroot options. + schroot_common::options::check_options(); + + if (vm.count("location")) + this->action = ACTION_LOCATION; + + if (vm.count("all")) + this->all = true; + if (vm.count("all-chroots")) this->all_chroots = true; + if (vm.count("all-sessions")) this->all_sessions = true; + if (vm.count("all-source-chroots")) this->all_source_chroots = true; - } - - for (const auto& useroption : this->useroptions) - { - std::string::size_type sep = useroption.find_first_of('=', 0); - std::string key = useroption.substr(0,sep); - ++sep; - std::string value = useroption.substr(sep); - this->useroptions_map.insert(std::make_pair(key,value)); - } + if (vm.count("exclude-aliases")) + this->exclude_aliases = true; + + if (vm.count("preserve-environment")) + this->preserve = true; + + if (vm.count("automatic-session")) + this->action = ACTION_SESSION_AUTO; + if (vm.count("begin-session")) + this->action = ACTION_SESSION_BEGIN; + if (vm.count("recover-session")) + this->action = ACTION_SESSION_RECOVER; + if (vm.count("run-session")) + this->action = ACTION_SESSION_RUN; + if (vm.count("end-session")) + this->action = ACTION_SESSION_END; + if (vm.count("force")) + this->session_force = true; + + if (this->all == true) + { + this->all_chroots = true; + this->all_sessions = true; + this->all_source_chroots = true; + } + + for (const auto& useroption : this->useroptions) + { + std::string::size_type sep = useroption.find_first_of('=', 0); + std::string key = useroption.substr(0,sep); + ++sep; + std::string value = useroption.substr(sep); + this->useroptions_map.insert(std::make_pair(key,value)); + } + } + } diff --git a/bin/schroot/schroot.cc b/bin/schroot/schroot.cc index 395af026..7aeffb51 100644 --- a/bin/schroot/schroot.cc +++ b/bin/schroot/schroot.cc @@ -25,7 +25,6 @@ using std::endl; using boost::format; -using namespace schroot; /** * Main routine. diff --git a/libexec/listmounts/listmounts.cc b/libexec/listmounts/listmounts.cc index 7ba1be93..46d3cd1f 100644 --- a/libexec/listmounts/listmounts.cc +++ b/libexec/listmounts/listmounts.cc @@ -18,8 +18,8 @@ #include <config.h> -#include <listmounts/options.h> -#include <listmounts/main.h> +#include <libexec/listmounts/options.h> +#include <libexec/listmounts/main.h> #include <bin-common/run.h> @@ -27,8 +27,6 @@ using std::endl; using boost::format; namespace opt = boost::program_options; -using namespace schroot_listmounts; - /** * Main routine. * diff --git a/libexec/listmounts/main.cc b/libexec/listmounts/main.cc index 7ecaedd1..a4118c37 100644 --- a/libexec/listmounts/main.cc +++ b/libexec/listmounts/main.cc @@ -21,7 +21,7 @@ #include <sbuild/mntstream.h> #include <sbuild/util.h> -#include <listmounts/main.h> +#include <libexec/listmounts/main.h> #include <cerrno> #include <climits> @@ -41,83 +41,87 @@ using std::endl; using boost::format; using sbuild::_; using sbuild::N_; -using namespace schroot_listmounts; -template<> -sbuild::error<main::error_code>::map_type -sbuild::error<main::error_code>::error_strings = - { - // TRANSLATORS: %1% = file - {main::FIND, N_("Failed to find ‘%1%’")} - }; - -main::main (options::ptr& options): - bin_common::main("schroot-listmounts", - // TRANSLATORS: '...' is an ellipsis e.g. U+2026, - // and '-' is an em-dash. - _("[OPTION…] — list mount points"), - options, - false), - opts(options) -{ -} - -main::~main () +namespace schroot_listmounts { -} -void -main::action_listmounts () -{ - std::string to_find = sbuild::normalname(this->opts->mountpoint); + template<> + sbuild::error<main::error_code>::map_type + sbuild::error<main::error_code>::error_strings = + { + // TRANSLATORS: %1% = file + {schroot_listmounts::main::FIND, N_("Failed to find ‘%1%’")} + }; + + main::main (options::ptr& options): + bin_common::main("schroot-listmounts", + // TRANSLATORS: '...' is an ellipsis e.g. U+2026, + // and '-' is an em-dash. + _("[OPTION…] — list mount points"), + options, + false), + opts(options) + { + } + main::~main () { - // NOTE: This is a non-standard GNU extension. - char *rpath = realpath(to_find.c_str(), NULL); - if (rpath == 0) - throw error(to_find, FIND, strerror(errno)); - - to_find = rpath; - free(rpath); - rpath = 0; } - // Check mounts. - sbuild::mntstream mounts("/proc/mounts"); - sbuild::mntstream::mntentry entry; - sbuild::string_list mountlist; + void + main::action_listmounts () + { + std::string to_find = sbuild::normalname(this->opts->mountpoint); - while (mounts >> entry) { - std::string mount_dir(entry.directory); - if (to_find == "/" || - (mount_dir.find(to_find) == 0 && - (// Names are the same. - mount_dir.size() == to_find.size() || - // Must have a following /, or not the same directory. - (mount_dir.size() > to_find.size() && - mount_dir[to_find.size()] == '/')))) - mountlist.push_back(mount_dir); + // NOTE: This is a non-standard GNU extension. + char *rpath = realpath(to_find.c_str(), NULL); + if (rpath == 0) + throw error(to_find, FIND, strerror(errno)); + + to_find = rpath; + free(rpath); + rpath = 0; } - for (sbuild::string_list::const_reverse_iterator mount = mountlist.rbegin(); - mount != mountlist.rend(); - ++mount) - std::cout << *mount << '\n'; - std::cout << std::flush; -} + // Check mounts. + sbuild::mntstream mounts("/proc/mounts"); + sbuild::mntstream::mntentry entry; + sbuild::string_list mountlist; + + while (mounts >> entry) + { + std::string mount_dir(entry.directory); + if (to_find == "/" || + (mount_dir.find(to_find) == 0 && + (// Names are the same. + mount_dir.size() == to_find.size() || + // Must have a following /, or not the same directory. + (mount_dir.size() > to_find.size() && + mount_dir[to_find.size()] == '/')))) + mountlist.push_back(mount_dir); + } + + for (sbuild::string_list::const_reverse_iterator mount = mountlist.rbegin(); + mount != mountlist.rend(); + ++mount) + std::cout << *mount << '\n'; + std::cout << std::flush; + } + + int + main::run_impl () + { + if (this->opts->action == options::ACTION_HELP) + action_help(std::cerr); + else if (this->opts->action == options::ACTION_VERSION) + action_version(std::cerr); + else if (this->opts->action == options::ACTION_LISTMOUNTS) + action_listmounts(); + else + assert(0); // Invalid action. + + return EXIT_SUCCESS; + } -int -main::run_impl () -{ - if (this->opts->action == options::ACTION_HELP) - action_help(std::cerr); - else if (this->opts->action == options::ACTION_VERSION) - action_version(std::cerr); - else if (this->opts->action == options::ACTION_LISTMOUNTS) - action_listmounts(); - else - assert(0); // Invalid action. - - return EXIT_SUCCESS; } diff --git a/libexec/listmounts/options.cc b/libexec/listmounts/options.cc index 122e9f41..6c13f610 100644 --- a/libexec/listmounts/options.cc +++ b/libexec/listmounts/options.cc @@ -20,7 +20,7 @@ #include <sbuild/i18n.h> -#include <listmounts/options.h> +#include <libexec/listmounts/options.h> #include <cstdlib> #include <iostream> @@ -32,59 +32,63 @@ using std::endl; using boost::format; using sbuild::_; namespace opt = boost::program_options; -using namespace schroot_listmounts; -const options::action_type options::ACTION_LISTMOUNTS ("listmounts"); - -options::options (): - bin_common::options(), - mountpoint(), - mount(_("Mount")) +namespace schroot_listmounts { -} -options::~options () -{ -} + const options::action_type options::ACTION_LISTMOUNTS ("listmounts"); -void -options::add_options () -{ - // Chain up to add basic options. - bin_common::options::add_options(); + options::options (): + bin_common::options(), + mountpoint(), + mount(_("Mount")) + { + } - action.add(ACTION_LISTMOUNTS); - action.set_default(ACTION_LISTMOUNTS); + options::~options () + { + } - mount.add_options() - ("mountpoint,m", opt::value<std::string>(&this->mountpoint), - _("Mountpoint to check (full path)")); -} + void + options::add_options () + { + // Chain up to add basic options. + bin_common::options::add_options(); -void -options::add_option_groups () -{ - // Chain up to add basic option groups. - bin_common::options::add_option_groups(); + action.add(ACTION_LISTMOUNTS); + action.set_default(ACTION_LISTMOUNTS); + + mount.add_options() + ("mountpoint,m", opt::value<std::string>(&this->mountpoint), + _("Mountpoint to check (full path)")); + } + + void + options::add_option_groups () + { + // Chain up to add basic option groups. + bin_common::options::add_option_groups(); #ifndef BOOST_PROGRAM_OPTIONS_DESCRIPTION_OLD - if (!mount.options().empty()) + if (!mount.options().empty()) #else - if (!mount.primary_keys().empty()) + if (!mount.primary_keys().empty()) #endif - { - visible.add(mount); - global.add(mount); - } -} - -void -options::check_options () -{ - // Chain up to check basic options. - bin_common::options::check_options(); + { + visible.add(mount); + global.add(mount); + } + } + + void + options::check_options () + { + // Chain up to check basic options. + bin_common::options::check_options(); + + if (this->action == ACTION_LISTMOUNTS && + this->mountpoint.empty()) + throw error(_("No mount point specified")); + } - if (this->action == ACTION_LISTMOUNTS && - this->mountpoint.empty()) - throw error(_("No mount point specified")); } diff --git a/libexec/mount/main.cc b/libexec/mount/main.cc index 88405eef..f01c87e4 100644 --- a/libexec/mount/main.cc +++ b/libexec/mount/main.cc @@ -21,7 +21,7 @@ #include <sbuild/mntstream.h> #include <sbuild/util.h> -#include <mount/main.h> +#include <libexec/mount/main.h> #include <cerrno> #include <climits> @@ -45,254 +45,258 @@ using std::endl; using boost::format; using sbuild::_; using sbuild::N_; -using namespace schroot_mount; -template<> -sbuild::error<main::error_code>::map_type -sbuild::error<main::error_code>::error_strings = - { - {main::CHILD_FORK, N_("Failed to fork child")}, - {main::CHILD_WAIT, N_("Wait for child failed")}, - // TRANSLATORS: %1% = command name - {main::EXEC, N_("Failed to execute “%1%”")}, - {main::REALPATH, N_("Failed to resolve path “%1%”")} - }; - -main::main (options::ptr& options): - bin_common::main("schroot-mount", - // TRANSLATORS: '...' is an ellipsis e.g. U+2026, - // and '-' is an em-dash. - _("[OPTION…] — mount filesystems"), - options, - false), - opts(options) +namespace schroot_mount { -} - -main::~main () -{ -} -std::string -main::resolve_path (std::string const& mountpoint) -{ - // Ensure entry has a leading / to prevent security hole where - // mountpoint might be outside the chroot. - std::string absmountpoint(mountpoint); - if (absmountpoint.empty() || absmountpoint[0] != '/') - absmountpoint = std::string("/") + absmountpoint; - - char *resolved_path = realpath(opts->mountpoint.c_str(), 0); - if (!resolved_path) - throw error(opts->mountpoint, REALPATH, strerror(errno)); - std::string basepath(resolved_path); - std::free(resolved_path); - - std::string directory(opts->mountpoint + absmountpoint); - // Canonicalise path to remove any symlinks. - resolved_path = realpath(directory.c_str(), 0); - if (resolved_path == 0) - { - // The path is either not present or is an invalid link. If - // it's not present, we'll create it later. If it's a link, - // bail out now. - bool link = false; - try - { - if (sbuild::stat(directory, true).is_link()) - link = true; - } - catch (...) - {} // Does not exist, not a link - - if (link) - throw error(directory, REALPATH, strerror(ENOTDIR)); - else - { - // Try validating the parent directory. - sbuild::string_list dirs = sbuild::split_string(mountpoint, "/"); - if (dirs.size() > 1) // Recurse if possible, otherwise continue - { - std::string saveddir = *dirs.rbegin(); - dirs.pop_back(); - - std::string newpath(resolve_path(sbuild::string_list_to_string(dirs, "/"))); - directory = newpath + "/" + saveddir; - } - } - } - else + template<> + sbuild::error<main::error_code>::map_type + sbuild::error<main::error_code>::error_strings = { - directory = resolved_path; - std::free(resolved_path); - } - // If the link was absolute (i.e. points somewhere on the host, - // outside the chroot, make sure that this is modified to be - // inside. - if (directory.size() < basepath.size() || - directory.substr(0,basepath.size()) != basepath) - directory = basepath + directory; - - return directory; -} - -void -main::action_mount () -{ - // Check mounts. - sbuild::mntstream mounts(opts->fstab); - - sbuild::mntstream::mntentry entry; + {schroot_mount::main::CHILD_FORK, N_("Failed to fork child")}, + {schroot_mount::main::CHILD_WAIT, N_("Wait for child failed")}, + // TRANSLATORS: %1% = command name + {schroot_mount::main::EXEC, N_("Failed to execute “%1%”")}, + {schroot_mount::main::REALPATH, N_("Failed to resolve path “%1%”")} + }; + + main::main (options::ptr& options): + bin_common::main("schroot-mount", + // TRANSLATORS: '...' is an ellipsis e.g. U+2026, + // and '-' is an em-dash. + _("[OPTION…] — mount filesystems"), + options, + false), + opts(options) + { + } - while (mounts >> entry) - { - std::string directory = resolve_path(entry.directory); - - if (!boost::filesystem::exists(directory)) - { - sbuild::log_debug(sbuild::DEBUG_INFO) - << boost::format("Creating ‘%1%' in '%2%’") - % entry.directory - % opts->mountpoint - << std::endl; - - if (!opts->dry_run) - { - try - { - boost::filesystem::create_directories(directory); - } - catch (std::exception const& e) - { - sbuild::log_exception_error(e); - exit(EXIT_FAILURE); - } - catch (...) - { - sbuild::log_error() - << _("An unknown exception occurred") << std::endl; - exit(EXIT_FAILURE); - } - } - } + main::~main () + { + } + std::string + main::resolve_path (std::string const& mountpoint) + { + // Ensure entry has a leading / to prevent security hole where + // mountpoint might be outside the chroot. + std::string absmountpoint(mountpoint); + if (absmountpoint.empty() || absmountpoint[0] != '/') + absmountpoint = std::string("/") + absmountpoint; + + char *resolved_path = realpath(opts->mountpoint.c_str(), 0); + if (!resolved_path) + throw error(opts->mountpoint, REALPATH, strerror(errno)); + std::string basepath(resolved_path); + std::free(resolved_path); + + std::string directory(opts->mountpoint + absmountpoint); + // Canonicalise path to remove any symlinks. + resolved_path = realpath(directory.c_str(), 0); + if (resolved_path == 0) + { + // The path is either not present or is an invalid link. If + // it's not present, we'll create it later. If it's a link, + // bail out now. + bool link = false; + try + { + if (sbuild::stat(directory, true).is_link()) + link = true; + } + catch (...) + {} // Does not exist, not a link + + if (link) + throw error(directory, REALPATH, strerror(ENOTDIR)); + else + { + // Try validating the parent directory. + sbuild::string_list dirs = sbuild::split_string(mountpoint, "/"); + if (dirs.size() > 1) // Recurse if possible, otherwise continue + { + std::string saveddir = *dirs.rbegin(); + dirs.pop_back(); + + std::string newpath(resolve_path(sbuild::string_list_to_string(dirs, "/"))); + directory = newpath + "/" + saveddir; + } + } + } + else + { + directory = resolved_path; + std::free(resolved_path); + } + // If the link was absolute (i.e. points somewhere on the host, + // outside the chroot, make sure that this is modified to be + // inside. + if (directory.size() < basepath.size() || + directory.substr(0,basepath.size()) != basepath) + directory = basepath + directory; + + return directory; + } + + void + main::action_mount () + { + // Check mounts. + sbuild::mntstream mounts(opts->fstab); + + sbuild::mntstream::mntentry entry; + + while (mounts >> entry) + { + std::string directory = resolve_path(entry.directory); + + if (!boost::filesystem::exists(directory)) + { + sbuild::log_debug(sbuild::DEBUG_INFO) + << boost::format("Creating ‘%1%' in '%2%’") + % entry.directory + % opts->mountpoint + << std::endl; + + if (!opts->dry_run) + { + try + { + boost::filesystem::create_directories(directory); + } + catch (std::exception const& e) + { + sbuild::log_exception_error(e); + exit(EXIT_FAILURE); + } + catch (...) + { + sbuild::log_error() + << _("An unknown exception occurred") << std::endl; + exit(EXIT_FAILURE); + } + } + } + + sbuild::log_debug(sbuild::DEBUG_INFO) + << boost::format("Mounting ‘%1%’ on ‘%2%’") + % entry.filesystem_name + % directory + << std::endl; + + if (!opts->dry_run) + { + sbuild::string_list command; + command.push_back("/bin/mount"); + if (opts->verbose) + command.push_back("-v"); + command.push_back("-t"); + command.push_back(entry.type); + command.push_back("-o"); + command.push_back(entry.options); + command.push_back(entry.filesystem_name); + command.push_back(directory); + + int status = run_child(command[0], command, sbuild::environment()); + + if (status) + exit(status); + } + } + } + + int + main::run_child (std::string const& file, + sbuild::string_list const& command, + sbuild::environment const& env) + { + int exit_status = 0; + pid_t pid; + + if ((pid = fork()) == -1) + { + throw error(CHILD_FORK, strerror(errno)); + } + else if (pid == 0) + { + try + { + sbuild::log_debug(sbuild::DEBUG_INFO) + << "mount_main: executing " + << sbuild::string_list_to_string(command, ", ") + << std::endl; + exec(file, command, env); + error e(file, EXEC, strerror(errno)); + sbuild::log_exception_error(e); + } + catch (std::exception const& e) + { + sbuild::log_exception_error(e); + } + catch (...) + { + sbuild::log_error() + << _("An unknown exception occurred") << std::endl; + } + _exit(EXIT_FAILURE); + } + else + { + wait_for_child(pid, exit_status); + } + + if (exit_status) sbuild::log_debug(sbuild::DEBUG_INFO) - << boost::format("Mounting ‘%1%’ on ‘%2%’") - % entry.filesystem_name - % directory + << "mount_main: " << file + << " failed with status " << exit_status + << std::endl; + else + sbuild::log_debug(sbuild::DEBUG_INFO) + << "mount_main: " << file + << " succeeded" << std::endl; - if (!opts->dry_run) - { - sbuild::string_list command; - command.push_back("/bin/mount"); - if (opts->verbose) - command.push_back("-v"); - command.push_back("-t"); - command.push_back(entry.type); - command.push_back("-o"); - command.push_back(entry.options); - command.push_back(entry.filesystem_name); - command.push_back(directory); - - int status = run_child(command[0], command, sbuild::environment()); - - if (status) - exit(status); - } - } -} - -int -main::run_child (std::string const& file, - sbuild::string_list const& command, - sbuild::environment const& env) -{ - int exit_status = 0; - pid_t pid; - - if ((pid = fork()) == -1) - { - throw error(CHILD_FORK, strerror(errno)); - } - else if (pid == 0) - { - try - { - sbuild::log_debug(sbuild::DEBUG_INFO) - << "mount_main: executing " - << sbuild::string_list_to_string(command, ", ") - << std::endl; - exec(file, command, env); - error e(file, EXEC, strerror(errno)); - sbuild::log_exception_error(e); - } - catch (std::exception const& e) - { - sbuild::log_exception_error(e); - } - catch (...) - { - sbuild::log_error() - << _("An unknown exception occurred") << std::endl; - } - _exit(EXIT_FAILURE); - } - else - { - wait_for_child(pid, exit_status); - } - - if (exit_status) - sbuild::log_debug(sbuild::DEBUG_INFO) - << "mount_main: " << file - << " failed with status " << exit_status - << std::endl; - else - sbuild::log_debug(sbuild::DEBUG_INFO) - << "mount_main: " << file - << " succeeded" - << std::endl; - - return exit_status; -} - -void -main::wait_for_child (pid_t pid, - int& child_status) -{ - child_status = EXIT_FAILURE; // Default exit status - - int status; + return exit_status; + } - while (1) - { - if (waitpid(pid, &status, 0) == -1) - { - if (errno == EINTR) - continue; // Wait again. - else - throw error(CHILD_WAIT, strerror(errno)); - } - else - break; - } - - if (WIFEXITED(status)) - child_status = WEXITSTATUS(status); -} + void + main::wait_for_child (pid_t pid, + int& child_status) + { + child_status = EXIT_FAILURE; // Default exit status + + int status; + + while (1) + { + if (waitpid(pid, &status, 0) == -1) + { + if (errno == EINTR) + continue; // Wait again. + else + throw error(CHILD_WAIT, strerror(errno)); + } + else + break; + } + + if (WIFEXITED(status)) + child_status = WEXITSTATUS(status); + } + + int + main::run_impl () + { + if (this->opts->action == options::ACTION_HELP) + action_help(std::cerr); + else if (this->opts->action == options::ACTION_VERSION) + action_version(std::cerr); + else if (this->opts->action == options::ACTION_MOUNT) + action_mount(); + else + assert(0); // Invalid action. + + return EXIT_SUCCESS; + } -int -main::run_impl () -{ - if (this->opts->action == options::ACTION_HELP) - action_help(std::cerr); - else if (this->opts->action == options::ACTION_VERSION) - action_version(std::cerr); - else if (this->opts->action == options::ACTION_MOUNT) - action_mount(); - else - assert(0); // Invalid action. - - return EXIT_SUCCESS; } diff --git a/libexec/mount/mount.cc b/libexec/mount/mount.cc index c998fd0b..0e7c112f 100644 --- a/libexec/mount/mount.cc +++ b/libexec/mount/mount.cc @@ -18,8 +18,8 @@ #include <config.h> -#include <mount/options.h> -#include <mount/main.h> +#include <libexec/mount/options.h> +#include <libexec/mount/main.h> #include <bin-common/run.h> @@ -27,8 +27,6 @@ using std::endl; using boost::format; namespace opt = boost::program_options; -using namespace schroot_mount; - /** * Main routine. * diff --git a/libexec/mount/options.cc b/libexec/mount/options.cc index 1fc7f78a..2c3d48b9 100644 --- a/libexec/mount/options.cc +++ b/libexec/mount/options.cc @@ -21,7 +21,7 @@ #include <sbuild/i18n.h> #include <sbuild/util.h> -#include <mount/options.h> +#include <libexec/mount/options.h> #include <cstdlib> #include <iostream> @@ -33,71 +33,75 @@ using std::endl; using boost::format; using sbuild::_; namespace opt = boost::program_options; -using namespace schroot_mount; -const options::action_type options::ACTION_MOUNT ("mount"); - -options::options (): - bin_common::options(), - dry_run(false), - fstab(), - mountpoint(), - mount(_("Mount")) -{ -} - -options::~options () +namespace schroot_mount { -} - -void -options::add_options () -{ - // Chain up to add basic options. - bin_common::options::add_options(); - - action.add(ACTION_MOUNT); - action.set_default(ACTION_MOUNT); - - mount.add_options() - ("dry-run,d", - _("Perform a simulation of actions which would be taken")) - ("fstab,f", opt::value<std::string>(&this->fstab), - _("fstab file to read (full path)")) - ("mountpoint,m", opt::value<std::string>(&this->mountpoint), - _("Mountpoint to check (full path)")); -} - -void -options::add_option_groups () -{ - // Chain up to add basic option groups. - bin_common::options::add_option_groups(); + const options::action_type options::ACTION_MOUNT ("mount"); + + options::options (): + bin_common::options(), + dry_run(false), + fstab(), + mountpoint(), + mount(_("Mount")) + { + } + + options::~options () + { + } + + void + options::add_options () + { + // Chain up to add basic options. + bin_common::options::add_options(); + + action.add(ACTION_MOUNT); + action.set_default(ACTION_MOUNT); + + + mount.add_options() + ("dry-run,d", + _("Perform a simulation of actions which would be taken")) + ("fstab,f", opt::value<std::string>(&this->fstab), + _("fstab file to read (full path)")) + ("mountpoint,m", opt::value<std::string>(&this->mountpoint), + _("Mountpoint to check (full path)")); + } + + void + options::add_option_groups () + { + // Chain up to add basic option groups. + bin_common::options::add_option_groups(); #ifndef BOOST_PROGRAM_OPTIONS_DESCRIPTION_OLD - if (!mount.options().empty()) + if (!mount.options().empty()) #else - if (!mount.primary_keys().empty()) + if (!mount.primary_keys().empty()) #endif - { - visible.add(mount); - global.add(mount); - } -} + { + visible.add(mount); + global.add(mount); + } + } -void -options::check_options () -{ - // Chain up to check basic options. - bin_common::options::check_options(); + void + options::check_options () + { + // Chain up to check basic options. + bin_common::options::check_options(); + + if (vm.count("dry-run")) + this->dry_run = true; - if (vm.count("dry-run")) - this->dry_run = true; + this->mountpoint = sbuild::normalname(this->mountpoint); - this->mountpoint = sbuild::normalname(this->mountpoint); + if (this->action == ACTION_MOUNT && + this->mountpoint.empty()) + throw error(_("No mount point specified")); + } - if (this->action == ACTION_MOUNT && - this->mountpoint.empty()) - throw error(_("No mount point specified")); } |