diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-12-02 00:34:09 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-12-03 20:16:17 +0100 |
| commit | 3a495e7550759396b79410fa08899829d6636438 (patch) | |
| tree | 8240cea9b34d068883d2e192d3fe918bb5c364d5 /src/lib | |
| parent | e7bc0d3105c9d0cdfb4e0e433dc3d674c770ff33 (diff) | |
Allow PrivilegeEscalator to be disabled during tests.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/cross.h | 2 | ||||
| -rw-r--r-- | src/lib/cross_linux.cc | 15 |
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)); + } } } |
