system/corennnnn
リビジョン | 65b262c23831aebf76a55f46dfb74983c26718c7 (tree) |
---|---|
日時 | 2017-01-17 00:30:10 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
コミッター | Chih-Wei Huang |
Merge remote-tracking branch 'cm/cm-13.0' into cm-13.0-x86
@@ -89,6 +89,11 @@ typedef enum android_LogPriority { | ||
89 | 89 | } android_LogPriority; |
90 | 90 | |
91 | 91 | /* |
92 | + * Release any logger resources (a new log write will immediately re-acquire) | |
93 | + */ | |
94 | +void __android_log_close(); | |
95 | + | |
96 | +/* | |
92 | 97 | * Send a simple string to the log. |
93 | 98 | */ |
94 | 99 | int __android_log_write(int prio, const char *tag, const char *text); |
@@ -32,6 +32,7 @@ private: | ||
32 | 32 | int mCommandCount; |
33 | 33 | bool mWithSeq; |
34 | 34 | FrameworkCommandCollection *mCommands; |
35 | + bool mSkipToNextNullByte; | |
35 | 36 | |
36 | 37 | public: |
37 | 38 | FrameworkListener(const char *socketName); |
@@ -1022,8 +1022,10 @@ static int charging_mode_booting(void) { | ||
1022 | 1022 | if (f < 0) |
1023 | 1023 | return 0; |
1024 | 1024 | |
1025 | - if (1 != read(f, (void *)&cmb,1)) | |
1025 | + if (1 != read(f, (void *)&cmb,1)) { | |
1026 | + close(f); | |
1026 | 1027 | return 0; |
1028 | + } | |
1027 | 1029 | |
1028 | 1030 | close(f); |
1029 | 1031 | return ('1' == cmb); |
@@ -323,6 +323,48 @@ const char *android_log_id_to_name(log_id_t log_id) | ||
323 | 323 | } |
324 | 324 | #endif |
325 | 325 | |
326 | +/* | |
327 | + * Release any logger resources. A new log write will immediately re-acquire. | |
328 | + */ | |
329 | +void __android_log_close() | |
330 | +{ | |
331 | +#if FAKE_LOG_DEVICE | |
332 | + int i; | |
333 | +#endif | |
334 | + | |
335 | +#ifdef HAVE_PTHREADS | |
336 | + pthread_mutex_lock(&log_init_lock); | |
337 | +#endif | |
338 | + | |
339 | + write_to_log = __write_to_log_init; | |
340 | + | |
341 | + /* | |
342 | + * Threads that are actively writing at this point are not held back | |
343 | + * by a lock and are at risk of dropping the messages with a return code | |
344 | + * -EBADF. Prefer to return error code than add the overhead of a lock to | |
345 | + * each log writing call to guarantee delivery. In addition, anyone | |
346 | + * calling this is doing so to release the logging resources and shut down, | |
347 | + * for them to do so with outstanding log requests in other threads is a | |
348 | + * disengenuous use of this function. | |
349 | + */ | |
350 | +#if FAKE_LOG_DEVICE | |
351 | + for (i = 0; i < LOG_ID_MAX; i++) { | |
352 | + fakeLogClose(log_fds[i]); | |
353 | + log_fds[i] = -1; | |
354 | + } | |
355 | +#else | |
356 | + close(logd_fd); | |
357 | + logd_fd = -1; | |
358 | + | |
359 | + close(pstore_fd); | |
360 | + pstore_fd = -1; | |
361 | +#endif | |
362 | + | |
363 | +#ifdef HAVE_PTHREADS | |
364 | + pthread_mutex_unlock(&log_init_lock); | |
365 | +#endif | |
366 | +} | |
367 | + | |
326 | 368 | static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) |
327 | 369 | { |
328 | 370 | #if !defined(_WIN32) |
@@ -106,6 +106,41 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr) | ||
106 | 106 | return ret; |
107 | 107 | } |
108 | 108 | |
109 | +/* | |
110 | + * Release any logger resources. A new log write will immediately re-acquire. | |
111 | + */ | |
112 | +void __android_log_close() | |
113 | +{ | |
114 | +#ifdef HAVE_PTHREADS | |
115 | + pthread_mutex_lock(&log_init_lock); | |
116 | +#endif | |
117 | + | |
118 | + write_to_log = __write_to_log_init; | |
119 | + | |
120 | + /* | |
121 | + * Threads that are actively writing at this point are not held back | |
122 | + * by a lock and are at risk of dropping the messages with a return code | |
123 | + * -EBADF. Prefer to return error code than add the overhead of a lock to | |
124 | + * each log writing call to guarantee delivery. In addition, anyone | |
125 | + * calling this is doing so to release the logging resources and shut down, | |
126 | + * for them to do so with outstanding log requests in other threads is a | |
127 | + * disengenuous use of this function. | |
128 | + */ | |
129 | + | |
130 | + log_close(log_fds[LOG_ID_MAIN]); | |
131 | + log_fds[LOG_ID_MAIN] = -1; | |
132 | + log_close(log_fds[LOG_ID_RADIO]); | |
133 | + log_fds[LOG_ID_RADIO] = -1; | |
134 | + log_close(log_fds[LOG_ID_EVENTS]); | |
135 | + log_fds[LOG_ID_EVENTS] = -1; | |
136 | + log_close(log_fds[LOG_ID_SYSTEM]); | |
137 | + log_fds[LOG_ID_SYSTEM] = -1; | |
138 | + | |
139 | +#ifdef HAVE_PTHREADS | |
140 | + pthread_mutex_unlock(&log_init_lock); | |
141 | +#endif | |
142 | +} | |
143 | + | |
109 | 144 | static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) |
110 | 145 | { |
111 | 146 | pthread_mutex_lock(&log_init_lock); |
@@ -127,12 +127,17 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) { | ||
127 | 127 | ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( |
128 | 128 | LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); |
129 | 129 | |
130 | + // Check that we can close and reopen the logger | |
130 | 131 | log_time ts(CLOCK_MONOTONIC); |
131 | - | |
132 | 132 | ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts))); |
133 | + __android_log_close(); | |
134 | + | |
135 | + log_time ts1(CLOCK_MONOTONIC); | |
136 | + ASSERT_LT(0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1))); | |
133 | 137 | usleep(1000000); |
134 | 138 | |
135 | 139 | int count = 0; |
140 | + int second_count = 0; | |
136 | 141 | |
137 | 142 | for (;;) { |
138 | 143 | log_msg log_msg; |
@@ -156,10 +161,13 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) { | ||
156 | 161 | log_time tx(eventData + 4 + 1); |
157 | 162 | if (ts == tx) { |
158 | 163 | ++count; |
164 | + } else if (ts1 == tx) { | |
165 | + ++second_count; | |
159 | 166 | } |
160 | 167 | } |
161 | 168 | |
162 | 169 | EXPECT_EQ(1, count); |
170 | + EXPECT_EQ(1, second_count); | |
163 | 171 | |
164 | 172 | android_logger_list_close(logger_list); |
165 | 173 | } |
@@ -49,6 +49,7 @@ void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) { | ||
49 | 49 | errorRate = 0; |
50 | 50 | mCommandCount = 0; |
51 | 51 | mWithSeq = withSeq; |
52 | + mSkipToNextNullByte = false; | |
52 | 53 | } |
53 | 54 | |
54 | 55 | bool FrameworkListener::onDataAvailable(SocketClient *c) { |
@@ -59,10 +60,15 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) { | ||
59 | 60 | if (len < 0) { |
60 | 61 | SLOGE("read() failed (%s)", strerror(errno)); |
61 | 62 | return false; |
62 | - } else if (!len) | |
63 | + } else if (!len) { | |
63 | 64 | return false; |
64 | - if(buffer[len-1] != '\0') | |
65 | + } else if (buffer[len-1] != '\0') { | |
65 | 66 | SLOGW("String is not zero-terminated"); |
67 | + android_errorWriteLog(0x534e4554, "29831647"); | |
68 | + c->sendMsg(500, "Command too large for buffer", false); | |
69 | + mSkipToNextNullByte = true; | |
70 | + return false; | |
71 | + } | |
66 | 72 | |
67 | 73 | int offset = 0; |
68 | 74 | int i; |
@@ -70,11 +76,16 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) { | ||
70 | 76 | for (i = 0; i < len; i++) { |
71 | 77 | if (buffer[i] == '\0') { |
72 | 78 | /* IMPORTANT: dispatchCommand() expects a zero-terminated string */ |
73 | - dispatchCommand(c, buffer + offset); | |
79 | + if (mSkipToNextNullByte) { | |
80 | + mSkipToNextNullByte = false; | |
81 | + } else { | |
82 | + dispatchCommand(c, buffer + offset); | |
83 | + } | |
74 | 84 | offset = i + 1; |
75 | 85 | } |
76 | 86 | } |
77 | 87 | |
88 | + mSkipToNextNullByte = false; | |
78 | 89 | return true; |
79 | 90 | } |
80 | 91 |
@@ -463,9 +463,14 @@ static int32_t MapCentralDirectory0(int fd, const char* debug_file_name, | ||
463 | 463 | * Grab the CD offset and size, and the number of entries in the |
464 | 464 | * archive and verify that they look reasonable. |
465 | 465 | */ |
466 | - if (eocd->cd_start_offset + eocd->cd_size > eocd_offset) { | |
466 | + if (static_cast<off64_t>(eocd->cd_start_offset) + eocd->cd_size > eocd_offset) { | |
467 | 467 | ALOGW("Zip: bad offsets (dir %" PRIu32 ", size %" PRIu32 ", eocd %" PRId64 ")", |
468 | 468 | eocd->cd_start_offset, eocd->cd_size, static_cast<int64_t>(eocd_offset)); |
469 | +#if defined(__ANDROID__) | |
470 | + if (eocd->cd_start_offset + eocd->cd_size <= eocd_offset) { | |
471 | + android_errorWriteLog(0x534e4554, "31251826"); | |
472 | + } | |
473 | +#endif | |
469 | 474 | return kInvalidOffset; |
470 | 475 | } |
471 | 476 | if (eocd->num_records == 0) { |