diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-06-23 20:07:41 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-06-23 20:07:41 -0500 |
commit | 6209b9c9f77af5f7ca0618a44bfd0b5955d7d678 (patch) | |
tree | df9b6b5ce94183300a18591e744c45080583e6af /hscript/meta.cc | |
parent | 19d1c74b4c6baabc4b70216e4efc8800044ea4ac (diff) | |
download | horizon-6209b9c9f77af5f7ca0618a44bfd0b5955d7d678.tar.gz horizon-6209b9c9f77af5f7ca0618a44bfd0b5955d7d678.tar.bz2 horizon-6209b9c9f77af5f7ca0618a44bfd0b5955d7d678.tar.xz horizon-6209b9c9f77af5f7ca0618a44bfd0b5955d7d678.zip |
hscript: Implement runlevel support in svcenable key
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r-- | hscript/meta.cc | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc index 15734c5..0ad4ea5 100644 --- a/hscript/meta.cc +++ b/hscript/meta.cc @@ -623,21 +623,34 @@ Key *SvcEnable::parseFromData(const std::string &data, const ScriptLocation &pos, int *errors, int *, const Script *script) { const static std::string valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.-_"; + std::string::size_type space = data.find_first_of(' ');; + std::string svc, runlevel{"default"}; - if(data.find_first_not_of(valid_chars) != std::string::npos) { + if(space != std::string::npos) { + svc = data.substr(0, space); + runlevel = data.substr(space + 1); + } else { + svc = data; + } + + if(svc.find_first_not_of(valid_chars) != std::string::npos) { if(errors) *errors += 1; output_error(pos, "svcenable: invalid service name", data); return nullptr; } - return new SvcEnable(script, pos, data); + return new SvcEnable(script, pos, svc, runlevel); +} + +bool SvcEnable::validate() const { + return true; /* validation occurs during parsing */ } bool SvcEnable::execute() const { const std::string target = script->targetDirectory() + - "/etc/runlevels/default/" + _value; - const std::string initd = "/etc/init.d/" + _value; - output_info(pos, "svcenable: enabling service " + _value); + "/etc/runlevels/" + _runlevel + "/" + _svc; + const std::string initd = "/etc/init.d/" + _svc; + output_info(pos, "svcenable: enabling service " + _svc); if(script->options().test(Simulate)) { std::cout << "ln -s " << initd << " " << target << std::endl; @@ -647,12 +660,12 @@ bool SvcEnable::execute() const { #ifdef HAS_INSTALL_ENV error_code ec; if(!fs::exists(script->targetDirectory() + initd, ec)) { - output_warning(pos, "svcenable: missing service", _value); + output_warning(pos, "svcenable: missing service", _svc); } fs::create_symlink(initd, target, ec); if(ec) { - output_error(pos, "svcenable: could not enable service " + _value, + output_error(pos, "svcenable: could not enable service " + _svc, ec.message()); return false; } |