From 12844170ad33d96cb0c5fa411f4eb62fea6e3d5d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 10 Mar 2014 01:49:37 +0100 Subject: support very long mtab entries in mountpoint discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- apt-pkg/contrib/cdromutl.cc | 48 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'apt-pkg') 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 #include #include +#include #include #include #include @@ -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 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::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(); } /*}}}*/ -- cgit v1.2.3