/* aplogd_io_read_data()
 *
 * Description: This function reads data from an input file descriptor and adds
 * it to the circular RAM buffer.
 *
 * @poll_num: (int) Element of the poll struct array to read from
 *
 * Return: None
 *
 * Notes: None
 */
static void aplogd_io_read_data(int poll_num)
{
	int my_fd = 0;
	int len=0;
	int ret=0;
	int ReadableLogSize;
	my_fd   = aplogd_io_fd[poll_num].fd;
	VPRINT("aplogd_io_read_data poll_num=%d.\n",poll_num);
	if(poll_num < APLOGD_INPUT_KERNEL_POLL_INDEX){
		int ret=0;
		unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1] __attribute__((aligned(4)));
		struct logger_entry *entry = (struct logger_entry *) buf;
		AndroidLogEntry log_entry;
		char binaryMsgBuf[1024];
		ReadableLogSize=ioctl(my_fd, LOGGER_GET_LOG_LEN);
		while(ReadableLogSize>0){
			ret = read (my_fd, entry, LOGGER_ENTRY_MAX_LEN);
			if (ret < 0) {
				if (errno == EINTR)
					continue;
				if (errno == EAGAIN)
					break;
				perror("logcat read");
				exit(EXIT_FAILURE);
			}
			else if (!ret) {
				EPRINT("read: Unexpected EOF!\n");
				exit(EXIT_FAILURE);
			}
			/* NOTE: driver guarantees we read exactly one full entry */
			if(entry->len >=LOGGER_ENTRY_MAX_LEN)
				entry->len=LOGGER_ENTRY_MAX_LEN-1;
			entry->msg[entry->len] = '\0';
			if(APLOGD_INPUT_EVENTS_POLL_INDEX == poll_num )
				errno = android_log_processBinaryLogBuffer(entry, &log_entry, g_eventTagMap,binaryMsgBuf, sizeof(binaryMsgBuf));
			else
				errno = android_log_processLogBuffer(entry, &log_entry);
			if(errno <0) {
				EPRINT("Error in android_log_processLogBuffer.\n");
				break;
				}
			ret=LogfilterAndBuffering(g_logformat, &log_entry, poll_num);
			if(ret<0){
				EPRINT("Error in LogfilterAndBuffering.\n");
				break;
			}else{
				unwritten_bytes+=ret;
				if(unwritten_bytes>= aplogd_output_buffering){
					aplogd_rambuf_outputall();
					unwritten_bytes=0;
					aplogd_poll_timeout=-1;
				}else{
					aplogd_poll_timeout=60000;
				}
			}
			ReadableLogSize-=ret;
		}//while loop
	}else if (APLOGD_INPUT_KERNEL_POLL_INDEX == poll_num){
Esempio n. 2
0
static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        static bool hasOpenedEventTagMap = false;
        static EventTagMap *eventTagMap = NULL;

        if (!eventTagMap && !hasOpenedEventTagMap) {
            eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
            hasOpenedEventTagMap = true;
        }
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    if (err < 0) {
        goto error;
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        bool match = regexOk(entry);

        g_printCount += match;
        if (match || g_printItAnyways) {
            bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

            if (bytesWritten < 0) {
                logcat_panic(false, "output error");
            }
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
Esempio n. 3
0
static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 g_eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    if (err < 0) {
        goto error;
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        if (false && g_devCount > 1) {
            binaryMsgBuf[0] = dev->label;
            binaryMsgBuf[1] = ' ';
            bytesWritten = write(g_outFD, binaryMsgBuf, 2);
            if (bytesWritten < 0) {
                perror("output error");
                exit(-1);
            }
        }

        bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

        if (bytesWritten < 0) {
            perror("output error");
            exit(-1);
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
Esempio n. 4
0
static void processBuffer(struct logger_entry *buf)
{
    int bytesWritten;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (g_isBinary) {
        err = android_log_processBinaryLogBuffer(buf, &entry, g_eventTagMap,
                binaryMsgBuf, sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(buf, &entry);
    }
    if (err < 0)
        goto error;

    bytesWritten = android_log_filterAndPrintLogLine(
                        g_logformat, g_outFD, &entry);

    if (bytesWritten < 0) {
        perror("output error");
        exit(-1);
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0 
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}