blob: 51000ba384f2035c4b36aa4742675b3a79ed9427 [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(
Eric Carusocc7106c2017-04-27 14:22:42 -070019 const dbus::FileDescriptor& outfd,
Ben Chana0011d82014-05-13 00:19:29 -070020 const std::string& destination,
Eric Carusocc7106c2017-04-27 14:22:42 -070021 const brillo::VariantDictionary& options) {
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050022 ProcessWithId* p = CreateProcess(true);
Elly Jones00e439d2011-12-19 16:59:10 -050023 if (!p)
24 return "";
Mike Frysinger9bab10a2015-05-18 03:35:32 -040025
Eric Carusocc7106c2017-04-27 14:22:42 -070026 if (brillo::GetVariantValueOrDefault<bool>(options, "v6"))
Mike Frysinger9bab10a2015-05-18 03:35:32 -040027 p->AddArg(kTracepath6);
28 else
29 p->AddArg(kTracepath);
30
Eric Carusocc7106c2017-04-27 14:22:42 -070031 if (options.count("numeric") == 1)
Elly Jones00e439d2011-12-19 16:59:10 -050032 p->AddArg("-n");
Eric Carusocc7106c2017-04-27 14:22:42 -070033
Elly Jones00e439d2011-12-19 16:59:10 -050034 p->AddArg(destination);
Eric Carusocc7106c2017-04-27 14:22:42 -070035 p->BindFd(outfd.value(), STDOUT_FILENO);
36 p->BindFd(outfd.value(), STDERR_FILENO);
Elly Jones00e439d2011-12-19 16:59:10 -050037 LOG(INFO) << "tracepath: running process id: " << p->id();
38 p->Start();
39 return p->id();
40}
41
Ben Chana0011d82014-05-13 00:19:29 -070042} // namespace debugd