Skip to content

Commit

Permalink
Rename CLI macros and redis_strlcpy to valkey
Browse files Browse the repository at this point in the history
Signed-off-by: Shivshankar-Reddy <[email protected]>
  • Loading branch information
Shivshankar-Reddy committed Apr 10, 2024
1 parent f8cec23 commit fe454dc
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ int anetUnixGenericConnect(char *err, const char *path, int flags)
return ANET_ERR;

sa.sun_family = AF_LOCAL;
redis_strlcpy(sa.sun_path,path,sizeof(sa.sun_path));
valkey_strlcpy(sa.sun_path,path,sizeof(sa.sun_path));
if (flags & ANET_CONNECT_NONBLOCK) {
if (anetNonBlock(err,s) != ANET_OK) {
close(s);
Expand Down Expand Up @@ -613,7 +613,7 @@ int anetUnixServer(char *err, char *path, mode_t perm, int backlog)

memset(&sa,0,sizeof(sa));
sa.sun_family = AF_LOCAL;
redis_strlcpy(sa.sun_path,path,sizeof(sa.sun_path));
valkey_strlcpy(sa.sun_path,path,sizeof(sa.sun_path));
if (anetListen(err,s,(struct sockaddr*)&sa,sizeof(sa),backlog,perm) == ANET_ERR)
return ANET_ERR;
return s;
Expand Down
4 changes: 2 additions & 2 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ void clusterUpdateMyselfIp(void) {
* duplicating the string. This way later we can check if
* the address really changed. */
prev_ip = zstrdup(prev_ip);
redis_strlcpy(myself->ip,server.cluster_announce_ip,NET_IP_STR_LEN);
valkey_strlcpy(myself->ip,server.cluster_announce_ip,NET_IP_STR_LEN);
} else {
myself->ip[0] = '\0'; /* Force autodetection. */
}
Expand Down Expand Up @@ -3526,7 +3526,7 @@ static void clusterBuildMessageHdr(clusterMsg *hdr, int type, size_t msglen) {
* first byte is zero, they'll do auto discovery. */
memset(hdr->myip,0,NET_IP_STR_LEN);
if (server.cluster_announce_ip) {
redis_strlcpy(hdr->myip,server.cluster_announce_ip,NET_IP_STR_LEN);
valkey_strlcpy(hdr->myip,server.cluster_announce_ip,NET_IP_STR_LEN);
}

/* Handle cluster-announce-[tls-|bus-]port. */
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ static int enumConfigSet(standardConfig *config, sds *argv, int argc, const char
}
sdsrange(enumerr,0,-3); /* Remove final ", ". */

redis_strlcpy(loadbuf, enumerr, LOADBUF_SIZE);
valkey_strlcpy(loadbuf, enumerr, LOADBUF_SIZE);

sdsfree(enumerr);
*err = loadbuf;
Expand Down
2 changes: 1 addition & 1 deletion src/fmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
* will error on stdlib definitions in files as well*/
#if (__GNUC__ && __GNUC__ >= 4) && !defined __APPLE__
int sprintf(char *str, const char *format, ...) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of snprintf instead")));
char *strcpy(char *restrict dest, const char *src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of redis_strlcpy instead")));
char *strcpy(char *restrict dest, const char *src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of valkey_strlcpy instead")));
char *strcat(char *restrict dest, const char *restrict src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of redis_strlcat instead")));
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -9056,7 +9056,7 @@ int VM_GetClusterNodeInfo(ValkeyModuleCtx *ctx, const char *id, char *ip, char *
return VALKEYMODULE_ERR;
}

if (ip) redis_strlcpy(ip, clusterNodeIp(node),NET_IP_STR_LEN);
if (ip) valkey_strlcpy(ip, clusterNodeIp(node),NET_IP_STR_LEN);

if (master_id) {
/* If the information is not available, the function will set the
Expand Down Expand Up @@ -12627,7 +12627,7 @@ int moduleVerifyResourceName(const char *name) {
static char configerr[CONFIG_ERR_SIZE];
static void propagateErrorString(ValkeyModuleString *err_in, const char **err) {
if (err_in) {
redis_strlcpy(configerr, err_in->ptr, CONFIG_ERR_SIZE);
valkey_strlcpy(configerr, err_in->ptr, CONFIG_ERR_SIZE);
decrRefCount(err_in);
*err = configerr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ void rdbRemoveTempFile(pid_t childpid, int from_signal) {

/* Generate temp rdb file name using async-signal safe functions. */
ll2string(pid, sizeof(pid), childpid);
redis_strlcpy(tmpfile, "temp-", sizeof(tmpfile));
valkey_strlcpy(tmpfile, "temp-", sizeof(tmpfile));
redis_strlcat(tmpfile, pid, sizeof(tmpfile));
redis_strlcat(tmpfile, ".rdb", sizeof(tmpfile));

Expand Down
2 changes: 1 addition & 1 deletion src/strl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
redis_strlcpy(char *dst, const char *src, size_t dsize)
valkey_strlcpy(char *dst, const char *src, size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;
Expand Down
48 changes: 24 additions & 24 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,53 +1385,53 @@ static void test_string2ll(void) {
long long v;

/* May not start with +. */
redis_strlcpy(buf,"+1",sizeof(buf));
valkey_strlcpy(buf,"+1",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 0);

/* Leading space. */
redis_strlcpy(buf," 1",sizeof(buf));
valkey_strlcpy(buf," 1",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 0);

/* Trailing space. */
redis_strlcpy(buf,"1 ",sizeof(buf));
valkey_strlcpy(buf,"1 ",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 0);

/* May not start with 0. */
redis_strlcpy(buf,"01",sizeof(buf));
valkey_strlcpy(buf,"01",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 0);

redis_strlcpy(buf,"-1",sizeof(buf));
valkey_strlcpy(buf,"-1",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == -1);

redis_strlcpy(buf,"0",sizeof(buf));
valkey_strlcpy(buf,"0",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == 0);

redis_strlcpy(buf,"1",sizeof(buf));
valkey_strlcpy(buf,"1",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == 1);

redis_strlcpy(buf,"99",sizeof(buf));
valkey_strlcpy(buf,"99",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == 99);

redis_strlcpy(buf,"-99",sizeof(buf));
valkey_strlcpy(buf,"-99",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == -99);

redis_strlcpy(buf,"-9223372036854775808",sizeof(buf));
valkey_strlcpy(buf,"-9223372036854775808",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == LLONG_MIN);

redis_strlcpy(buf,"-9223372036854775809",sizeof(buf)); /* overflow */
valkey_strlcpy(buf,"-9223372036854775809",sizeof(buf)); /* overflow */
assert(string2ll(buf,strlen(buf),&v) == 0);

redis_strlcpy(buf,"9223372036854775807",sizeof(buf));
valkey_strlcpy(buf,"9223372036854775807",sizeof(buf));
assert(string2ll(buf,strlen(buf),&v) == 1);
assert(v == LLONG_MAX);

redis_strlcpy(buf,"9223372036854775808",sizeof(buf)); /* overflow */
valkey_strlcpy(buf,"9223372036854775808",sizeof(buf)); /* overflow */
assert(string2ll(buf,strlen(buf),&v) == 0);
}

Expand All @@ -1440,46 +1440,46 @@ static void test_string2l(void) {
long v;

/* May not start with +. */
redis_strlcpy(buf,"+1",sizeof(buf));
valkey_strlcpy(buf,"+1",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 0);

/* May not start with 0. */
redis_strlcpy(buf,"01",sizeof(buf));
valkey_strlcpy(buf,"01",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 0);

redis_strlcpy(buf,"-1",sizeof(buf));
valkey_strlcpy(buf,"-1",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == -1);

redis_strlcpy(buf,"0",sizeof(buf));
valkey_strlcpy(buf,"0",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == 0);

redis_strlcpy(buf,"1",sizeof(buf));
valkey_strlcpy(buf,"1",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == 1);

redis_strlcpy(buf,"99",sizeof(buf));
valkey_strlcpy(buf,"99",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == 99);

redis_strlcpy(buf,"-99",sizeof(buf));
valkey_strlcpy(buf,"-99",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == -99);

#if LONG_MAX != LLONG_MAX
redis_strlcpy(buf,"-2147483648",sizeof(buf));
valkey_strlcpy(buf,"-2147483648",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == LONG_MIN);

redis_strlcpy(buf,"-2147483649",sizeof(buf)); /* overflow */
valkey_strlcpy(buf,"-2147483649",sizeof(buf)); /* overflow */
assert(string2l(buf,strlen(buf),&v) == 0);

redis_strlcpy(buf,"2147483647",sizeof(buf));
valkey_strlcpy(buf,"2147483647",sizeof(buf));
assert(string2l(buf,strlen(buf),&v) == 1);
assert(v == LONG_MAX);

redis_strlcpy(buf,"2147483648",sizeof(buf)); /* overflow */
valkey_strlcpy(buf,"2147483648",sizeof(buf)); /* overflow */
assert(string2l(buf,strlen(buf),&v) == 0);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int snprintf_async_signal_safe(char *to, size_t n, const char *fmt, ...)
#else
int snprintf_async_signal_safe(char *to, size_t n, const char *fmt, ...);
#endif
size_t redis_strlcpy(char *dst, const char *src, size_t dsize);
size_t valkey_strlcpy(char *dst, const char *src, size_t dsize);
size_t redis_strlcat(char *dst, const char *src, size_t dsize);

#ifdef SERVER_TEST
Expand Down
46 changes: 23 additions & 23 deletions src/valkey-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
#define OUTPUT_CSV 2
#define OUTPUT_JSON 3
#define OUTPUT_QUOTED_JSON 4
#define REDIS_CLI_KEEPALIVE_INTERVAL 15 /* seconds */
#define REDIS_CLI_DEFAULT_PIPE_TIMEOUT 30 /* seconds */
#define REDIS_CLI_HISTFILE_ENV "REDISCLI_HISTFILE"
#define CLI_KEEPALIVE_INTERVAL 15 /* seconds */
#define CLI_DEFAULT_PIPE_TIMEOUT 30 /* seconds */
#define CLI_HISTFILE_ENV "REDISCLI_HISTFILE"
#define CLI_HISTFILE_DEFAULT ".valkeycli_history"
#define REDIS_CLI_RCFILE_ENV "REDISCLI_RCFILE"
#define CLI_RCFILE_ENV "REDISCLI_RCFILE"
#define CLI_RCFILE_DEFAULT ".valkeyclirc"
#define REDIS_CLI_AUTH_ENV "REDISCLI_AUTH"
#define REDIS_CLI_CLUSTER_YES_ENV "REDISCLI_CLUSTER_YES"
#define CLI_AUTH_ENV "REDISCLI_AUTH"
#define CLI_CLUSTER_YES_ENV "REDISCLI_CLUSTER_YES"

#define CLUSTER_MANAGER_SLOTS 16384
#define CLUSTER_MANAGER_PORT_INCR 10000 /* same as CLUSTER_PORT_INCR */
Expand Down Expand Up @@ -296,7 +296,7 @@ static long getLongInfoField(char *info, char *field);
/*------------------------------------------------------------------------------
* Utility functions
*--------------------------------------------------------------------------- */
size_t redis_strlcpy(char *dst, const char *src, size_t dsize);
size_t valkey_strlcpy(char *dst, const char *src, size_t dsize);

static void cliPushHandler(void *, void *);

Expand Down Expand Up @@ -1693,7 +1693,7 @@ static int cliConnect(int flags) {
* in order to prevent timeouts caused by the execution of long
* commands. At the same time this improves the detection of real
* errors. */
anetKeepAlive(NULL, context->fd, REDIS_CLI_KEEPALIVE_INTERVAL);
anetKeepAlive(NULL, context->fd, CLI_KEEPALIVE_INTERVAL);

/* State of the current connection. */
config.current_resp3 = 0;
Expand Down Expand Up @@ -2985,12 +2985,12 @@ static int parseOptions(int argc, char **argv) {

static void parseEnv(void) {
/* Set auth from env, but do not overwrite CLI arguments if passed */
char *auth = getenv(REDIS_CLI_AUTH_ENV);
char *auth = getenv(CLI_AUTH_ENV);
if (auth != NULL && config.conn_info.auth == NULL) {
config.conn_info.auth = auth;
}

char *cluster_yes = getenv(REDIS_CLI_CLUSTER_YES_ENV);
char *cluster_yes = getenv(CLI_CLUSTER_YES_ENV);
if (cluster_yes != NULL && !strcmp(cluster_yes, "1")) {
config.cluster_manager_command.flags |= CLUSTER_MANAGER_CMD_FLAG_YES;
}
Expand Down Expand Up @@ -3032,13 +3032,13 @@ static void usage(int err) {
" Default timeout is 0, meaning no limit, depending on the OS.\n"
" -s <socket> Server socket (overrides hostname and port).\n"
" -a <password> Password to use when connecting to the server.\n"
" You can also use the " REDIS_CLI_AUTH_ENV " environment\n"
" You can also use the " CLI_AUTH_ENV " environment\n"
" variable to pass this password more safely\n"
" (if both are used, this argument takes precedence).\n"
" --user <username> Used to send ACL style 'AUTH username pass'. Needs -a.\n"
" --pass <password> Alias of -a for consistency with the new --user option.\n"
" --askpass Force user to input password with mask from STDIN.\n"
" If this argument is used, '-a' and " REDIS_CLI_AUTH_ENV "\n"
" If this argument is used, '-a' and " CLI_AUTH_ENV "\n"
" environment variable will be ignored.\n"
" -u <uri> Server URI on format redis://user:password@host:port/dbnum\n"
" User, password and dbnum are optional. For authentication\n"
Expand Down Expand Up @@ -3095,7 +3095,7 @@ version,tls_usage);
" --pipe-timeout <n> In --pipe mode, abort with error if after sending all data.\n"
" no reply is received within <n> seconds.\n"
" Default timeout: %d. Use 0 to wait forever.\n",
REDIS_CLI_DEFAULT_PIPE_TIMEOUT);
CLI_DEFAULT_PIPE_TIMEOUT);
fprintf(target,
" --bigkeys Sample keys looking for keys with many elements (complexity).\n"
" --memkeys Sample keys looking for keys consuming a lot of memory.\n"
Expand Down Expand Up @@ -3258,7 +3258,7 @@ void cliSetPreferences(char **argv, int argc, int interactive) {

/* Load the ~/.valkeyclirc file if any. */
void cliLoadPreferences(void) {
sds rcfile = getDotfilePath(REDIS_CLI_RCFILE_ENV,CLI_RCFILE_DEFAULT);
sds rcfile = getDotfilePath(CLI_RCFILE_ENV,CLI_RCFILE_DEFAULT);
if (rcfile == NULL) return;
FILE *fp = fopen(rcfile,"r");
char buf[1024];
Expand Down Expand Up @@ -3379,7 +3379,7 @@ static void repl(void) {

/* Only use history and load the rc file when stdin is a tty. */
if (isatty(fileno(stdin))) {
historyfile = getDotfilePath(REDIS_CLI_HISTFILE_ENV,CLI_HISTFILE_DEFAULT);
historyfile = getDotfilePath(CLI_HISTFILE_ENV,CLI_HISTFILE_DEFAULT);
//keep in-memory history always regardless if history file can be determined
history = 1;
if (historyfile != NULL) {
Expand Down Expand Up @@ -4043,7 +4043,7 @@ static int clusterManagerCheckRedisReply(clusterManagerNode *n,
if (is_err) {
if (err != NULL) {
*err = zmalloc((r->len + 1) * sizeof(char));
redis_strlcpy(*err, r->str,(r->len + 1));
valkey_strlcpy(*err, r->str,(r->len + 1));
} else CLUSTER_MANAGER_PRINT_REPLY_ERROR(n, r->str);
}
return 0;
Expand Down Expand Up @@ -4113,7 +4113,7 @@ static int clusterManagerNodeConnect(clusterManagerNode *node) {
* in order to prevent timeouts caused by the execution of long
* commands. At the same time this improves the detection of real
* errors. */
anetKeepAlive(NULL, node->context->fd, REDIS_CLI_KEEPALIVE_INTERVAL);
anetKeepAlive(NULL, node->context->fd, CLI_KEEPALIVE_INTERVAL);
if (config.conn_info.auth) {
redisReply *reply;
if (config.conn_info.user == NULL)
Expand Down Expand Up @@ -4203,7 +4203,7 @@ static redisReply *clusterManagerGetNodeRedisInfo(clusterManagerNode *node,
if (info->type == REDIS_REPLY_ERROR) {
if (err != NULL) {
*err = zmalloc((info->len + 1) * sizeof(char));
redis_strlcpy(*err, info->str,(info->len + 1));
valkey_strlcpy(*err, info->str,(info->len + 1));
}
freeReplyObject(info);
return NULL;
Expand Down Expand Up @@ -4780,7 +4780,7 @@ static int clusterManagerSetSlot(clusterManagerNode *node1,
success = 0;
if (err != NULL) {
*err = zmalloc((reply->len + 1) * sizeof(char));
redis_strlcpy(*err, reply->str,(reply->len + 1));
valkey_strlcpy(*err, reply->str,(reply->len + 1));
} else CLUSTER_MANAGER_PRINT_REPLY_ERROR(node1, reply->str);
goto cleanup;
}
Expand Down Expand Up @@ -5054,7 +5054,7 @@ static int clusterManagerMigrateKeysInSlot(clusterManagerNode *source,
success = 0;
if (err != NULL) {
*err = zmalloc((reply->len + 1) * sizeof(char));
redis_strlcpy(*err, reply->str,(reply->len + 1));
valkey_strlcpy(*err, reply->str,(reply->len + 1));
CLUSTER_MANAGER_PRINT_REPLY_ERROR(source, *err);
}
goto next;
Expand Down Expand Up @@ -5166,7 +5166,7 @@ static int clusterManagerMigrateKeysInSlot(clusterManagerNode *source,
if (migrate_reply != NULL) {
if (err) {
*err = zmalloc((migrate_reply->len + 1) * sizeof(char));
redis_strlcpy(*err, migrate_reply->str, (migrate_reply->len + 1));
valkey_strlcpy(*err, migrate_reply->str, (migrate_reply->len + 1));
}
printf("\n");
CLUSTER_MANAGER_PRINT_REPLY_ERROR(source,
Expand Down Expand Up @@ -5283,7 +5283,7 @@ static int clusterManagerFlushNodeConfig(clusterManagerNode *node, char **err) {
if (reply == NULL || (is_err = (reply->type == REDIS_REPLY_ERROR))) {
if (is_err && err != NULL) {
*err = zmalloc((reply->len + 1) * sizeof(char));
redis_strlcpy(*err, reply->str, (reply->len + 1));
valkey_strlcpy(*err, reply->str, (reply->len + 1));
}
success = 0;
/* If the cluster did not already joined it is possible that
Expand Down Expand Up @@ -9881,7 +9881,7 @@ int main(int argc, char **argv) {
config.pattern = NULL;
config.rdb_filename = NULL;
config.pipe_mode = 0;
config.pipe_timeout = REDIS_CLI_DEFAULT_PIPE_TIMEOUT;
config.pipe_timeout = CLI_DEFAULT_PIPE_TIMEOUT;
config.bigkeys = 0;
config.memkeys = 0;
config.hotkeys = 0;
Expand Down

0 comments on commit fe454dc

Please sign in to comment.