-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclobber_state_main.cc
60 lines (47 loc) · 1.74 KB
/
clobber_state_main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2018 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 "init/clobber_state.h"
#include <unistd.h>
#include <memory>
#include <base/files/file.h>
#include <base/files/file_util.h>
#include <base/logging.h>
#include "init/crossystem_impl.h"
namespace {
base::File OpenTerminal() {
base::FilePath terminal_path;
if (base::PathExists(base::FilePath("/sbin/frecon"))) {
terminal_path = base::FilePath("/run/frecon/vt0");
} else {
terminal_path = base::FilePath("/dev/tty1");
}
base::File terminal =
base::File(terminal_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
if (!terminal.IsValid()) {
PLOG(WARNING) << "Could not open terminal " << terminal_path.value()
<< " falling back to /dev/null";
terminal = base::File(base::FilePath("/dev/null"),
base::File::FLAG_OPEN | base::File::FLAG_WRITE);
}
return terminal;
}
} // namespace
int main(int argc, char* argv[]) {
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_FILE;
settings.log_file_path = "/tmp/clobber-state.log";
// All logging happens in the main thread, so there is no need to lock the log
// file.
settings.lock_log = logging::DONT_LOCK_LOG_FILE;
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
logging::InitLogging(settings);
if (getuid() != 0) {
LOG(ERROR) << "clobber-state must be run as root";
return 1;
}
ClobberState::Arguments args = ClobberState::ParseArgv(argc, argv);
ClobberState clobber(args, std::make_unique<CrosSystemImpl>(),
std::make_unique<ClobberUi>(OpenTerminal()));
return clobber.Run();
}