Allow PrivilegeEscalator to be disabled during tests.
authorCarl Hetherington <cth@carlh.net>
Tue, 1 Dec 2020 23:34:09 +0000 (00:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 3 Dec 2020 19:16:17 +0000 (20:16 +0100)
src/lib/cross.h
src/lib/cross_linux.cc

index 8b594177e884df269de5395976ed79e135132714..d8f0e56a565ab397092ca6408675fd997890120d 100644 (file)
@@ -73,6 +73,8 @@ class PrivilegeEscalator
 public:
        PrivilegeEscalator ();
        ~PrivilegeEscalator ();
+
+       static bool test;
 };
 
 /** @class Waker
index b6241ec1a3f38763b76e19b03aad2df74fac187b..262ba59ce4cd5c9650234fef4c575edd97ebdc46 100644 (file)
@@ -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));
+               }
        }
 }