From bac3536cc949b3af0185e7b8f9b18318b37ac8b0 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 7 Jun 2016 11:22:00 -0700 Subject: [PATCH] init: expand arguments of services when they start Arguments of commands are expanded based on properties if they contain ${property.name}, however this is not currently done for arguments of services. This patch makes it that arguments of services are expanded each time that the service starts at the point immediately before execve(). Change-Id: Iba581a8377e25a6478d4d2ec2e8b29e181d8640c --- init/service.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/init/service.cpp b/init/service.cpp index 4175d054f..fad61c6da 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -471,13 +471,21 @@ bool Service::Start() { } } + std::vector expanded_args; std::vector strs; - for (const auto& s : args_) { - strs.push_back(const_cast(s.c_str())); + expanded_args.resize(args_.size()); + strs.push_back(const_cast(args_[0].c_str())); + for (std::size_t i = 1; i < args_.size(); ++i) { + if (!expand_props(args_[i], &expanded_args[i])) { + ERROR("%s: cannot expand '%s'\n", args_[0].c_str(), args_[i].c_str()); + _exit(127); + } + strs.push_back(const_cast(expanded_args[i].c_str())); } strs.push_back(nullptr); - if (execve(args_[0].c_str(), (char**) &strs[0], (char**) ENV) < 0) { - ERROR("cannot execve('%s'): %s\n", args_[0].c_str(), strerror(errno)); + + if (execve(strs[0], (char**) &strs[0], (char**) ENV) < 0) { + ERROR("cannot execve('%s'): %s\n", strs[0], strerror(errno)); } _exit(127);