From 3216bdcce3eac58acb615e33bcf0b63d35f26ac3 Mon Sep 17 00:00:00 2001 From: vanhofen Date: Sat, 26 Jan 2019 17:05:44 +0100 Subject: [PATCH] helpers: add function to execute control scripts Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/7882ee480517bff94c2e4a434b0c218a1aef44aa Author: vanhofen Date: 2019-01-26 (Sat, 26 Jan 2019) Origin message was: ------------------ - helpers: add function to execute control scripts ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- 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 38e9742a5..5712c70e2 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -527,6 +527,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 38a2955b1..eb788e23d 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -59,6 +59,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);