static void setupOutput() { if (g_outputFileName == NULL) { g_outFD = STDOUT_FILENO; } else { if (set_sched_policy(0, SP_BACKGROUND) < 0) { fprintf(stderr, "failed to set background scheduling policy\n"); } struct sched_param param; memset(¶m, 0, sizeof(param)); if (sched_setscheduler((pid_t) 0, SCHED_BATCH, ¶m) < 0) { fprintf(stderr, "failed to set to batch scheduler\n"); } if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_BACKGROUND) < 0) { fprintf(stderr, "failed set to priority\n"); } g_outFD = openLogFile (g_outputFileName); if (g_outFD < 0) { logcat_panic(false, "couldn't open output file"); } struct stat statbuf; if (fstat(g_outFD, &statbuf) == -1) { close(g_outFD); logcat_panic(false, "couldn't get output file stat\n"); } if ((size_t) statbuf.st_size > SIZE_MAX || statbuf.st_size < 0) { close(g_outFD); logcat_panic(false, "invalid output file stat\n"); } g_outByteCount = statbuf.st_size; } }
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; }
static void maybePrintStart(log_device_t* dev, bool printDividers) { if (!dev->printed || printDividers) { if (g_devCount > 1 && !g_printBinary) { char buf[1024]; snprintf(buf, sizeof(buf), "--------- %s %s\n", dev->printed ? "switch to" : "beginning of", dev->device); if (write(g_outFD, buf, strlen(buf)) < 0) { logcat_panic(false, "output error"); } } dev->printed = true; } }