OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <syslog.h> | |
7 | |
8 // syslog.h and base/logging.h both try to #define LOG_INFO and LOG_WARNING. | |
9 // We need to #undef at least these two before including base/logging.h. The | |
10 // others are included to be consistent. | |
11 namespace { | |
12 const int kSyslogInfo = LOG_INFO; | |
13 const int kSyslogWarning = LOG_WARNING; | |
14 const int kSyslogError = LOG_ERR; | |
15 const int kSyslogCritical = LOG_CRIT; | |
16 | |
17 #undef LOG_INFO | |
18 #undef LOG_WARNING | |
19 #undef LOG_ERR | |
20 #undef LOG_INFO | |
21 } // namespace | |
22 | |
23 #include <iostream> | 6 #include <iostream> |
24 #include <string> | 7 #include <string> |
25 | 8 |
26 #include <base/command_line.h> | 9 #include <base/command_line.h> |
27 #include <base/file_util.h> | 10 #include <base/file_util.h> |
28 #include <base/logging.h> | 11 #include <chromeos/syslog_logging.h> |
29 | 12 |
30 #include "entd/entd.h" | 13 #include "entd/entd.h" |
31 #include "entd/extensions.h" | 14 #include "entd/extensions.h" |
32 #include "entd/callback_server.h" | 15 #include "entd/callback_server.h" |
33 #include "entd/http.h" | 16 #include "entd/http.h" |
34 #include "entd/pkcs11.h" | 17 #include "entd/pkcs11.h" |
35 #include "entd/utils.h" | 18 #include "entd/utils.h" |
36 | 19 |
37 namespace switches { | 20 namespace switches { |
38 // Path to search for extensions; can contain ~ or env variables (e.g. ${HOME}) | 21 // Path to search for extensions; can contain ~ or env variables (e.g. ${HOME}) |
(...skipping 29 matching lines...) Expand all Loading... | |
68 // be used to override the default logic. | 51 // be used to override the default logic. |
69 static const char *kEnableSyslog = "enable-syslog"; | 52 static const char *kEnableSyslog = "enable-syslog"; |
70 static const char *kDisableSyslog = "disable-syslog"; | 53 static const char *kDisableSyslog = "disable-syslog"; |
71 | 54 |
72 static const char *kLibcrosLocation = "libcros-location"; | 55 static const char *kLibcrosLocation = "libcros-location"; |
73 | 56 |
74 static const char *kCallbackOrigin = "callback-origin"; | 57 static const char *kCallbackOrigin = "callback-origin"; |
75 | 58 |
76 } // namespace switches | 59 } // namespace switches |
77 | 60 |
78 bool handle_message(int severity, const std::string &message) { | |
79 switch (severity) { | |
80 case logging::LOG_INFO: | |
81 severity = kSyslogInfo; | |
82 break; | |
83 | |
84 case logging::LOG_WARNING: | |
85 severity = kSyslogWarning; | |
86 break; | |
87 | |
88 case logging::LOG_ERROR: | |
89 case logging::LOG_ERROR_REPORT: | |
90 severity = kSyslogError; | |
91 break; | |
92 | |
93 case logging::LOG_FATAL: | |
94 severity = kSyslogCritical; | |
95 break; | |
96 } | |
97 | |
98 // The first "] " should be the end of the header added by the logging | |
99 // code. The meat of the message is two characters after that. | |
100 size_t pos = message.find("] "); | |
101 if (pos != std::string::npos && message.length() > pos + 2) { | |
102 pos += 2; | |
103 } else { | |
104 pos = 0; | |
105 } | |
106 | |
107 const char* str = message.c_str() + pos; | |
108 | |
109 syslog(severity, "%s", str); | |
110 return false; | |
111 } | |
112 | |
113 // Return values: | 61 // Return values: |
114 // 0: Entd completed successfully and should not be restarted. | 62 // 0: Entd completed successfully and should not be restarted. |
115 // 1: Entd encountered a failure, but will probably fail again if restarted, | 63 // 1: Entd encountered a failure, but will probably fail again if restarted, |
116 // so please don't. | 64 // so please don't. |
117 // 2: Entd has NOT encountered a failure, but would like to be restarted. | 65 // 2: Entd has NOT encountered a failure, but would like to be restarted. |
118 // >2: Entd has encountered a failure, restarting may help. | 66 // >2: Entd has encountered a failure, restarting may help. |
119 // | 67 // |
120 // So, exit with a zero or one means leave it down, otherwise restart. | 68 // So, exit with a zero or one means leave it down, otherwise restart. |
121 // | 69 // |
122 int main(int argc, char** argv) { | 70 int main(int argc, char** argv) { |
123 std::string manifest, policy, utility; | 71 std::string manifest, policy, utility; |
124 | 72 |
125 CommandLine::Init(argc, argv); | 73 CommandLine::Init(argc, argv); |
126 CommandLine* cl = CommandLine::ForCurrentProcess(); | 74 CommandLine* cl = CommandLine::ForCurrentProcess(); |
127 | 75 int log_flags = chromeos::kLogToStderr; |
128 logging::InitLogging("/dev/null", logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | |
129 logging::DONT_LOCK_LOG_FILE, | |
130 logging::APPEND_TO_OLD_LOG_FILE); | |
131 | 76 |
132 if (cl->HasSwitch(switches::kEnableSyslog) || | 77 if (cl->HasSwitch(switches::kEnableSyslog) || |
133 (!isatty(STDOUT_FILENO) && !cl->HasSwitch(switches::kDisableSyslog))) { | 78 (!isatty(STDOUT_FILENO) && !cl->HasSwitch(switches::kDisableSyslog))) { |
134 // If syslog was explicitly enabled, or stdout is not a tty and syslog | 79 // If syslog was explicitly enabled, or stdout is not a tty and syslog |
135 // was not explicitly disabled, then send all LOG(...) messages to syslog. | 80 // was not explicitly disabled, then send all LOG(...) messages to syslog. |
136 logging::SetLogMessageHandler(handle_message); | 81 log_flags |= chromeos::kLogToSyslog; |
137 } | 82 } |
83 chromeos::InitLog(log_flags); | |
rginda
2011/03/02 19:26:38
nit: newline before this please.
| |
138 | 84 |
139 LOG(INFO) << "Starting entd"; | 85 LOG(INFO) << "Starting entd"; |
140 | 86 |
141 std::string base_extension_path = | 87 std::string base_extension_path = |
142 cl->GetSwitchValueASCII(switches::kExtensionPath); | 88 cl->GetSwitchValueASCII(switches::kExtensionPath); |
143 std::string username = cl->GetSwitchValueASCII(switches::kUsername); | 89 std::string username = cl->GetSwitchValueASCII(switches::kUsername); |
144 std::string root_ca_file = cl->GetSwitchValueASCII(switches::kRootCAFile); | 90 std::string root_ca_file = cl->GetSwitchValueASCII(switches::kRootCAFile); |
145 | 91 |
146 // Get file paths from a valid policy extension if it exists | 92 // Get file paths from a valid policy extension if it exists |
147 std::string extension_path; | 93 std::string extension_path; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 if (!manifest.empty()) | 175 if (!manifest.empty()) |
230 d.SetManifestFile(manifest); | 176 d.SetManifestFile(manifest); |
231 | 177 |
232 if (!policy.empty()) | 178 if (!policy.empty()) |
233 d.SetPolicyFile(policy); | 179 d.SetPolicyFile(policy); |
234 | 180 |
235 uint32_t rv = d.Run(); | 181 uint32_t rv = d.Run(); |
236 LOG(INFO) << "Exiting entd with code: " << rv; | 182 LOG(INFO) << "Exiting entd with code: " << rv; |
237 return rv; | 183 return rv; |
238 } | 184 } |
OLD | NEW |