blob: 8aa1abbaec7643b3fa9ecff910d27becdadc94c3 [file] [log] [blame]
Mark Salyzyn0175b072014-02-26 09:50:16 -08001/*
2 * Copyright (C) 2012-2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <dirent.h>
18#include <errno.h>
19#include <fcntl.h>
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070020#include <poll.h>
Mark Salyzyn882f8562013-12-26 15:13:36 -080021#include <sched.h>
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070022#include <semaphore.h>
23#include <signal.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080024#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <sys/capability.h>
Mark Salyzyneb06de72014-10-13 09:59:37 -070028#include <sys/klog.h>
Elliott Hughese5a0f202014-07-18 17:39:41 -070029#include <sys/prctl.h>
Riley Andrewsd98f4e82015-06-08 23:36:34 -070030#include <sys/resource.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080031#include <sys/stat.h>
32#include <sys/types.h>
Mark Salyzynccbadc62015-03-12 12:25:35 -070033#include <syslog.h>
Mark Salyzyne457b742014-02-19 17:18:31 -080034#include <unistd.h>
Mark Salyzyn0175b072014-02-26 09:50:16 -080035
William Robertsaeca97b2015-07-31 13:10:36 -070036#include <cstdbool>
Mark Salyzynd5600fd2015-06-12 14:59:42 -070037#include <memory>
38
Mark Salyzyne457b742014-02-19 17:18:31 -080039#include <cutils/properties.h>
Mark Salyzyn56ba4b52015-01-30 15:19:48 -080040#include <cutils/sched_policy.h>
Mark Salyzyn11e55cb2015-03-10 16:45:17 -070041#include <cutils/sockets.h>
Mark Salyzynff32f3c2015-04-13 14:24:45 -070042#include <log/event_tag_map.h>
William Robertsaeca97b2015-07-31 13:10:36 -070043#include <packagelistparser/packagelistparser.h>
Mark Salyzyne3aeeee2015-03-17 07:56:32 -070044#include <private/android_filesystem_config.h>
Riley Andrewsd98f4e82015-06-08 23:36:34 -070045#include <utils/threads.h>
Mark Salyzyne457b742014-02-19 17:18:31 -080046
Mark Salyzyn0175b072014-02-26 09:50:16 -080047#include "CommandListener.h"
48#include "LogBuffer.h"
49#include "LogListener.h"
William Roberts29d238d2013-02-08 09:45:26 +090050#include "LogAudit.h"
Mark Salyzyna1aacb72014-10-15 08:49:39 -070051#include "LogKlog.h"
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070052#include "LogUtils.h"
Mark Salyzyn0175b072014-02-26 09:50:16 -080053
Mark Salyzynccbadc62015-03-12 12:25:35 -070054#define KMSG_PRIORITY(PRI) \
55 '<', \
56 '0' + LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(PRI)) / 10, \
57 '0' + LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(PRI)) % 10, \
58 '>'
59
Mark Salyzyndfc47e82014-03-24 10:26:47 -070060//
61// The service is designed to be run by init, it does not respond well
62// to starting up manually. When starting up manually the sockets will
63// fail to open typically for one of the following reasons:
64// EADDRINUSE if logger is running.
65// EACCESS if started without precautions (below)
66//
67// Here is a cookbook procedure for starting up logd manually assuming
68// init is out of the way, pedantically all permissions and selinux
69// security is put back in place:
70//
71// setenforce 0
72// rm /dev/socket/logd*
73// chmod 777 /dev/socket
74// # here is where you would attach the debugger or valgrind for example
75// runcon u:r:logd:s0 /system/bin/logd </dev/null >/dev/null 2>&1 &
76// sleep 1
77// chmod 755 /dev/socket
78// chown logd.logd /dev/socket/logd*
79// restorecon /dev/socket/logd*
80// setenforce 1
81//
82// If minimalism prevails, typical for debugging and security is not a concern:
83//
84// setenforce 0
85// chmod 777 /dev/socket
86// logd
87//
88
Mark Salyzyn0175b072014-02-26 09:50:16 -080089static int drop_privs() {
Mark Salyzyn882f8562013-12-26 15:13:36 -080090 struct sched_param param;
91 memset(&param, 0, sizeof(param));
92
Mark Salyzyn56ba4b52015-01-30 15:19:48 -080093 if (set_sched_policy(0, SP_BACKGROUND) < 0) {
94 return -1;
95 }
96
Mark Salyzyn882f8562013-12-26 15:13:36 -080097 if (sched_setscheduler((pid_t) 0, SCHED_BATCH, &param) < 0) {
98 return -1;
99 }
100
Riley Andrewsd98f4e82015-06-08 23:36:34 -0700101 if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) {
102 return -1;
103 }
104
Mark Salyzyn0175b072014-02-26 09:50:16 -0800105 if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
106 return -1;
107 }
108
Nick Kralevichc39ba5a2015-11-07 16:52:17 -0800109 gid_t groups[] = { AID_READPROC };
110
111 if (setgroups(sizeof(groups) / sizeof(groups[0]), groups) == -1) {
Jeff Vander Stoep3f62a022015-07-23 15:18:36 -0700112 return -1;
113 }
114
Mark Salyzyn0175b072014-02-26 09:50:16 -0800115 if (setgid(AID_LOGD) != 0) {
116 return -1;
117 }
118
119 if (setuid(AID_LOGD) != 0) {
120 return -1;
121 }
122
123 struct __user_cap_header_struct capheader;
124 struct __user_cap_data_struct capdata[2];
125 memset(&capheader, 0, sizeof(capheader));
126 memset(&capdata, 0, sizeof(capdata));
127 capheader.version = _LINUX_CAPABILITY_VERSION_3;
128 capheader.pid = 0;
129
130 capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
William Roberts29d238d2013-02-08 09:45:26 +0900131 capdata[CAP_TO_INDEX(CAP_AUDIT_CONTROL)].permitted |= CAP_TO_MASK(CAP_AUDIT_CONTROL);
132
133 capdata[0].effective = capdata[0].permitted;
134 capdata[1].effective = capdata[1].permitted;
Mark Salyzyn0175b072014-02-26 09:50:16 -0800135 capdata[0].inheritable = 0;
136 capdata[1].inheritable = 0;
137
138 if (capset(&capheader, &capdata[0]) < 0) {
139 return -1;
140 }
141
142 return 0;
143}
144
Mark Salyzyne0fa2912014-04-28 16:39:04 -0700145// Property helper
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800146static bool check_flag(const char *prop, const char *flag) {
147 const char *cp = strcasestr(prop, flag);
148 if (!cp) {
Mark Salyzyne0fa2912014-04-28 16:39:04 -0700149 return false;
150 }
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800151 // We only will document comma (,)
152 static const char sep[] = ",:;|+ \t\f";
153 if ((cp != prop) && !strchr(sep, cp[-1])) {
154 return false;
155 }
156 cp += strlen(flag);
157 return !*cp || !!strchr(sep, *cp);
158}
Mark Salyzyne0fa2912014-04-28 16:39:04 -0700159
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800160bool property_get_bool(const char *key, int flag) {
161 char def[PROPERTY_VALUE_MAX];
162 char property[PROPERTY_VALUE_MAX];
163 def[0] = '\0';
164 if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
165 char newkey[PROPERTY_KEY_MAX];
166 snprintf(newkey, sizeof(newkey), "ro.%s", key);
167 property_get(newkey, property, "");
Mark Salyzyn07522c62016-03-02 07:51:48 -0800168 // persist properties set by /data require inoculation with
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800169 // logd-reinit. They may be set in init.rc early and function, but
170 // otherwise are defunct unless reset. Do not rely on persist
171 // properties for startup-only keys unless you are willing to restart
172 // logd daemon (not advised).
173 snprintf(newkey, sizeof(newkey), "persist.%s", key);
174 property_get(newkey, def, property);
175 }
176
177 property_get(key, property, def);
178
179 if (check_flag(property, "true")) {
180 return true;
181 }
182 if (check_flag(property, "false")) {
183 return false;
184 }
185 if (check_flag(property, "eng")) {
186 flag |= BOOL_DEFAULT_FLAG_ENG;
187 }
188 // this is really a "not" flag
189 if (check_flag(property, "svelte")) {
190 flag |= BOOL_DEFAULT_FLAG_SVELTE;
191 }
192
193 // Sanity Check
194 if (flag & (BOOL_DEFAULT_FLAG_SVELTE | BOOL_DEFAULT_FLAG_ENG)) {
195 flag &= ~BOOL_DEFAULT_FLAG_TRUE_FALSE;
196 flag |= BOOL_DEFAULT_TRUE;
197 }
198
199 if ((flag & BOOL_DEFAULT_FLAG_SVELTE)
200 && property_get_bool("ro.config.low_ram",
201 BOOL_DEFAULT_FALSE)) {
202 return false;
203 }
204 if (flag & BOOL_DEFAULT_FLAG_ENG) {
205 property_get("ro.build.type", property, "");
206 if (!strcmp(property, "user")) {
207 return false;
208 }
209 }
210
211 return (flag & BOOL_DEFAULT_FLAG_TRUE_FALSE) != BOOL_DEFAULT_FALSE;
Mark Salyzyne0fa2912014-04-28 16:39:04 -0700212}
213
Mark Salyzynccbadc62015-03-12 12:25:35 -0700214// Remove the static, and use this variable
215// globally for debugging if necessary. eg:
216// write(fdDmesg, "I am here\n", 10);
217static int fdDmesg = -1;
218
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700219static sem_t uidName;
220static uid_t uid;
221static char *name;
222
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700223static sem_t reinit;
224static bool reinit_running = false;
225static LogBuffer *logBuf = NULL;
Mark Salyzyne0fa2912014-04-28 16:39:04 -0700226
William Robertsaeca97b2015-07-31 13:10:36 -0700227static bool package_list_parser_cb(pkg_info *info, void * /* userdata */) {
228
229 bool rc = true;
230 if (info->uid == uid) {
231 name = strdup(info->name);
232 // false to stop processing
233 rc = false;
234 }
235
236 packagelist_free(info);
237 return rc;
238}
239
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700240static void *reinit_thread_start(void * /*obj*/) {
241 prctl(PR_SET_NAME, "logd.daemon");
242 set_sched_policy(0, SP_BACKGROUND);
Riley Andrewsd98f4e82015-06-08 23:36:34 -0700243 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND);
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700244
Mark Salyzyn07522c62016-03-02 07:51:48 -0800245 // If we are AID_ROOT, we should drop to AID_SYSTEM, if we are anything
246 // else, we have even lesser privileges and accept our fate. Not worth
247 // checking for error returns setting this thread's privileges.
248 (void)setgid(AID_SYSTEM);
249 (void)setuid(AID_SYSTEM);
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700250
251 while (reinit_running && !sem_wait(&reinit) && reinit_running) {
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700252
253 // uidToName Privileged Worker
254 if (uid) {
255 name = NULL;
256
William Robertsaeca97b2015-07-31 13:10:36 -0700257 packagelist_parse(package_list_parser_cb, NULL);
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700258
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700259 uid = 0;
260 sem_post(&uidName);
261 continue;
262 }
263
Mark Salyzynccbadc62015-03-12 12:25:35 -0700264 if (fdDmesg >= 0) {
265 static const char reinit_message[] = { KMSG_PRIORITY(LOG_INFO),
266 'l', 'o', 'g', 'd', '.', 'd', 'a', 'e', 'm', 'o', 'n', ':',
267 ' ', 'r', 'e', 'i', 'n', 'i', 't', '\n' };
268 write(fdDmesg, reinit_message, sizeof(reinit_message));
269 }
270
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700271 // Anything that reads persist.<property>
272 if (logBuf) {
273 logBuf->init();
Mark Salyzyn932f7ac2015-08-28 08:02:59 -0700274 logBuf->initPrune(NULL);
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700275 }
276 }
277
278 return NULL;
279}
280
Mark Salyzyn95108f12015-04-20 07:26:27 -0700281static sem_t sem_name;
282
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700283char *android::uidToName(uid_t u) {
284 if (!u || !reinit_running) {
285 return NULL;
286 }
287
Mark Salyzyn95108f12015-04-20 07:26:27 -0700288 sem_wait(&sem_name);
289
290 // Not multi-thread safe, we use sem_name to protect
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700291 uid = u;
292
293 name = NULL;
294 sem_post(&reinit);
295 sem_wait(&uidName);
Mark Salyzyn95108f12015-04-20 07:26:27 -0700296 char *ret = name;
297
298 sem_post(&sem_name);
299
300 return ret;
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700301}
302
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700303// Serves as a global method to trigger reinitialization
304// and as a function that can be provided to signal().
305void reinit_signal_handler(int /*signal*/) {
306 sem_post(&reinit);
307}
308
Mark Salyzynff32f3c2015-04-13 14:24:45 -0700309// tagToName converts an events tag into a name
310const char *android::tagToName(uint32_t tag) {
311 static const EventTagMap *map;
312
313 if (!map) {
314 sem_wait(&sem_name);
315 if (!map) {
316 map = android_openEventTagMap(EVENT_TAG_MAP_FILE);
317 }
318 sem_post(&sem_name);
319 if (!map) {
320 return NULL;
321 }
322 }
323 return android_lookupEventTag(map, tag);
324}
325
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700326static void readDmesg(LogAudit *al, LogKlog *kl) {
327 if (!al && !kl) {
328 return;
329 }
330
Mark Salyzynea1a2412015-09-02 07:39:53 -0700331 int rc = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700332 if (rc <= 0) {
333 return;
334 }
335
Mark Salyzynea1a2412015-09-02 07:39:53 -0700336 size_t len = rc + 1024; // Margin for additional input race or trailing nul
337 std::unique_ptr<char []> buf(new char[len]);
338
339 rc = klogctl(KLOG_READ_ALL, buf.get(), len);
340 if (rc <= 0) {
341 return;
342 }
343
344 if ((size_t)rc < len) {
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700345 len = rc + 1;
346 }
Mark Salyzynea1a2412015-09-02 07:39:53 -0700347 buf[--len] = '\0';
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700348
Mark Salyzynb6bee332015-09-08 08:56:32 -0700349 if (kl && kl->isMonotonic()) {
Mark Salyzyn151beac2015-09-04 11:37:42 -0700350 kl->synchronize(buf.get(), len);
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700351 }
352
Mark Salyzynea1a2412015-09-02 07:39:53 -0700353 size_t sublen;
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700354 for (char *ptr = NULL, *tok = buf.get();
Mark Salyzynea1a2412015-09-02 07:39:53 -0700355 (rc >= 0) && ((tok = log_strntok_r(tok, &len, &ptr, &sublen)));
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700356 tok = NULL) {
357 if (al) {
Mark Salyzyn151beac2015-09-04 11:37:42 -0700358 rc = al->log(tok, sublen);
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700359 }
360 if (kl) {
Mark Salyzyn151beac2015-09-04 11:37:42 -0700361 rc = kl->log(tok, sublen);
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700362 }
363 }
364}
365
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700366// Foreground waits for exit of the main persistent threads
367// that are started here. The threads are created to manage
368// UNIX domain client sockets for writing, reading and
369// controlling the user space logger, and for any additional
370// logging plugins like auditd and restart control. Additional
371// transitory per-client threads are created for each reader.
372int main(int argc, char *argv[]) {
Mark Salyzyna1aacb72014-10-15 08:49:39 -0700373 int fdPmesg = -1;
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800374 bool klogd = property_get_bool("logd.kernel",
375 BOOL_DEFAULT_TRUE |
376 BOOL_DEFAULT_FLAG_PERSIST |
377 BOOL_DEFAULT_FLAG_ENG |
378 BOOL_DEFAULT_FLAG_SVELTE);
Mark Salyzyna1aacb72014-10-15 08:49:39 -0700379 if (klogd) {
380 fdPmesg = open("/proc/kmsg", O_RDONLY | O_NDELAY);
381 }
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700382 fdDmesg = open("/dev/kmsg", O_WRONLY);
383
384 // issue reinit command. KISS argument parsing.
385 if ((argc > 1) && argv[1] && !strcmp(argv[1], "--reinit")) {
386 int sock = TEMP_FAILURE_RETRY(
387 socket_local_client("logd",
388 ANDROID_SOCKET_NAMESPACE_RESERVED,
389 SOCK_STREAM));
390 if (sock < 0) {
391 return -errno;
392 }
393 static const char reinit[] = "reinit";
394 ssize_t ret = TEMP_FAILURE_RETRY(write(sock, reinit, sizeof(reinit)));
395 if (ret < 0) {
396 return -errno;
397 }
398 struct pollfd p;
399 memset(&p, 0, sizeof(p));
400 p.fd = sock;
401 p.events = POLLIN;
Mark Salyzynf011a332015-12-10 11:27:03 -0800402 ret = TEMP_FAILURE_RETRY(poll(&p, 1, 1000));
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700403 if (ret < 0) {
404 return -errno;
405 }
406 if ((ret == 0) || !(p.revents & POLLIN)) {
407 return -ETIME;
408 }
409 static const char success[] = "success";
410 char buffer[sizeof(success) - 1];
411 memset(buffer, 0, sizeof(buffer));
412 ret = TEMP_FAILURE_RETRY(read(sock, buffer, sizeof(buffer)));
413 if (ret < 0) {
414 return -errno;
415 }
416 return strncmp(buffer, success, sizeof(success) - 1) != 0;
417 }
418
419 // Reinit Thread
420 sem_init(&reinit, 0, 0);
Mark Salyzyn08739ba2015-03-16 08:26:05 -0700421 sem_init(&uidName, 0, 0);
Mark Salyzyn95108f12015-04-20 07:26:27 -0700422 sem_init(&sem_name, 0, 1);
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700423 pthread_attr_t attr;
424 if (!pthread_attr_init(&attr)) {
425 struct sched_param param;
426
427 memset(&param, 0, sizeof(param));
428 pthread_attr_setschedparam(&attr, &param);
429 pthread_attr_setschedpolicy(&attr, SCHED_BATCH);
430 if (!pthread_attr_setdetachstate(&attr,
431 PTHREAD_CREATE_DETACHED)) {
432 pthread_t thread;
433 reinit_running = true;
434 if (pthread_create(&thread, &attr, reinit_thread_start, NULL)) {
435 reinit_running = false;
436 }
437 }
438 pthread_attr_destroy(&attr);
Mark Salyzyne9bebd02014-04-03 09:55:26 -0700439 }
440
Mark Salyzyn0175b072014-02-26 09:50:16 -0800441 if (drop_privs() != 0) {
442 return -1;
443 }
444
445 // Serves the purpose of managing the last logs times read on a
446 // socket connection, and as a reader lock on a range of log
447 // entries.
448
449 LastLogTimes *times = new LastLogTimes();
450
451 // LogBuffer is the object which is responsible for holding all
452 // log entries.
453
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700454 logBuf = new LogBuffer(times);
455
456 signal(SIGHUP, reinit_signal_handler);
Mark Salyzyn0175b072014-02-26 09:50:16 -0800457
Mark Salyzyn9c66a582015-12-14 16:40:12 -0800458 if (property_get_bool("logd.statistics",
459 BOOL_DEFAULT_TRUE |
460 BOOL_DEFAULT_FLAG_PERSIST |
461 BOOL_DEFAULT_FLAG_ENG |
462 BOOL_DEFAULT_FLAG_SVELTE)) {
Mark Salyzyna1aacb72014-10-15 08:49:39 -0700463 logBuf->enableStatistics();
Mark Salyzynf5fc5092014-09-21 14:22:18 -0700464 }
Mark Salyzyne457b742014-02-19 17:18:31 -0800465
Mark Salyzyn0175b072014-02-26 09:50:16 -0800466 // LogReader listens on /dev/socket/logdr. When a client
467 // connects, log entries in the LogBuffer are written to the client.
468
469 LogReader *reader = new LogReader(logBuf);
470 if (reader->startListener()) {
471 exit(1);
472 }
473
474 // LogListener listens on /dev/socket/logdw for client
475 // initiated log messages. New log entries are added to LogBuffer
476 // and LogReader is notified to send updates to connected clients.
477
478 LogListener *swl = new LogListener(logBuf, reader);
Mark Salyzyn581edc12013-11-20 13:38:52 -0800479 // Backlog and /proc/sys/net/unix/max_dgram_qlen set to large value
Mark Salyzyn39944c82015-09-08 11:24:07 -0700480 if (swl->startListener(600)) {
Mark Salyzyn0175b072014-02-26 09:50:16 -0800481 exit(1);
482 }
483
484 // Command listener listens on /dev/socket/logd for incoming logd
485 // administrative commands.
486
487 CommandListener *cl = new CommandListener(logBuf, reader, swl);
488 if (cl->startListener()) {
489 exit(1);
490 }
491
William Roberts29d238d2013-02-08 09:45:26 +0900492 // LogAudit listens on NETLINK_AUDIT socket for selinux
493 // initiated log messages. New log entries are added to LogBuffer
494 // and LogReader is notified to send updates to connected clients.
495
Sami Tolvanena742d102016-06-14 18:04:43 +0000496 bool auditd = property_get_bool("logd.auditd",
497 BOOL_DEFAULT_TRUE |
498 BOOL_DEFAULT_FLAG_PERSIST);
499 LogAudit *al = NULL;
500 if (auditd) {
501 al = new LogAudit(logBuf, reader,
502 property_get_bool("logd.auditd.dmesg",
503 BOOL_DEFAULT_TRUE |
504 BOOL_DEFAULT_FLAG_PERSIST)
505 ? fdDmesg
506 : -1);
507 }
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700508
Mark Salyzyna1aacb72014-10-15 08:49:39 -0700509 LogKlog *kl = NULL;
510 if (klogd) {
Sami Tolvanena742d102016-06-14 18:04:43 +0000511 kl = new LogKlog(logBuf, reader, fdDmesg, fdPmesg, al != NULL);
Mark Salyzyna1aacb72014-10-15 08:49:39 -0700512 }
Mark Salyzyneb06de72014-10-13 09:59:37 -0700513
Sami Tolvanena742d102016-06-14 18:04:43 +0000514 readDmesg(al, kl);
Mark Salyzyneb06de72014-10-13 09:59:37 -0700515
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700516 // failure is an option ... messages are in dmesg (required by standard)
Mark Salyzyneb06de72014-10-13 09:59:37 -0700517
Mark Salyzynd5600fd2015-06-12 14:59:42 -0700518 if (kl && kl->startListener()) {
519 delete kl;
520 }
Mark Salyzyneb06de72014-10-13 09:59:37 -0700521
Sami Tolvanena742d102016-06-14 18:04:43 +0000522 if (al && al->startListener()) {
523 delete al;
William Roberts29d238d2013-02-08 09:45:26 +0900524 }
525
Mark Salyzyn11e55cb2015-03-10 16:45:17 -0700526 TEMP_FAILURE_RETRY(pause());
527
Mark Salyzyn0175b072014-02-26 09:50:16 -0800528 exit(0);
529}