summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2011-03-10 11:31:34 +0100
committerMichael Vogt <mvo@debian.org>2011-03-10 11:31:34 +0100
commit5039a4c529d8c62bfd770fe90347a7805f31724a (patch)
treef6414e867aa5827cc94313a67546d7a79e902bad /apt-pkg/contrib
parente9ecab0f97be19326c52f2afe04fd9b44eba01ae (diff)
parentc9952021ba65db0581f6053cd6d6e8bf7d563e8f (diff)
merged the lp:~mvo/apt/mvo branch
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cdromutl.cc31
-rw-r--r--apt-pkg/contrib/cdromutl.h1
-rw-r--r--apt-pkg/contrib/fileutl.cc9
3 files changed, 41 insertions, 0 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 68b980407..83c324f54 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -15,6 +15,7 @@
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
#include <apti18n.h>
@@ -234,3 +235,33 @@ 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 };
+
+ 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))
+ return string(out[1]);
+ }
+ }
+ fclose(f);
+ }
+ }
+
+ return string();
+}
+
+
diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h
index 9d14249c5..38ed2996e 100644
--- a/apt-pkg/contrib/cdromutl.h
+++ b/apt-pkg/contrib/cdromutl.h
@@ -19,5 +19,6 @@ bool MountCdrom(string Path, string DeviceName="");
bool UnmountCdrom(string Path);
bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
bool IsMounted(string &Path);
+string FindMountPointForDevice(const char *device);
#endif
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 767951daf..50019872e 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -67,6 +67,15 @@ bool RunScripts(const char *Cnf)
// This is the child
if (Child == 0)
{
+ if (_config->FindDir("DPkg::Chroot-Directory","/") != "/")
+ {
+ std::cerr << "Chrooting into "
+ << _config->FindDir("DPkg::Chroot-Directory")
+ << std::endl;
+ if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
+ _exit(100);
+ }
+
if (chdir("/tmp/") != 0)
_exit(100);