diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-03-10 01:49:37 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-03-13 13:58:46 +0100 |
commit | 12844170ad33d96cb0c5fa411f4eb62fea6e3d5d (patch) | |
tree | ffbfff3aa0edbf3b80678530076b7d4ee09bd124 /apt-pkg/contrib/cdromutl.cc | |
parent | a0975c8d97f06ac116c5cea9a98993817ced0e86 (diff) |
support very long mtab entries in mountpoint discovery
Old code limited lines to 250 characters which is probably enough for
everybody, but who knows… It also takes care of device nodes which start
with the same prefix.
Diffstat (limited to 'apt-pkg/contrib/cdromutl.cc')
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index f850e08a5..936e377fb 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -23,6 +23,7 @@ #include <string.h> #include <iostream> #include <string> +#include <vector> #include <sys/statvfs.h> #include <dirent.h> #include <fcntl.h> @@ -262,37 +263,34 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) return true; } /*}}}*/ - // FindMountPointForDevice - Find mountpoint for the given device /*{{{*/ string FindMountPointForDevice(const char *devnode) { - char buf[255]; - char *out[10]; - int i=0; - // this is the order that mount uses as well - const char *mount[] = { "/etc/mtab", - "/proc/mount", - NULL }; + std::vector<std::string> const mounts = _config->FindVector("Dir::state::MountPoints", "/etc/mtab,/proc/mount"); - for (i=0; mount[i] != NULL; i++) { - if (FileExists(mount[i])) { - FILE *f=fopen(mount[i], "r"); - while ( fgets(buf, sizeof(buf), f) != NULL) { - if (strncmp(buf, devnode, strlen(devnode)) == 0) { - if(TokSplitString(' ', buf, out, 10)) - { - fclose(f); - // unescape the \0XXX chars in the path - string mount_point = out[1]; - return DeEscapeString(mount_point); - } - } - } - fclose(f); + for (std::vector<std::string>::const_iterator m = mounts.begin(); m != mounts.end(); ++m) + if (FileExists(*m) == true) + { + char * line = NULL; + size_t line_len = 0; + FILE * f = fopen(m->c_str(), "r"); + while(getline(&line, &line_len, f) != -1) + { + char * out[] = { NULL, NULL, NULL }; + TokSplitString(' ', line, out, 3); + if (out[2] != NULL || out[1] == NULL || out[0] == NULL) + continue; + if (strcmp(out[0], devnode) != 0) + continue; + fclose(f); + // unescape the \0XXX chars in the path + string mount_point = out[1]; + return DeEscapeString(mount_point); + } + fclose(f); } - } - + return string(); } /*}}}*/ |