Skip to content

Commit

Permalink
mcelog: fix 'mcelog --client' blocked problem
Browse files Browse the repository at this point in the history
I found this problem on my x86 box:
$ mcelog --client
Memory errors
SOCKET 1 CHANNEL any DIMM any
corrected memory errors:
	660748032 total
	660748032 in 24h
uncorrected memory errors:
	0 total
	0 in 24h
...
Per page corrected memory statistics:
1000: total 854944 seen "854944 in 24h" offline-failed triggered
done
<blocked here>

I found the "done" command was split to two parts, so the client
don't known when to quit. The strace result is bellow:
$ strace -s 1024 mcelog --client
...
read(4, " total 1 seen \"1 in 24h\" online\n\na0c75f000: total 1 seen \"
1 in 24h\" online\n\na0cdbe000: total 1 seen \"1 in 24h\" online\n\na0d2
e7000: total 1 seen \"1 in 24h\" online\n\na1a3cf000: total 1 seen \"1 in
 24h\" online\n\na1d1ea000: total 1 seen \"1 in 24h\" online\n\na1d673000:
...
3f029000: total 1 seen \"1 in 24h\" online\n\ndo", 1024) = 1024
                                              ^^
read(4, "ne\n", 1024)                   = 3
         ^^^^

In this patch, I used fgets() to read one line string from server each time,
instead of reading 1024 bytes with read().

v2: close fp before return

[AK: Fixed warning]
Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
Reviewed-by: Sang Yan <sangyan@huawei.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
  • Loading branch information
Xie XiuQi authored and Andi Kleen committed Nov 12, 2014
1 parent 9de4924 commit b79a42a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions client.c
Expand Up @@ -29,9 +29,9 @@ void ask_server(char *command)
{
struct sockaddr_un sun;
int fd;
FILE * fp;
int n;
char buf[1024];
int done;
char *path = config_string("server", "socket-path");
if (!path)
path = SOCKET_PATH;
Expand All @@ -52,14 +52,18 @@ void ask_server(char *command)
if (write(fd, command, n) != n)
SYSERRprintf("client command write");

done = 0;
while (!done && (n = read(fd, buf, sizeof buf)) > 0) {
if (n >= 5 && !memcmp(buf + n - 5, "done\n", 5)) {
n -= 5;
done = 1;
if ((fp = fdopen(fd, "r")) != NULL) {
while (fgets(buf, sizeof buf, fp)) {
n = strlen(buf);
if (n >= 5 && !memcmp(buf + n - 5, "done\n", 5)) {
fclose(fp);
return;
}

fputs(buf, stdout);
}
write(1, buf, n);
fclose(fp);
}
if (n < 0)
SYSERRprintf("client read");

SYSERRprintf("client read");
}

0 comments on commit b79a42a

Please sign in to comment.