summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-12-02 00:34:09 +0100
committerCarl Hetherington <cth@carlh.net>2020-12-03 20:16:17 +0100
commit3a495e7550759396b79410fa08899829d6636438 (patch)
tree8240cea9b34d068883d2e192d3fe918bb5c364d5 /src
parente7bc0d3105c9d0cdfb4e0e433dc3d674c770ff33 (diff)
Allow PrivilegeEscalator to be disabled during tests.
Diffstat (limited to 'src')
-rw-r--r--src/lib/cross.h2
-rw-r--r--src/lib/cross_linux.cc15
2 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/cross.h b/src/lib/cross.h
index 8b594177e..d8f0e56a5 100644
--- a/src/lib/cross.h
+++ b/src/lib/cross.h
@@ -73,6 +73,8 @@ class PrivilegeEscalator
public:
PrivilegeEscalator ();
~PrivilegeEscalator ();
+
+ static bool test;
};
/** @class Waker
diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc
index b6241ec1a..262ba59ce 100644
--- a/src/lib/cross_linux.cc
+++ b/src/lib/cross_linux.cc
@@ -373,16 +373,23 @@ unprivileged ()
}
}
+
+bool PrivilegeEscalator::test = false;
+
PrivilegeEscalator::~PrivilegeEscalator ()
{
- unprivileged ();
+ if (!test) {
+ unprivileged ();
+ }
}
PrivilegeEscalator::PrivilegeEscalator ()
{
- int const r = seteuid(0);
- if (r < 0) {
- throw PrivilegeError (String::compose("seteuid() call failed with %1", errno));
+ if (!test) {
+ int const r = seteuid(0);
+ if (r < 0) {
+ throw PrivilegeError (String::compose("seteuid() call failed with %1", errno));
+ }
}
}