From b027bec1572d6ada2f0a25bae1ef86909ba11059 Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Sat, 26 Jan 2019 17:05:44 +0100 Subject: [PATCH] - helpers: add function to execute control scripts Signed-off-by: Thilo Graf --- src/system/helpers.cpp | 14 ++++++++++++++ src/system/helpers.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index be9ae68df..a9d4e88df 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -397,6 +397,20 @@ std::string find_executable(const char *name) return ""; } +bool exec_controlscript(std::string script) +{ + std::string controlscript = (std::string)CONTROLDIR + "/" + script; + if (access((std::string)CONTROLDIR_VAR + "/" + script.c_str(), X_OK) == 0) + controlscript = (std::string)CONTROLDIR_VAR + "/" + script; + + dprintf(DEBUG_NORMAL, "executing %s\n", controlscript.c_str()); + int ret = my_system(controlscript.c_str()); + if (ret) + dprintf(DEBUG_NORMAL, "control script failed\n"); + + return ret; +} + std::string backtick(std::string command) { char *buf = NULL; diff --git a/src/system/helpers.h b/src/system/helpers.h index 3a8cc477f..d51b42ee8 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -57,6 +57,7 @@ bool get_mem_usage(unsigned long &total, unsigned long &free); int mySleep(int sec); std::string find_executable(const char *name); +bool exec_controlscript(std::string script); /* basically what "foo=`command`" does in the shell */ std::string backtick(std::string command);