blob: d171f83ff6a46b0c670f1e71ebf0676b9519e313 [file] [log] [blame]
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "icmp_tool.h"
#include <stdlib.h>
#include <base/strings/stringprintf.h>
#include "process_with_output.h"
using base::StringPrintf;
using std::map;
using std::string;
namespace debugd {
ICMPTool::ICMPTool() { }
ICMPTool::~ICMPTool() { }
string ICMPTool::TestICMP(const string& host, DBus::Error* error) {
map<string, string> options;
return TestICMPWithOptions(host, options, error);
string ICMPTool::TestICMPWithOptions(const string& host,
const map<string, string>& options,
DBus::Error* error) {
char *envvar = getenv("DEBUGD_HELPERS");
string path = StringPrintf("%s/icmp", envvar ? envvar
: "/usr/libexec/debugd/helpers");
if (path.length() > PATH_MAX)
return "<path too long>";
ProcessWithOutput p;
if (!p.Init())
return "<can't create process>";
for (map<string, string>::const_iterator it = options.begin();
it != options.end();
it++) {
// No need to quote here because chromeos:ProcessImpl (base class of
// ProcessWithOutput) passes arguments as is to helpers/icmp, which will
// check arguments before executing in the shell.
p.AddArg(StringPrintf("--%s=%s", it->first.c_str(), it->second.c_str()));
string out;
return out;
}; // namespace debugd