blob: daf950f970fbfcbe116a96bd44a14e4345f84b49 [file] [log] [blame]
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "process_with_id.h"
#include <fcntl.h>
#include <unistd.h>
#include <base/strings/string_number_conversions.h>
namespace debugd {
ProcessWithId::ProcessWithId() {}
bool ProcessWithId::Init() {
return SandboxedProcess::Init() && GenerateId();
}
bool ProcessWithId::GenerateId() {
char buf[16];
FILE* urandom = fopen("/dev/urandom", "r");
if (!urandom) {
PLOG(ERROR) << "Can't open /dev/urandom";
return false;
}
if (fread(&buf, sizeof(buf), 1, urandom) != 1) {
PLOG(ERROR) << "Can't read";
fclose(urandom);
return false;
}
id_ = base::HexEncode(buf, sizeof(buf));
fclose(urandom);
return true;
}
} // namespace debugd