blob: bdad5f2025c0e8baf264e14d0c8936d916b29fe4 [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 "ping_tool.h"
#include <map>
#include <string>
#include "process_with_id.h"
namespace debugd {
const char* kSetuidHack = "/usr/libexec/debugd/helpers/minijail-setuid-hack.sh";
const char* kPing = "/bin/ping";
PingTool::PingTool() : SubprocessTool() { }
PingTool::~PingTool() { }
std::string PingTool::Start(const DBus::FileDescriptor& outfd,
const std::string& destination,
const std::map<std::string, DBus::Variant>&
options,
DBus::Error& error) {
ProcessWithId* p = CreateProcess(true);
if (!p)
return "";
p->AddArg(kSetuidHack);
p->AddArg(kPing);
if (options.count("broadcast") == 1) {
p->AddArg("-b");
}
if (options.count("count") == 1) {
// If we try to convert a non-int value to an int here, dbus-c++ will toss
// a C++ exception, which the dbus-c++ main loop will convert into a dbus
// exception and return it to our caller.
p->AddIntOption("-c", options.find("count")->second);
}
if (options.count("interval") == 1) {
p->AddIntOption("-i", options.find("interval")->second);
}
if (options.count("numeric") == 1) {
p->AddArg("-n");
}
if (options.count("packetsize") == 1) {
p->AddIntOption("-s", options.find("packetsize")->second);
}
if (options.count("waittime") == 1) {
p->AddIntOption("-W", options.find("waittime")->second);
}
p->AddArg(destination);
p->BindFd(outfd.get(), STDOUT_FILENO);
p->BindFd(outfd.get(), STDERR_FILENO);
LOG(INFO) << "ping: running process id: " << p->id();
p->Start();
return p->id();
}
}; // namespace debugd