From 3a495e7550759396b79410fa08899829d6636438 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 2 Dec 2020 00:34:09 +0100 Subject: [PATCH] Allow PrivilegeEscalator to be disabled during tests. --- src/lib/cross.h | 2 ++ 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)); + } } } -- 2.30.2