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 | |
Tom Hughes | d6c2d39 | 2020-08-24 18:12:11 -0700 | [diff] [blame] | 18 | std::string TracePathTool::Start(const base::ScopedFD& outfd, |
| 19 | const std::string& destination, |
| 20 | const brillo::VariantDictionary& options) { |
Ben Chan | 0d840a7 | 2018-09-27 00:24:48 -0700 | [diff] [blame] | 21 | ProcessWithId* p = |
| 22 | CreateProcess(true /* sandboxed */, false /* access_root_mount_ns */); |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 23 | if (!p) |
| 24 | return ""; |
Mike Frysinger | 9bab10a | 2015-05-18 03:35:32 -0400 | [diff] [blame] | 25 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 26 | if (brillo::GetVariantValueOrDefault<bool>(options, "v6")) |
Mike Frysinger | 9bab10a | 2015-05-18 03:35:32 -0400 | [diff] [blame] | 27 | p->AddArg(kTracepath6); |
| 28 | else |
| 29 | p->AddArg(kTracepath); |
| 30 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 31 | if (options.count("numeric") == 1) |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 32 | p->AddArg("-n"); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 33 | |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 34 | p->AddArg(destination); |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 35 | p->BindFd(outfd.get(), STDOUT_FILENO); |
| 36 | p->BindFd(outfd.get(), STDERR_FILENO); |
Elly Jones | 00e439d | 2011-12-19 16:59:10 -0500 | [diff] [blame] | 37 | LOG(INFO) << "tracepath: running process id: " << p->id(); |
| 38 | p->Start(); |
| 39 | return p->id(); |
| 40 | } |
| 41 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 42 | } // namespace debugd |