core: optimize PrivilegeHelper::runElevated()
Using std::function is overkill
Change-Id: I0e60592aea1b2fb82c3ea780701dae5e129a9810
diff --git a/core/privilege-helper.hpp b/core/privilege-helper.hpp
index 7ddbafc..bbf08e2 100644
--- a/core/privilege-helper.hpp
+++ b/core/privilege-helper.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -35,7 +35,6 @@
class PrivilegeHelper
{
public:
-
/** \brief represents a serious seteuid/gid failure
*
* This should only be caught by main as part of a graceful program termination.
@@ -53,7 +52,7 @@
const char*
what() const
{
- return m_whatMessage.c_str();
+ return m_whatMessage.data();
}
private:
@@ -66,11 +65,22 @@
static void
drop();
+ template<class F>
static void
- runElevated(function<void()> f);
+ runElevated(F&& f)
+ {
+ raise();
+ try {
+ f();
+ }
+ catch (...) {
+ drop();
+ throw;
+ }
+ drop();
+ }
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-
static void
raise();