diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-01-07 16:18:48 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-01-07 16:18:48 +0400 |
commit | d4437ff28020eb9df19ba16f07eaa907a8e55163 (patch) | |
tree | 8a98bd15e2b1f486c4e80ffa19d22602aa5a2bef | |
parent | 3a2fbe8989c0ce7f1b23eefdd59ae8aca2cba5dd (diff) | |
download | schroot-d4437ff28020eb9df19ba16f07eaa907a8e55163.tar.gz |
Ported to mnttab
-rw-r--r-- | CMakeLists.txt | 30 | ||||
-rw-r--r-- | lib/sbuild/mntstream.cc | 57 | ||||
-rw-r--r-- | lib/sbuild/mntstream.h | 19 |
3 files changed, 105 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e2e7c80d..4b7d953d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,10 +97,40 @@ check_include_file_cxx ("memory" HAVE_CXX_MEMORY) # tuple check_include_file_cxx ("tuple" HAVE_CXX_TUPLE) +# System headers +include (CheckIncludeFiles) +include (CheckStructHasMember) +check_include_file_cxx ("mntent.h" HAVE_MNTENT_H) +check_include_file_cxx ("sys/mnttab.h" HAVE_SYS_MNTTAB_H) + +if (HAVE_MNTENT_H) + add_definitions (-D HAVE_MNTENT_H=1) + check_struct_has_member ("struct mntent" mnt_opts "mntent.h" HAVE_MNTENT) + if (HAVE_MNTENT) + add_definitions (-D HAVE_MNTENT=1) + endif() +endif() +if (HAVE_SYS_MNTTAB_H) + add_definitions (-D HAVE_SYS_MNTTAB_H=1) + check_struct_has_member ("struct mnttab" mnt_mntopts "sys/mnttab.h" HAVE_MNTTAB) + if (HAVE_MNTTAB) + add_definitions (-D HAVE_MNTTAB=1) + endif() +endif() + # LIBRARY CHECKS include (CheckLibraryExists) include (CheckFunctionExists) +check_function_exists (setmntent HAVE_SETMNTENT) +if (HAVE_SETMNTENT) + add_definitions (-D HAVE_SETMNTENT=1) +endif() +check_function_exists (endmntent HAVE_ENDMNTENT) +if (HAVE_ENDMNTENT) + add_definitions (-D HAVE_ENDMNTENT=1) +endif() + include("cmake/boost-checks.cmake") include("cmake/regex-checks.cmake") diff --git a/lib/sbuild/mntstream.cc b/lib/sbuild/mntstream.cc index 7f5e7d46..6b61670e 100644 --- a/lib/sbuild/mntstream.cc +++ b/lib/sbuild/mntstream.cc @@ -23,6 +23,26 @@ #include <cerrno> #include <cstring> +#ifdef HAVE_MNTTAB +#ifdef __stringify +# undef __stringify +#endif +#define __stringify(x) #x +static const char* mnttab_errors[] = { + "no error", + "entry exceeds MNT_LINE_MAX (" __stringify(MNT_LINE_MAX) ")", + "too many fields in line", + "too few fields in line" +}; +static const char * mnttab_strerror(unsigned int e) +{ + if (e < sizeof(mnttab_errors)) + return mnttab_errors[e]; + else + return "unknown error"; +} +#endif + namespace sbuild { @@ -36,6 +56,7 @@ namespace sbuild {mntstream::MNT_READ, N_("Failed to read mount file ‘%1%’")} }; +#ifdef HAVE_MNTENT mntstream::mntentry::mntentry (const struct mntent& entry): filesystem_name(entry.mnt_fsname), directory(entry.mnt_dir), @@ -45,6 +66,18 @@ namespace sbuild fsck_pass(entry.mnt_passno) { } +#endif +#ifdef HAVE_MNTTAB + mntstream::mntentry::mntentry (const struct mnttab& entry): + filesystem_name(entry.mnt_special), + directory(entry.mnt_mountp), + type(entry.mnt_fstype), + options(entry.mnt_mntopts), + dump_frequency(0), + fsck_pass(0) + { + } +#endif mntstream::mntstream(const std::string& file): @@ -66,7 +99,11 @@ namespace sbuild void mntstream::open(const std::string& file) { +#ifdef HAVE_SETMNTENT this->mntfile = setmntent(file.c_str(), "r"); +#else + this->mntfile = fopen(file.c_str(), "r"); +#endif if (this->mntfile == 0) { this->file.clear(); @@ -90,6 +127,7 @@ namespace sbuild for (i = 0; i < quantity; ++i) { +#ifdef HAVE_MNTENT struct mntent* entry; errno = 0; entry = getmntent(mntfile); @@ -106,6 +144,20 @@ namespace sbuild } mntentry newentry(*entry); // make a mntentry +#elif HAVE_MNTTAB + struct mnttab entry; + int rc = getmntent(mntfile, &entry); + if (rc < 0) { + return; // EOF + } else if (rc > 0) { + this->error_status = true; + throw error(this->file, MNT_READ, mnttab_strerror(rc)); + } + + mntentry newentry(entry); // make a mntentry +#else +#error Neither HAVE_MNTTAB nor HAVE_MNTENT is defined +#endif this->data.push_back(newentry); // push onto the end of the list } } @@ -113,8 +165,13 @@ namespace sbuild void mntstream::close() { +#ifdef HAVE_ENDMNTENT if (this->mntfile) endmntent(this->mntfile); // don't throw an exception on failure +#else + if (this->mntfile) + fclose(this->mntfile); // don't throw an exception on failure +#endif // -- it could be called in the // destructor this->mntfile = 0; diff --git a/lib/sbuild/mntstream.h b/lib/sbuild/mntstream.h index a406d6ed..b1d27741 100644 --- a/lib/sbuild/mntstream.h +++ b/lib/sbuild/mntstream.h @@ -27,7 +27,14 @@ #include <stdio.h> #include <sys/types.h> -#include <mntent.h> + +#ifdef HAVE_MNTENT_H +# include <mntent.h> +#endif + +#ifdef HAVE_SYS_MNTTAB_H +# include <sys/mnttab.h> +#endif namespace sbuild { @@ -68,12 +75,22 @@ namespace sbuild mntentry () {}; +#ifdef HAVE_MNTENT /** * The contructor. * * @param entry the mntent structure to wrap. */ mntentry (const struct mntent& entry); +#endif +#ifdef HAVE_MNTTAB + /** + * The contructor. + * + * @param entry the mnttab structure to wrap. + */ + mntentry (const struct mnttab& entry); +#endif /// Name of mounted filesystem. std::string filesystem_name; |