diff --git a/src/acl.c b/src/acl.c index 92598e43c..433dd3d3f 100644 --- a/src/acl.c +++ b/src/acl.c @@ -1268,7 +1268,9 @@ sds ACLLoadFromFile(const char *filename) { * When C_ERR is returned a log is produced with hints about the issue. */ int ACLSaveToFile(const char *filename) { sds acl = sdsempty(); - int fd; + int fd = -1; + sds tmpfilename = NULL; + int retval = C_ERR; /* Let's generate an SDS string containing the new version of the * ACL file. */ @@ -1291,41 +1293,38 @@ int ACLSaveToFile(const char *filename) { raxStop(&ri); /* Create a temp file with the new content. */ - sds tmpfilename = sdsnew(filename); + tmpfilename = sdsnew(filename); tmpfilename = sdscatfmt(tmpfilename,".tmp-%i-%I", (int)getpid(),(int)mstime()); if ((fd = open(tmpfilename,O_WRONLY|O_CREAT,0644)) == -1) { serverLog(LL_WARNING,"Opening temp ACL file for ACL SAVE: %s", strerror(errno)); - sdsfree(tmpfilename); - sdsfree(acl); - return C_ERR; + goto cleanup; } /* Write it. */ if (write(fd,acl,sdslen(acl)) != (ssize_t)sdslen(acl)) { serverLog(LL_WARNING,"Writing ACL file for ACL SAVE: %s", strerror(errno)); - close(fd); - unlink(tmpfilename); - sdsfree(tmpfilename); - sdsfree(acl); - return C_ERR; + goto cleanup; } - close(fd); - sdsfree(acl); + close(fd); fd = -1; /* Let's replace the new file with the old one. */ if (rename(tmpfilename,filename) == -1) { serverLog(LL_WARNING,"Renaming ACL file for ACL SAVE: %s", strerror(errno)); - unlink(tmpfilename); - sdsfree(tmpfilename); - return C_ERR; + goto cleanup; } + sdsfree(tmpfilename); tmpfilename = NULL; + retval = C_OK; /* If we reached this point, everything is fine. */ +cleanup: + if (fd != -1) close(fd); + if (tmpfilename) unlink(tmpfilename); sdsfree(tmpfilename); - return C_OK; + sdsfree(acl); + return retval; } /* This function is called once the server is already running, modules are @@ -1372,7 +1371,7 @@ void ACLLoadUsersAtStartup(void) { * ACL USERS * ACL CAT [] * ACL SETUSER ... acl rules ... - * ACL DELUSER + * ACL DELUSER [...] * ACL GETUSER */ void aclCommand(client *c) { @@ -1400,6 +1399,10 @@ void aclCommand(client *c) { addReplyError(c,"The 'default' user cannot be removed"); return; } + } + + for (int j = 2; j < c->argc; j++) { + sds username = c->argv[j]->ptr; user *u; if (raxRemove(Users,(unsigned char*)username, sdslen(username), @@ -1546,7 +1549,7 @@ void aclCommand(client *c) { "USERS -- List all the registered usernames.", "SETUSER [attribs ...] -- Create or modify a user.", "GETUSER -- Get the user details.", -"DELUSER -- Delete a user.", +"DELUSER [...] -- Delete a list of users.", "CAT -- List available categories.", "CAT -- List commands inside category.", "WHOAMI -- Return the current connection username.", diff --git a/src/networking.cpp b/src/networking.cpp index 6379ffd09..36d82a189 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -862,23 +862,7 @@ void addReplyNullArray(client *c) { /* Create the length prefix of a bulk reply, example: $2234 */ void addReplyBulkLenCore(client *c, robj *obj, bool fAsync) { - size_t len; - - if (sdsEncodedObject(obj)) { - len = sdslen((sds)ptrFromObj(obj)); - } else { - long n = (long)ptrFromObj(obj); - - /* Compute how many bytes will take this integer as a radix 10 string */ - len = 1; - if (n < 0) { - len++; - n = -n; - } - while((n = n/10) != 0) { - len++; - } - } + size_t len = stringObjectLen(obj); if (len < OBJ_SHARED_BULKHDR_LEN) addReplyCore(c,shared.bulkhdr[len], fAsync); diff --git a/src/redis-cli.c b/src/redis-cli.c index b52da3500..3667a1919 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -4930,6 +4930,12 @@ static int clusterManagerCommandCreate(int argc, char **argv) { cursor += slots_per_node; } + /* Rotating the list sometimes helps to get better initial + * anti-affinity before the optimizer runs. */ + clusterManagerNode *first_node = interleaved[0]; + for (i = 0; i < (interleaved_len - 1); i++) + interleaved[i] = interleaved[i + 1]; + interleaved[interleaved_len - 1] = first_node; int assign_unused = 0, available_count = interleaved_len; assign_replicas: for (i = 0; i < masters_count; i++) {