blob: febf775f2229e5429f24412a01b561b5abbcd778 [file] [log] [blame]
Mark Salyzynae4d9282014-10-15 08:49:39 -07001/*
2 * Copyright (C) 2014 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 <ctype.h>
18#include <errno.h>
19#include <inttypes.h>
20#include <limits.h>
21#include <stdarg.h>
22#include <stdlib.h>
23#include <sys/prctl.h>
24#include <sys/uio.h>
25#include <syslog.h>
26
27#include <log/logger.h>
28
29#include "LogKlog.h"
30
31#define KMSG_PRIORITY(PRI) \
32 '<', \
33 '0' + (LOG_SYSLOG | (PRI)) / 10, \
34 '0' + (LOG_SYSLOG | (PRI)) % 10, \
35 '>'
36
37static const char priority_message[] = { KMSG_PRIORITY(LOG_INFO), '\0' };
38
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070039// Parsing is hard
40
41// called if we see a '<', s is the next character, returns pointer after '>'
42static char *is_prio(char *s) {
43 if (!isdigit(*s++)) {
44 return NULL;
45 }
Mark Salyzyn618d0de2015-07-13 10:19:34 -070046 static const size_t max_prio_len = 4;
47 size_t len = 0;
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070048 char c;
Mark Salyzyn618d0de2015-07-13 10:19:34 -070049 while (((c = *s++)) && (++len <= max_prio_len)) {
Mark Salyzynee49c6a2015-06-12 14:59:42 -070050 if (!isdigit(c)) {
Mark Salyzyn46d159d2015-08-26 09:30:00 -070051 return ((c == '>') && (*s == '[')) ? s : NULL;
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070052 }
53 }
54 return NULL;
55}
56
57// called if we see a '[', s is the next character, returns pointer after ']'
58static char *is_timestamp(char *s) {
59 while (*s == ' ') {
60 ++s;
61 }
62 if (!isdigit(*s++)) {
63 return NULL;
64 }
65 bool first_period = true;
66 char c;
67 while ((c = *s++)) {
68 if ((c == '.') && first_period) {
69 first_period = false;
Mark Salyzynee49c6a2015-06-12 14:59:42 -070070 } else if (!isdigit(c)) {
71 return ((c == ']') && !first_period && (*s == ' ')) ? s : NULL;
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070072 }
73 }
74 return NULL;
75}
76
77// Like strtok_r with "\r\n" except that we look for log signatures (regex)
Mark Salyzyn618d0de2015-07-13 10:19:34 -070078// \(\(<[0-9]\{1,4\}>\)\([[] *[0-9]+[.][0-9]+[]] \)\{0,1\}\|[[] *[0-9]+[.][0-9]+[]] \)
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070079// and split if we see a second one without a newline.
80
81#define SIGNATURE_MASK 0xF0
82// <digit> following ('0' to '9' masked with ~SIGNATURE_MASK) added to signature
83#define LESS_THAN_SIG SIGNATURE_MASK
84#define OPEN_BRACKET_SIG ((SIGNATURE_MASK << 1) & SIGNATURE_MASK)
85// space is one more than <digit> of 9
Mark Salyzyn3e21de22015-06-08 14:51:30 -070086#define OPEN_BRACKET_SPACE ((char)(OPEN_BRACKET_SIG | 10))
Mark Salyzyn2c3b3002015-05-22 15:23:44 -070087
88char *log_strtok_r(char *s, char **last) {
89 if (!s) {
90 if (!(s = *last)) {
91 return NULL;
92 }
93 // fixup for log signature split <,
94 // LESS_THAN_SIG + <digit>
95 if ((*s & SIGNATURE_MASK) == LESS_THAN_SIG) {
96 *s = (*s & ~SIGNATURE_MASK) + '0';
97 *--s = '<';
98 }
99 // fixup for log signature split [,
100 // OPEN_BRACKET_SPACE is space, OPEN_BRACKET_SIG + <digit>
101 if ((*s & SIGNATURE_MASK) == OPEN_BRACKET_SIG) {
102 if (*s == OPEN_BRACKET_SPACE) {
103 *s = ' ';
104 } else {
105 *s = (*s & ~SIGNATURE_MASK) + '0';
106 }
107 *--s = '[';
108 }
109 }
110
111 s += strspn(s, "\r\n");
112
113 if (!*s) { // no non-delimiter characters
114 *last = NULL;
115 return NULL;
116 }
117 char *peek, *tok = s;
118
119 for (;;) {
120 char c = *s++;
121 switch (c) {
122 case '\0':
123 *last = NULL;
124 return tok;
125
126 case '\r':
127 case '\n':
128 s[-1] = '\0';
129 *last = s;
130 return tok;
131
132 case '<':
133 peek = is_prio(s);
134 if (!peek) {
135 break;
136 }
137 if (s != (tok + 1)) { // not first?
138 s[-1] = '\0';
139 *s &= ~SIGNATURE_MASK;
140 *s |= LESS_THAN_SIG; // signature for '<'
141 *last = s;
142 return tok;
143 }
144 s = peek;
145 if ((*s == '[') && ((peek = is_timestamp(s + 1)))) {
146 s = peek;
147 }
148 break;
149
150 case '[':
151 peek = is_timestamp(s);
152 if (!peek) {
153 break;
154 }
155 if (s != (tok + 1)) { // not first?
156 s[-1] = '\0';
157 if (*s == ' ') {
158 *s = OPEN_BRACKET_SPACE;
159 } else {
160 *s &= ~SIGNATURE_MASK;
161 *s |= OPEN_BRACKET_SIG; // signature for '['
162 }
163 *last = s;
164 return tok;
165 }
166 s = peek;
167 break;
168 }
169 }
Mark Salyzyn618d0de2015-07-13 10:19:34 -0700170 // NOTREACHED
Mark Salyzyn2c3b3002015-05-22 15:23:44 -0700171}
172
Mark Salyzynae4d9282014-10-15 08:49:39 -0700173log_time LogKlog::correction = log_time(CLOCK_REALTIME) - log_time(CLOCK_MONOTONIC);
174
Mark Salyzyn77187782015-05-12 15:21:31 -0700175LogKlog::LogKlog(LogBuffer *buf, LogReader *reader, int fdWrite, int fdRead, bool auditd) :
176 SocketListener(fdRead, false),
177 logbuf(buf),
178 reader(reader),
179 signature(CLOCK_MONOTONIC),
Mark Salyzyn77187782015-05-12 15:21:31 -0700180 initialized(false),
181 enableLogging(true),
182 auditd(auditd) {
Mark Salyzynae4d9282014-10-15 08:49:39 -0700183 static const char klogd_message[] = "%slogd.klogd: %" PRIu64 "\n";
184 char buffer[sizeof(priority_message) + sizeof(klogd_message) + 20 - 4];
185 snprintf(buffer, sizeof(buffer), klogd_message, priority_message,
186 signature.nsec());
187 write(fdWrite, buffer, strlen(buffer));
188}
189
190bool LogKlog::onDataAvailable(SocketClient *cli) {
191 if (!initialized) {
192 prctl(PR_SET_NAME, "logd.klogd");
193 initialized = true;
194 enableLogging = false;
195 }
196
197 char buffer[LOGGER_ENTRY_MAX_PAYLOAD];
198 size_t len = 0;
199
200 for(;;) {
201 ssize_t retval = 0;
202 if ((sizeof(buffer) - 1 - len) > 0) {
203 retval = read(cli->getSocket(), buffer + len, sizeof(buffer) - 1 - len);
204 }
205 if ((retval == 0) && (len == 0)) {
206 break;
207 }
208 if (retval < 0) {
209 return false;
210 }
211 len += retval;
212 bool full = len == (sizeof(buffer) - 1);
213 char *ep = buffer + len;
214 *ep = '\0';
215 len = 0;
Mark Salyzyn2c3b3002015-05-22 15:23:44 -0700216 for(char *ptr = NULL, *tok = buffer;
217 ((tok = log_strtok_r(tok, &ptr)));
Mark Salyzynae4d9282014-10-15 08:49:39 -0700218 tok = NULL) {
219 if (((tok + strlen(tok)) == ep) && (retval != 0) && full) {
220 len = strlen(tok);
221 memmove(buffer, tok, len);
222 break;
223 }
224 if (*tok) {
225 log(tok);
226 }
227 }
228 }
229
230 return true;
231}
232
233
234void LogKlog::calculateCorrection(const log_time &monotonic,
235 const char *real_string) {
236 log_time real;
237 if (!real.strptime(real_string, "%Y-%m-%d %H:%M:%S.%09q UTC")) {
238 return;
239 }
240 // kernel report UTC, log_time::strptime is localtime from calendar.
241 // Bionic and liblog strptime does not support %z or %Z to pick up
242 // timezone so we are calculating our own correction.
243 time_t now = real.tv_sec;
244 struct tm tm;
245 memset(&tm, 0, sizeof(tm));
246 tm.tm_isdst = -1;
247 localtime_r(&now, &tm);
248 real.tv_sec += tm.tm_gmtoff;
249 correction = real - monotonic;
250}
251
252void LogKlog::sniffTime(log_time &now, const char **buf, bool reverse) {
253 const char *cp;
254 if ((cp = now.strptime(*buf, "[ %s.%q]"))) {
255 static const char suspend[] = "PM: suspend entry ";
256 static const char resume[] = "PM: suspend exit ";
Mark Salyzynacb1ddf2015-07-23 09:22:50 -0700257 static const char healthd[] = "healthd: battery ";
Mark Salyzynae4d9282014-10-15 08:49:39 -0700258 static const char suspended[] = "Suspended for ";
259
260 if (isspace(*cp)) {
261 ++cp;
262 }
263 if (!strncmp(cp, suspend, sizeof(suspend) - 1)) {
264 calculateCorrection(now, cp + sizeof(suspend) - 1);
265 } else if (!strncmp(cp, resume, sizeof(resume) - 1)) {
266 calculateCorrection(now, cp + sizeof(resume) - 1);
Mark Salyzynacb1ddf2015-07-23 09:22:50 -0700267 } else if (!strncmp(cp, healthd, sizeof(healthd) - 1)) {
268 // look for " 2???-??-?? ??:??:??.????????? ???"
269 const char *tp;
270 for (tp = cp + sizeof(healthd) - 1; *tp && (*tp != '\n'); ++tp) {
271 if ((tp[0] == ' ') && (tp[1] == '2') && (tp[5] == '-')) {
272 calculateCorrection(now, tp + 1);
273 break;
274 }
275 }
Mark Salyzynae4d9282014-10-15 08:49:39 -0700276 } else if (!strncmp(cp, suspended, sizeof(suspended) - 1)) {
277 log_time real;
278 char *endp;
279 real.tv_sec = strtol(cp + sizeof(suspended) - 1, &endp, 10);
280 if (*endp == '.') {
281 real.tv_nsec = strtol(endp + 1, &endp, 10) * 1000000L;
282 if (reverse) {
283 correction -= real;
284 } else {
285 correction += real;
286 }
287 }
288 }
289
290 convertMonotonicToReal(now);
291 *buf = cp;
292 } else {
293 now = log_time(CLOCK_REALTIME);
294 }
295}
296
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700297pid_t LogKlog::sniffPid(const char *cp) {
298 while (*cp) {
299 // Mediatek kernels with modified printk
300 if (*cp == '[') {
301 int pid = 0;
302 char dummy;
303 if (sscanf(cp, "[%d:%*[a-z_./0-9:A-Z]]%c", &pid, &dummy) == 2) {
304 return pid;
305 }
306 break; // Only the first one
307 }
308 ++cp;
309 }
310 return 0;
311}
312
Mark Salyzynae4d9282014-10-15 08:49:39 -0700313// Passed the entire SYSLOG_ACTION_READ_ALL buffer and interpret a
314// compensated start time.
315void LogKlog::synchronize(const char *buf) {
316 const char *cp = strstr(buf, "] PM: suspend e");
317 if (!cp) {
318 return;
319 }
320
321 do {
322 --cp;
323 } while ((cp > buf) && (isdigit(*cp) || isspace(*cp) || (*cp == '.')));
324
325 log_time now;
326 sniffTime(now, &cp, true);
327
328 char *suspended = strstr(buf, "] Suspended for ");
329 if (!suspended || (suspended > cp)) {
330 return;
331 }
332 cp = suspended;
333
334 do {
335 --cp;
336 } while ((cp > buf) && (isdigit(*cp) || isspace(*cp) || (*cp == '.')));
337
338 sniffTime(now, &cp, true);
339}
340
341// kernel log prefix, convert to a kernel log priority number
342static int parseKernelPrio(const char **buf) {
343 int pri = LOG_USER | LOG_INFO;
344 const char *cp = *buf;
345 if (*cp == '<') {
346 pri = 0;
347 while(isdigit(*++cp)) {
348 pri = (pri * 10) + *cp - '0';
349 }
350 if (*cp == '>') {
351 ++cp;
352 } else {
353 cp = *buf;
354 pri = LOG_USER | LOG_INFO;
355 }
356 *buf = cp;
357 }
358 return pri;
359}
360
361// Convert kernel log priority number into an Android Logger priority number
362static int convertKernelPrioToAndroidPrio(int pri) {
363 switch(pri & LOG_PRIMASK) {
364 case LOG_EMERG:
365 // FALLTHRU
366 case LOG_ALERT:
367 // FALLTHRU
368 case LOG_CRIT:
369 return ANDROID_LOG_FATAL;
370
371 case LOG_ERR:
372 return ANDROID_LOG_ERROR;
373
374 case LOG_WARNING:
375 return ANDROID_LOG_WARN;
376
377 default:
378 // FALLTHRU
379 case LOG_NOTICE:
380 // FALLTHRU
381 case LOG_INFO:
382 break;
383
384 case LOG_DEBUG:
385 return ANDROID_LOG_DEBUG;
386 }
387
388 return ANDROID_LOG_INFO;
389}
390
391//
392// log a message into the kernel log buffer
393//
394// Filter rules to parse <PRI> <TIME> <tag> and <message> in order for
395// them to appear correct in the logcat output:
396//
397// LOG_KERN (0):
398// <PRI>[<TIME>] <tag> ":" <message>
399// <PRI>[<TIME>] <tag> <tag> ":" <message>
400// <PRI>[<TIME>] <tag> <tag>_work ":" <message>
401// <PRI>[<TIME>] <tag> '<tag>.<num>' ":" <message>
402// <PRI>[<TIME>] <tag> '<tag><num>' ":" <message>
403// <PRI>[<TIME>] <tag>_host '<tag>.<num>' ":" <message>
404// (unimplemented) <PRI>[<TIME>] <tag> '<num>.<tag>' ":" <message>
405// <PRI>[<TIME>] "[INFO]"<tag> : <message>
406// <PRI>[<TIME>] "------------[ cut here ]------------" (?)
407// <PRI>[<TIME>] "---[ end trace 3225a3070ca3e4ac ]---" (?)
408// LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_SYSLOG, LOG_LPR, LOG_NEWS
409// LOG_UUCP, LOG_CRON, LOG_AUTHPRIV, LOG_FTP:
410// <PRI+TAG>[<TIME>] (see sys/syslog.h)
411// Observe:
412// Minimum tag length = 3 NB: drops things like r5:c00bbadf, but allow PM:
413// Maximum tag words = 2
414// Maximum tag length = 16 NB: we are thinking of how ugly logcat can get.
415// Not a Tag if there is no message content.
416// leading additional spaces means no tag, inherit last tag.
417// Not a Tag if <tag>: is "ERROR:", "WARNING:", "INFO:" or "CPU:"
418// Drop:
419// empty messages
420// messages with ' audit(' in them if auditd is running
421// logd.klogd:
422// return -1 if message logd.klogd: <signature>
423//
424int LogKlog::log(const char *buf) {
425 if (auditd && strstr(buf, " audit(")) {
426 return 0;
427 }
428
429 int pri = parseKernelPrio(&buf);
430
431 log_time now;
432 sniffTime(now, &buf, false);
433
434 // sniff for start marker
435 const char klogd_message[] = "logd.klogd: ";
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700436 const char *start = strstr(buf, klogd_message);
437 if (start) {
438 uint64_t sig = strtoll(start + sizeof(klogd_message) - 1, NULL, 10);
Mark Salyzynae4d9282014-10-15 08:49:39 -0700439 if (sig == signature.nsec()) {
440 if (initialized) {
441 enableLogging = true;
442 } else {
443 enableLogging = false;
444 }
445 return -1;
446 }
447 return 0;
448 }
449
450 if (!enableLogging) {
451 return 0;
452 }
453
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700454 // Parse pid, tid and uid
455 const pid_t pid = sniffPid(buf);
456 const pid_t tid = pid;
457 const uid_t uid = pid ? logbuf->pidToUid(pid) : 0;
Mark Salyzynae4d9282014-10-15 08:49:39 -0700458
459 // Parse (rules at top) to pull out a tag from the incoming kernel message.
460 // Some may view the following as an ugly heuristic, the desire is to
461 // beautify the kernel logs into an Android Logging format; the goal is
462 // admirable but costly.
463 while (isspace(*buf)) {
464 ++buf;
465 }
466 if (!*buf) {
467 return 0;
468 }
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700469 start = buf;
Mark Salyzynae4d9282014-10-15 08:49:39 -0700470 const char *tag = "";
471 const char *etag = tag;
472 if (!isspace(*buf)) {
473 const char *bt, *et, *cp;
474
475 bt = buf;
476 if (!strncmp(buf, "[INFO]", 6)) {
477 // <PRI>[<TIME>] "[INFO]"<tag> ":" message
478 bt = buf + 6;
479 }
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700480 for(et = bt; *et && (*et != ':') && !isspace(*et); ++et) {
481 // skip ':' within [ ... ]
482 if (*et == '[') {
483 while (*et && *et != ']') {
484 ++et;
485 }
486 }
487 }
Mark Salyzynae4d9282014-10-15 08:49:39 -0700488 for(cp = et; isspace(*cp); ++cp);
489 size_t size;
490
491 if (*cp == ':') {
492 // One Word
493 tag = bt;
494 etag = et;
495 buf = cp + 1;
496 } else {
497 size = et - bt;
498 if (strncmp(bt, cp, size)) {
499 // <PRI>[<TIME>] <tag>_host '<tag>.<num>' : message
500 if (!strncmp(bt + size - 5, "_host", 5)
Mark Salyzyn618d0de2015-07-13 10:19:34 -0700501 && !strncmp(bt, cp, size - 5)) {
Mark Salyzynae4d9282014-10-15 08:49:39 -0700502 const char *b = cp;
503 cp += size - 5;
504 if (*cp == '.') {
505 while (!isspace(*++cp) && (*cp != ':'));
506 const char *e;
507 for(e = cp; isspace(*cp); ++cp);
508 if (*cp == ':') {
509 tag = b;
510 etag = e;
511 buf = cp + 1;
512 }
513 }
514 } else {
515 while (!isspace(*++cp) && (*cp != ':'));
516 const char *e;
517 for(e = cp; isspace(*cp); ++cp);
518 // Two words
519 if (*cp == ':') {
520 tag = bt;
521 etag = e;
522 buf = cp + 1;
523 }
524 }
525 } else if (isspace(cp[size])) {
Mark Salyzynae4d9282014-10-15 08:49:39 -0700526 cp += size;
527 while (isspace(*++cp));
528 // <PRI>[<TIME>] <tag> <tag> : message
529 if (*cp == ':') {
530 tag = bt;
531 etag = et;
532 buf = cp + 1;
533 }
534 } else if (cp[size] == ':') {
535 // <PRI>[<TIME>] <tag> <tag> : message
536 tag = bt;
537 etag = et;
538 buf = cp + size + 1;
539 } else if ((cp[size] == '.') || isdigit(cp[size])) {
540 // <PRI>[<TIME>] <tag> '<tag>.<num>' : message
541 // <PRI>[<TIME>] <tag> '<tag><num>' : message
542 const char *b = cp;
543 cp += size;
544 while (!isspace(*++cp) && (*cp != ':'));
545 const char *e = cp;
546 while (isspace(*cp)) {
547 ++cp;
548 }
549 if (*cp == ':') {
550 tag = b;
551 etag = e;
552 buf = cp + 1;
553 }
554 } else {
555 while (!isspace(*++cp) && (*cp != ':'));
556 const char *e = cp;
557 while (isspace(*cp)) {
558 ++cp;
559 }
560 // Two words
561 if (*cp == ':') {
562 tag = bt;
563 etag = e;
564 buf = cp + 1;
565 }
566 }
567 }
568 size = etag - tag;
569 if ((size <= 1)
Mark Salyzyn618d0de2015-07-13 10:19:34 -0700570 // register names like x9
571 || ((size == 2) && (isdigit(tag[0]) || isdigit(tag[1])))
572 // register names like x18 but not driver names like en0
573 || ((size == 3) && (isdigit(tag[1]) && isdigit(tag[2])))
574 // blacklist
575 || ((size == 3) && !strncmp(tag, "CPU", 3))
576 || ((size == 7) && !strncmp(tag, "WARNING", 7))
577 || ((size == 5) && !strncmp(tag, "ERROR", 5))
578 || ((size == 4) && !strncmp(tag, "INFO", 4))) {
Mark Salyzynae4d9282014-10-15 08:49:39 -0700579 buf = start;
580 etag = tag = "";
581 }
582 }
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700583 // Suppress additional stutter in tag:
584 // eg: [143:healthd]healthd -> [143:healthd]
585 size_t taglen = etag - tag;
586 // Mediatek-special printk induced stutter
587 char *np = strrchr(tag, ']');
588 if (np && (++np < etag)) {
589 size_t s = etag - np;
590 if (((s + s) < taglen) && !strncmp(np, np - 1 - s, s)) {
591 taglen = np - tag;
592 }
593 }
Mark Salyzynee49c6a2015-06-12 14:59:42 -0700594 // skip leading space
Mark Salyzynae4d9282014-10-15 08:49:39 -0700595 while (isspace(*buf)) {
596 ++buf;
597 }
Mark Salyzynee49c6a2015-06-12 14:59:42 -0700598 // truncate trailing space
599 size_t b = strlen(buf);
600 while (b && isspace(buf[b-1])) {
601 --b;
602 }
603 // trick ... allow tag with empty content to be logged. log() drops empty
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700604 if (!b && taglen) {
Mark Salyzynee49c6a2015-06-12 14:59:42 -0700605 buf = " ";
606 b = 1;
607 }
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700608 size_t n = 1 + taglen + 1 + b + 1;
Mark Salyzynae4d9282014-10-15 08:49:39 -0700609
610 // Allocate a buffer to hold the interpreted log message
611 int rc = n;
612 char *newstr = reinterpret_cast<char *>(malloc(n));
613 if (!newstr) {
614 rc = -ENOMEM;
615 return rc;
616 }
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700617 np = newstr;
Mark Salyzynae4d9282014-10-15 08:49:39 -0700618
619 // Convert priority into single-byte Android logger priority
620 *np = convertKernelPrioToAndroidPrio(pri);
621 ++np;
622
623 // Copy parsed tag following priority
Mark Salyzyn46d159d2015-08-26 09:30:00 -0700624 strncpy(np, tag, taglen);
625 np += taglen;
Mark Salyzynae4d9282014-10-15 08:49:39 -0700626 *np = '\0';
627 ++np;
628
629 // Copy main message to the remainder
Mark Salyzynee49c6a2015-06-12 14:59:42 -0700630 strncpy(np, buf, b);
631 np[b] = '\0';
Mark Salyzynae4d9282014-10-15 08:49:39 -0700632
633 // Log message
634 rc = logbuf->log(LOG_ID_KERNEL, now, uid, pid, tid, newstr,
635 (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
636 free(newstr);
637
638 // notify readers
639 if (!rc) {
640 reader->notifyNewLog();
641 }
642
643 return rc;
644}