summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-06-30 11:02:49 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-06-30 11:02:49 -0500
commitb0690189d37cb96924fd52e6647f84020ba56ef6 (patch)
tree50165df72228c0347a9bc0c24e6283d705908c40 /hscript
parentf269dabec9ea44084692991877eacda60d78c355 (diff)
downloadhorizon-b0690189d37cb96924fd52e6647f84020ba56ef6.tar.gz
horizon-b0690189d37cb96924fd52e6647f84020ba56ef6.tar.bz2
horizon-b0690189d37cb96924fd52e6647f84020ba56ef6.tar.xz
horizon-b0690189d37cb96924fd52e6647f84020ba56ef6.zip
hscript: Ensure operstate file exists before reading
Diffstat (limited to 'hscript')
-rw-r--r--hscript/script_e.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/hscript/script_e.cc b/hscript/script_e.cc
index b8087e6..866a836 100644
--- a/hscript/script_e.cc
+++ b/hscript/script_e.cc
@@ -485,11 +485,16 @@ bool Script::execute() const {
+ iface, ec.message());
EXECUTE_FAILURE("network");
} else {
- std::ifstream statefs("/sys/class/net/" + iface + "/operstate");
- char state;
- statefs.read(&state, 1);
- if(state != 'u')
+ std::string ifpath{"/sys/class/net/" + iface + "/operstate"};
+ if(fs::exists(ifpath)) {
+ std::ifstream statefs(ifpath);
+ char state;
+ statefs.read(&state, 1);
+ if(state != 'u')
+ run_command("service", {"net." + iface, "start"});
+ } else {
run_command("service", {"net." + iface, "start"});
+ }
}
}
break;