diff options
author | Mihail Zenkov <mihail.zenkov@gmail.com> | 2016-03-31 11:33:11 +0000 |
---|---|---|
committer | Gerrit Rockbox <gerrit@rockbox.org> | 2016-04-04 11:07:44 +0200 |
commit | e599810ffaa6412326f61d026fc598c721b3a01c (patch) | |
tree | fe21a4f5f388ed87e3112f00ff68cf3448f34e4e | |
parent | 26beb30c155aebc5e6e50366f1cfa34300a8c63a (diff) | |
download | rockbox-e599810ffaa6412326f61d026fc598c721b3a01c.tar.gz rockbox-e599810ffaa6412326f61d026fc598c721b3a01c.zip |
Don't add new message to logf when we dump it to file
Fix log file corruption if we have new messages at dumping log to file. Comment
removed as it incorrect. We store all messages in direct order (last message at
end of file).
Change-Id: I4acfa8a0935cc41a889e08f6bc42974fefd1ade2
-rw-r--r-- | apps/logfdisp.c | 20 | ||||
-rw-r--r-- | firmware/export/logf.h | 1 | ||||
-rw-r--r-- | firmware/logf.c | 4 |
3 files changed, 16 insertions, 9 deletions
diff --git a/apps/logfdisp.c b/apps/logfdisp.c index 8547778f64..54c345faae 100644 --- a/apps/logfdisp.c +++ b/apps/logfdisp.c | |||
@@ -218,42 +218,44 @@ bool logfdisplay(void) | |||
218 | } | 218 | } |
219 | #endif /* HAVE_LCD_BITMAP */ | 219 | #endif /* HAVE_LCD_BITMAP */ |
220 | 220 | ||
221 | /* Store the logf log to logf.txt in the .rockbox directory. The order of the | ||
222 | * entries will be "reversed" so that the most recently logged entry is on the | ||
223 | * top of the file */ | ||
224 | bool logfdump(void) | 221 | bool logfdump(void) |
225 | { | 222 | { |
226 | int fd; | 223 | int fd; |
227 | 224 | ||
228 | splashf(HZ, "Log File Dumped"); | 225 | splashf(HZ, "Log File Dumped"); |
229 | 226 | ||
230 | /* nothing to print ? */ | 227 | /* nothing to print ? */ |
231 | if(logfindex == 0 && !logfwrap) | 228 | if(logfindex == 0 && !logfwrap) |
232 | /* nothing is logged just yet */ | 229 | /* nothing is logged just yet */ |
233 | return false; | 230 | return false; |
234 | 231 | ||
232 | logfenabled = false; | ||
233 | |||
235 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666); | 234 | fd = open(ROCKBOX_DIR "/logf.txt", O_CREAT|O_WRONLY|O_TRUNC, 0666); |
236 | if(-1 != fd) { | 235 | if(-1 != fd) { |
237 | int i; | 236 | int i; |
238 | 237 | ||
239 | if(logfwrap) | 238 | if(logfwrap) |
240 | i = logfindex; | 239 | i = logfindex; |
241 | else | 240 | else |
242 | i = 0; | 241 | i = 0; |
243 | 242 | ||
244 | do { | 243 | do { |
245 | if(logfbuffer[i]=='\0') | 244 | if(logfbuffer[i]=='\0') |
246 | fdprintf(fd, "\n"); | 245 | fdprintf(fd, "\n"); |
247 | else | 246 | else |
248 | fdprintf(fd, "%c", logfbuffer[i]); | 247 | fdprintf(fd, "%c", logfbuffer[i]); |
249 | 248 | ||
250 | i++; | 249 | i++; |
251 | if(i >= MAX_LOGF_SIZE) | 250 | if(i >= MAX_LOGF_SIZE) |
252 | i = 0; | 251 | i = 0; |
253 | } while(i != logfindex); | 252 | } while(i != logfindex); |
254 | 253 | ||
255 | close(fd); | 254 | close(fd); |
256 | } | 255 | } |
256 | |||
257 | logfenabled = true; | ||
258 | |||
257 | return false; | 259 | return false; |
258 | } | 260 | } |
259 | 261 | ||
diff --git a/firmware/export/logf.h b/firmware/export/logf.h index e881e7e496..c8aaad06b4 100644 --- a/firmware/export/logf.h +++ b/firmware/export/logf.h | |||
@@ -34,6 +34,7 @@ | |||
34 | extern unsigned char logfbuffer[MAX_LOGF_SIZE]; | 34 | extern unsigned char logfbuffer[MAX_LOGF_SIZE]; |
35 | extern int logfindex; | 35 | extern int logfindex; |
36 | extern bool logfwrap; | 36 | extern bool logfwrap; |
37 | extern bool logfenabled; | ||
37 | #endif /* __PCTOOL__ */ | 38 | #endif /* __PCTOOL__ */ |
38 | 39 | ||
39 | #define logf _logf | 40 | #define logf _logf |
diff --git a/firmware/logf.c b/firmware/logf.c index 0f05c6590d..bdc5ad9cc0 100644 --- a/firmware/logf.c +++ b/firmware/logf.c | |||
@@ -62,6 +62,7 @@ static int logdiskfindex; | |||
62 | unsigned char logfbuffer[MAX_LOGF_SIZE]; | 62 | unsigned char logfbuffer[MAX_LOGF_SIZE]; |
63 | int logfindex; | 63 | int logfindex; |
64 | bool logfwrap; | 64 | bool logfwrap; |
65 | bool logfenabled = true; | ||
65 | #endif | 66 | #endif |
66 | 67 | ||
67 | #ifdef HAVE_REMOTE_LCD | 68 | #ifdef HAVE_REMOTE_LCD |
@@ -214,6 +215,9 @@ static int logf_push(void *userp, unsigned char c) | |||
214 | 215 | ||
215 | void _logf(const char *fmt, ...) | 216 | void _logf(const char *fmt, ...) |
216 | { | 217 | { |
218 | if (!logfenabled) | ||
219 | return; | ||
220 | |||
217 | #ifdef USB_ENABLE_SERIAL | 221 | #ifdef USB_ENABLE_SERIAL |
218 | int old_logfindex = logfindex; | 222 | int old_logfindex = logfindex; |
219 | #endif | 223 | #endif |