]> git.saurik.com Git - redis.git/commitdiff
Fixed redis-cli readLine loop to correctly handle EOF.
authorLuc Heinrich <luc@honk-honk.com>
Mon, 23 Mar 2009 11:43:16 +0000 (12:43 +0100)
committerLuc Heinrich <luc@honk-honk.com>
Mon, 23 Mar 2009 11:43:16 +0000 (12:43 +0100)
When using the shutdown command with redis-cli the server saves the database and, if successful, silently closes the connection. The redis-cli tool did not correcty handle this EOF case in its readLine loop and was therefore infinitely looping - and eating 100% of the CPU - while waiting for some data which would never come.

redis-cli.c

index 38c986b34b81e32a757140ef395af698bd7b1c7e..cd106684fbca6152a4fac051e4f048456d710dcd 100644 (file)
@@ -135,11 +135,13 @@ static sds cliReadLine(int fd) {
 
     while(1) {
         char c;
+        ssize_t ret;
 
-        if (read(fd,&c,1) == -1) {
+        ret = read(fd,&c,1);
+        if (ret == -1) {
             sdsfree(line);
             return NULL;
-        } else if (c == '\n') {
+        } else if ((ret == 0) || (c == '\n')) {
             break;
         } else {
             line = sdscatlen(line,&c,1);