Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 5 | #include "tpm2-simulator/simulator.h" |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 6 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame^] | 7 | #include <base/at_exit.h> |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 8 | #include <base/logging.h> |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame^] | 9 | #include <brillo/flag_helper.h> |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 10 | #include <brillo/syslog_logging.h> |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 11 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 12 | int main(int argc, char* argv[]) { |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame^] | 13 | DEFINE_bool(sigstop, true, "raise SIGSTOP when TPM initialized"); |
| 14 | DEFINE_string(work_dir, "/mnt/stateful_partition/unencrypted/tpm2-simulator", |
| 15 | "Daemon data folder"); |
| 16 | |
| 17 | base::AtExitManager at_exit; |
| 18 | |
| 19 | brillo::FlagHelper::Init(argc, argv, "TPM2 simulator"); |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 20 | brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderrIfTty); |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 21 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame^] | 22 | if (chdir(FLAGS_work_dir.c_str()) < 0) { |
| 23 | PLOG(ERROR) << "Failed to change to current directory"; |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 24 | } |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 25 | |
| 26 | tpm2_simulator::SimulatorDaemon daemon; |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame^] | 27 | daemon.set_sigstop_on_initialized(FLAGS_sigstop); |
| 28 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 29 | daemon.Run(); |
Jocelyn Bohr | 185432c | 2015-08-13 14:16:09 -0700 | [diff] [blame] | 30 | } |