blob: c2202e87cdbf8428974895d32e578f138e67d90b [file] [log] [blame]
Elly Jonesa44d22d2012-01-05 18:05:56 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Elly Jonese7cb5b32011-12-01 14:18:32 -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/process_with_id.h"
Elly Jonese7cb5b32011-12-01 14:18:32 -05006
Mike Frysinger56379d72019-02-19 16:03:03 -05007#include <string>
8#include <vector>
9
Ben Chan92f092e2017-02-15 11:55:47 -080010#include <base/rand_util.h>
Ben Chan9953a592014-02-05 23:32:00 -080011#include <base/strings/string_number_conversions.h>
Elly Jonese7cb5b32011-12-01 14:18:32 -050012
13namespace debugd {
14
Ben Chan92f092e2017-02-15 11:55:47 -080015namespace {
16
17constexpr int kNumRandomBytesInId = 16;
18
19} // namespace
20
Mike Frysinger56379d72019-02-19 16:03:03 -050021bool ProcessWithId::Init(const std::vector<std::string>& minijail_extra_args) {
22 if (SandboxedProcess::Init(minijail_extra_args)) {
Ben Chan92f092e2017-02-15 11:55:47 -080023 GenerateId();
24 return true;
25 }
26 return false;
Elly Jonese7cb5b32011-12-01 14:18:32 -050027}
28
Mike Frysinger56379d72019-02-19 16:03:03 -050029bool ProcessWithId::Init() {
30 return ProcessWithId::Init({});
31}
32
Ben Chan92f092e2017-02-15 11:55:47 -080033void ProcessWithId::GenerateId() {
34 std::string random_bytes = base::RandBytesAsString(kNumRandomBytesInId);
35 id_ = base::HexEncode(random_bytes.data(), random_bytes.size());
Elly Jonese7cb5b32011-12-01 14:18:32 -050036}
37
Ben Chana0011d82014-05-13 00:19:29 -070038} // namespace debugd