+ server.repl_state = REDIS_REPL_CONNECTED;
+ redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Finished with success");
+ /* Restart the AOF subsystem now that we finished the sync. This
+ * will trigger an AOF rewrite, and when done will start appending
+ * to the new file. */
+ if (server.aof_state != REDIS_AOF_OFF) {
+ int retry = 10;
+
+ stopAppendOnly();
+ while (retry-- && startAppendOnly() == REDIS_ERR) {
+ redisLog(REDIS_WARNING,"Failed enabling the AOF after successful master synchrnization! Trying it again in one second.");
+ sleep(1);
+ }
+ if (!retry) {
+ redisLog(REDIS_WARNING,"FATAL: this slave instance finished the synchronization with its master, but the AOF can't be turned on. Exiting now.");
+ exit(1);
+ }
+ }
+ }
+
+ return;
+
+error:
+ replicationAbortSyncTransfer();
+ return;
+}
+
+/* Send a synchronous command to the master. Used to send AUTH and
+ * REPLCONF commadns before starting the replication with SYNC.
+ *
+ * On success NULL is returned.
+ * On error an sds string describing the error is returned.
+ */
+char *sendSynchronousCommand(int fd, ...) {
+ va_list ap;
+ sds cmd = sdsempty();
+ char *arg, buf[256];
+
+ /* Create the command to send to the master, we use simple inline
+ * protocol for simplicity as currently we only send simple strings. */
+ va_start(ap,fd);
+ while(1) {
+ arg = va_arg(ap, char*);
+ if (arg == NULL) break;
+
+ if (sdslen(cmd) != 0) cmd = sdscatlen(cmd," ",1);
+ cmd = sdscat(cmd,arg);
+ }
+ cmd = sdscatlen(cmd,"\r\n",2);
+
+ /* Transfer command to the server. */
+ if (syncWrite(fd,cmd,sdslen(cmd),server.repl_syncio_timeout*1000) == -1) {
+ sdsfree(cmd);
+ return sdscatprintf(sdsempty(),"Writing to master: %s",
+ strerror(errno));