X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/3cd12b568776fcee3284ca692ad25e4ddce93c95..a5dce40726757a6679b534a5f8456120ff974483:/src/networking.c diff --git a/src/networking.c b/src/networking.c index 8949c948..29eed888 100644 --- a/src/networking.c +++ b/src/networking.c @@ -526,10 +526,16 @@ void freeClient(redisClient *c) { * close the connection with all our slaves if we have any, so * when we'll resync with the master the other slaves will sync again * with us as well. Note that also when the slave is not connected - * to the master it will keep refusing connections by other slaves. */ - while (listLength(server.slaves)) { - ln = listFirst(server.slaves); - freeClient((redisClient*)ln->value); + * to the master it will keep refusing connections by other slaves. + * + * We do this only if server.masterhost != NULL. If it is NULL this + * means the user called SLAVEOF NO ONE and we are freeing our + * link with the master, so no need to close link with slaves. */ + if (server.masterhost != NULL) { + while (listLength(server.slaves)) { + ln = listFirst(server.slaves); + freeClient((redisClient*)ln->value); + } } } /* Release memory */ @@ -870,15 +876,16 @@ void getClientsMaxBuffers(unsigned long *longest_output_list, } void clientCommand(redisClient *c) { + listNode *ln; + listIter li; + redisClient *client; + if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) { - listNode *ln; - listIter li; sds o = sdsempty(); time_t now = time(NULL); listRewind(server.clients,&li); while ((ln = listNext(&li)) != NULL) { - redisClient *client; char ip[32], flags[16], *p; int port; @@ -911,6 +918,26 @@ void clientCommand(redisClient *c) { } addReplyBulkCBuffer(c,o,sdslen(o)); sdsfree(o); + } else if (!strcasecmp(c->argv[1]->ptr,"kill") && c->argc == 3) { + listRewind(server.clients,&li); + while ((ln = listNext(&li)) != NULL) { + char ip[32], addr[64]; + int port; + + client = listNodeValue(ln); + if (anetPeerToString(client->fd,ip,&port) == -1) continue; + snprintf(addr,sizeof(addr),"%s:%d",ip,port); + if (strcmp(addr,c->argv[2]->ptr) == 0) { + addReply(c,shared.ok); + if (c == client) { + client->flags |= REDIS_CLOSE_AFTER_REPLY; + } else { + freeClient(client); + } + return; + } + } + addReplyError(c,"No such client"); } else { addReplyError(c, "Syntax error, try CLIENT (LIST | KILL ip:port)"); }