diff options
Diffstat (limited to 'libexec/listmounts/main.cc')
-rw-r--r-- | libexec/listmounts/main.cc | 140 |
1 files changed, 72 insertions, 68 deletions
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; } |