summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'liblog/fake_log_device.c')
-rw-r--r--liblog/fake_log_device.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 2fe5f6d13..20e409861 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -69,7 +69,7 @@ typedef struct LogState {
69 int fakeFd; 69 int fakeFd;
70 70
71 /* a printable name for this fake device */ 71 /* a printable name for this fake device */
72 char *debugName; 72 char debugName[sizeof("/dev/log/security")];
73 73
74 /* nonzero if this is a binary log */ 74 /* nonzero if this is a binary log */
75 int isBinary; 75 int isBinary;
@@ -123,8 +123,8 @@ static void unlock()
123 * File descriptor management. 123 * File descriptor management.
124 */ 124 */
125#define FAKE_FD_BASE 10000 125#define FAKE_FD_BASE 10000
126#define MAX_OPEN_LOGS 16 126#define MAX_OPEN_LOGS 8
127static LogState *openLogTable[MAX_OPEN_LOGS]; 127static LogState openLogTable[MAX_OPEN_LOGS];
128 128
129/* 129/*
130 * Allocate an fd and associate a new LogState with it. 130 * Allocate an fd and associate a new LogState with it.
@@ -134,11 +134,10 @@ static LogState *createLogState()
134{ 134{
135 size_t i; 135 size_t i;
136 136
137 for (i = 0; i < sizeof(openLogTable); i++) { 137 for (i = 0; i < (sizeof(openLogTable) / sizeof(openLogTable[0])); i++) {
138 if (openLogTable[i] == NULL) { 138 if (openLogTable[i].fakeFd == 0) {
139 openLogTable[i] = calloc(1, sizeof(LogState)); 139 openLogTable[i].fakeFd = FAKE_FD_BASE + i;
140 openLogTable[i]->fakeFd = FAKE_FD_BASE + i; 140 return &openLogTable[i];
141 return openLogTable[i];
142 } 141 }
143 } 142 }
144 return NULL; 143 return NULL;
@@ -150,7 +149,7 @@ static LogState *createLogState()
150static LogState *fdToLogState(int fd) 149static LogState *fdToLogState(int fd)
151{ 150{
152 if (fd >= FAKE_FD_BASE && fd < FAKE_FD_BASE + MAX_OPEN_LOGS) { 151 if (fd >= FAKE_FD_BASE && fd < FAKE_FD_BASE + MAX_OPEN_LOGS) {
153 return openLogTable[fd - FAKE_FD_BASE]; 152 return &openLogTable[fd - FAKE_FD_BASE];
154 } 153 }
155 return NULL; 154 return NULL;
156} 155}
@@ -166,9 +165,7 @@ static void deleteFakeFd(int fd)
166 165
167 ls = fdToLogState(fd); 166 ls = fdToLogState(fd);
168 if (ls != NULL) { 167 if (ls != NULL) {
169 openLogTable[fd - FAKE_FD_BASE] = NULL; 168 memset(&openLogTable[fd - FAKE_FD_BASE], 0, sizeof(openLogTable[0]));
170 free(ls->debugName);
171 free(ls);
172 } 169 }
173 170
174 unlock(); 171 unlock();
@@ -191,10 +188,12 @@ static void configureInitialState(const char* pathName, LogState* logState)
191{ 188{
192 static const int kDevLogLen = sizeof("/dev/log/") - 1; 189 static const int kDevLogLen = sizeof("/dev/log/") - 1;
193 190
194 logState->debugName = strdup(pathName); 191 strncpy(logState->debugName, pathName, sizeof(logState->debugName));
192 logState->debugName[sizeof(logState->debugName) - 1] = '\0';
195 193
196 /* identify binary logs */ 194 /* identify binary logs */
197 if (strcmp(pathName + kDevLogLen, "events") == 0) { 195 if (!strcmp(pathName + kDevLogLen, "events") ||
196 !strcmp(pathName + kDevLogLen, "security")) {
198 logState->isBinary = 1; 197 logState->isBinary = 1;
199 } 198 }
200 199
@@ -218,8 +217,7 @@ static void configureInitialState(const char* pathName, LogState* logState)
218 217
219 i = 0; 218 i = 0;
220 while (*tags != '\0' && !isspace(*tags) && *tags != ':' && 219 while (*tags != '\0' && !isspace(*tags) && *tags != ':' &&
221 i < kMaxTagLen) 220 i < kMaxTagLen) {
222 {
223 tagName[i++] = *tags++; 221 tagName[i++] = *tags++;
224 } 222 }
225 if (i == kMaxTagLen) { 223 if (i == kMaxTagLen) {
@@ -320,9 +318,9 @@ static const char* getPriorityString(int priority)
320 }; 318 };
321 int idx; 319 int idx;
322 320
323 idx = (int) priority - (int) ANDROID_LOG_VERBOSE; 321 idx = (int)priority - (int)ANDROID_LOG_VERBOSE;
324 if (idx < 0 || 322 if (idx < 0 ||
325 idx >= (int) (sizeof(priorityStrings) / sizeof(priorityStrings[0]))) 323 idx >= (int)(sizeof(priorityStrings) / sizeof(priorityStrings[0])))
326 return "?unknown?"; 324 return "?unknown?";
327 return priorityStrings[idx]; 325 return priorityStrings[idx];
328} 326}
@@ -454,13 +452,15 @@ static void showLog(LogState *state,
454 while (p < end) { 452 while (p < end) {
455 if (*p++ == '\n') numLines++; 453 if (*p++ == '\n') numLines++;
456 } 454 }
457 if (p > msg && *(p-1) != '\n') numLines++; 455 if (p > msg && *(p-1) != '\n') {
456 numLines++;
457 }
458 458
459 /* 459 /*
460 * Create an array of iovecs large enough to write all of 460 * Create an array of iovecs large enough to write all of
461 * the lines with a prefix and a suffix. 461 * the lines with a prefix and a suffix.
462 */ 462 */
463 const size_t INLINE_VECS = 6; 463 const size_t INLINE_VECS = 64;
464 const size_t MAX_LINES = ((size_t)~0)/(3*sizeof(struct iovec*)); 464 const size_t MAX_LINES = ((size_t)~0)/(3*sizeof(struct iovec*));
465 struct iovec stackVec[INLINE_VECS]; 465 struct iovec stackVec[INLINE_VECS];
466 struct iovec* vec = stackVec; 466 struct iovec* vec = stackVec;
@@ -494,7 +494,9 @@ static void showLog(LogState *state,
494 v++; 494 v++;
495 } 495 }
496 const char* start = p; 496 const char* start = p;
497 while (p < end && *p != '\n') p++; 497 while (p < end && *p != '\n') {
498 p++;
499 }
498 if ((p-start) > 0) { 500 if ((p-start) > 0) {
499 v->iov_base = (void*)start; 501 v->iov_base = (void*)start;
500 v->iov_len = p-start; 502 v->iov_len = p-start;