Merge "logd: create private/android_logger.h"
This commit is contained in:
commit
4730328da7
2 changed files with 42 additions and 16 deletions
34
include/private/android_logger.h
Normal file
34
include/private/android_logger.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This file is used to define the internal protocol for the Android Logger */
|
||||||
|
|
||||||
|
#ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
|
||||||
|
#define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <log/log.h>
|
||||||
|
#include <log/log_read.h>
|
||||||
|
|
||||||
|
/* Header Structure to logd */
|
||||||
|
typedef struct __attribute__((__packed__)) {
|
||||||
|
typeof_log_id_t id;
|
||||||
|
uint16_t tid;
|
||||||
|
log_time realtime;
|
||||||
|
} android_log_header_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <log/logger.h>
|
#include <log/logger.h>
|
||||||
|
#include <private/android_logger.h>
|
||||||
|
|
||||||
#include "LogListener.h"
|
#include "LogListener.h"
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
|
||||||
int socket = cli->getSocket();
|
int socket = cli->getSocket();
|
||||||
|
|
||||||
ssize_t n = recvmsg(socket, &hdr, 0);
|
ssize_t n = recvmsg(socket, &hdr, 0);
|
||||||
if (n <= (ssize_t)(sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time))) {
|
if (n <= (ssize_t)(sizeof(android_log_header_t))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,28 +82,19 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First log element is always log_id.
|
android_log_header_t *header = reinterpret_cast<android_log_header_t *>(buffer);
|
||||||
log_id_t log_id = (log_id_t) *((typeof_log_id_t *) buffer);
|
if (/* header->id < LOG_ID_MIN || */ header->id >= LOG_ID_MAX) {
|
||||||
if (log_id < 0 || log_id >= LOG_ID_MAX) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char *msg = ((char *)buffer) + sizeof_log_id_t;
|
|
||||||
n -= sizeof_log_id_t;
|
|
||||||
|
|
||||||
// second element is the thread id of the caller
|
char *msg = ((char *)buffer) + sizeof(android_log_header_t);
|
||||||
pid_t tid = (pid_t) *((uint16_t *) msg);
|
n -= sizeof(android_log_header_t);
|
||||||
msg += sizeof(uint16_t);
|
|
||||||
n -= sizeof(uint16_t);
|
|
||||||
|
|
||||||
// third element is the realtime at point of caller
|
|
||||||
log_time realtime(msg);
|
|
||||||
msg += sizeof(log_time);
|
|
||||||
n -= sizeof(log_time);
|
|
||||||
|
|
||||||
// NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
|
// NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
|
||||||
// truncated message to the logs.
|
// truncated message to the logs.
|
||||||
|
|
||||||
logbuf->log(log_id, realtime, cred->uid, cred->pid, tid, msg,
|
logbuf->log((log_id_t)header->id, header->realtime,
|
||||||
|
cred->uid, cred->pid, header->tid, msg,
|
||||||
((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
|
((size_t) n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX);
|
||||||
reader->notifyNewLog();
|
reader->notifyNewLog();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue