Elly Jones | a44d22d | 2012-01-05 18:05:56 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #include "debugd/src/tracepath_tool.h" |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 6 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 7 | #include "debugd/src/process_with_id.h" |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 8 | |
| 9 | namespace debugd { |
| 10 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame^] | 11 | namespace { |
| 12 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 13 | const char kTracepath[] = "/usr/sbin/tracepath"; |
Mike Frysinger | 9bab10a | 2015-05-18 03:35:32 -0400 | [diff] [blame] | 14 | const char kTracepath6[] = "/usr/sbin/tracepath6"; |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 15 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame^] | 16 | } // namespace |
| 17 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 18 | std::string TracePathTool::Start( |
| 19 | const DBus::FileDescriptor& outfd, |
| 20 | const std::string& destination, |
| 21 | const std::map<std::string, DBus::Variant>& options, |
| 22 | DBus::Error* error) { |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 23 | ProcessWithId* p = CreateProcess(true); |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 24 | if (!p) |
| 25 | return ""; |
Mike Frysinger | 9bab10a | 2015-05-18 03:35:32 -0400 | [diff] [blame] | 26 | |
| 27 | auto option_iter = options.find("v6"); |
| 28 | if (option_iter != options.end() && option_iter->second.reader().get_bool()) |
| 29 | p->AddArg(kTracepath6); |
| 30 | else |
| 31 | p->AddArg(kTracepath); |
| 32 | |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 33 | if (options.count("numeric") == 1) { |
| 34 | p->AddArg("-n"); |
| 35 | } |
| 36 | p->AddArg(destination); |
| 37 | p->BindFd(outfd.get(), STDOUT_FILENO); |
| 38 | p->BindFd(outfd.get(), STDERR_FILENO); |
| 39 | LOG(INFO) << "tracepath: running process id: " << p->id(); |
| 40 | p->Start(); |
| 41 | return p->id(); |
| 42 | } |
| 43 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 44 | } // namespace debugd |