Elly Jones | 7316178 | 2012-08-14 17:37:05 -0400 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "icmp_tool.h" |
| 6 | |
| 7 | #include <stdlib.h> |
| 8 | #include <base/stringprintf.h> |
| 9 | |
| 10 | #include "process_with_output.h" |
| 11 | |
| 12 | namespace debugd { |
| 13 | |
| 14 | ICMPTool::ICMPTool() { } |
| 15 | ICMPTool::~ICMPTool() { } |
| 16 | |
| 17 | std::string ICMPTool::TestICMP(const std::string& host, DBus::Error* error) { |
| 18 | char *envvar = getenv("DEBUGD_HELPERS"); |
| 19 | std::string path = StringPrintf("%s/icmp", envvar ? envvar |
| 20 | : "/usr/libexec/debugd/helpers"); |
| 21 | if (path.length() > PATH_MAX) |
| 22 | return "<path too long>"; |
| 23 | ProcessWithOutput p; |
| 24 | if (!p.Init()) |
| 25 | return "<can't create process>"; |
| 26 | p.AddArg(path); |
| 27 | p.AddArg(host); |
| 28 | p.Run(); |
| 29 | std::string out; |
| 30 | p.GetOutput(&out); |
| 31 | return out; |
| 32 | } |
| 33 | |
| 34 | }; // namespace debugd |