blob: 635e5b7cd5c31804e8ba79c812173f26d6e42300 [file] [log] [blame]
Elly Jonesa44d22d2012-01-05 18:05:56 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Elly Jones00e439d2011-12-19 16:59:10 -05002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#include "debugd/src/tracepath_tool.h"
Elly Jones00e439d2011-12-19 16:59:10 -05006
Alex Vakulenko262be3f2014-07-30 15:25:50 -07007#include "debugd/src/process_with_id.h"
Elly Jones00e439d2011-12-19 16:59:10 -05008
9namespace debugd {
10
Ben Chanaf125862017-02-08 23:11:18 -080011namespace {
12
Ben Chana0011d82014-05-13 00:19:29 -070013const char kTracepath[] = "/usr/sbin/tracepath";
Mike Frysinger9bab10a2015-05-18 03:35:32 -040014const char kTracepath6[] = "/usr/sbin/tracepath6";
Elly Jones00e439d2011-12-19 16:59:10 -050015
Ben Chanaf125862017-02-08 23:11:18 -080016} // namespace
17
Ben Chana0011d82014-05-13 00:19:29 -070018std::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-Jonesd9a16cd2012-11-12 16:09:49 -050023 ProcessWithId* p = CreateProcess(true);
Elly Jones00e439d2011-12-19 16:59:10 -050024 if (!p)
25 return "";
Mike Frysinger9bab10a2015-05-18 03:35:32 -040026
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 Jones00e439d2011-12-19 16:59:10 -050033 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 Chana0011d82014-05-13 00:19:29 -070044} // namespace debugd