Skip to content

Commit

Permalink
libibverbs: consistently parse environment variables in ibverbs_init
Browse files Browse the repository at this point in the history
Prior to this change, setting some of the variables to "0" would be
confusingly interpreted as enabling the feature.

Signed-off-by: Greg Inozemtsev <ginozemt@amazon.com>
  • Loading branch information
Greg Inozemtsev committed Feb 2, 2022
1 parent b3b5d93 commit 5a02100
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
14 changes: 4 additions & 10 deletions libibverbs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,20 +665,14 @@ static void verbs_set_log_file(void)

int ibverbs_init(void)
{
char *env_value;

if (getenv("RDMAV_FORK_SAFE") || getenv("IBV_FORK_SAFE"))
if (check_env("RDMAV_FORK_SAFE") || check_env("IBV_FORK_SAFE"))
if (ibv_fork_init())
fprintf(stderr, PFX "Warning: fork()-safety requested "
"but init failed\n");

/* Backward compatibility for the mlx4 driver env */
env_value = getenv("MLX4_DEVICE_FATAL_CLEANUP");
if (env_value)
verbs_allow_disassociate_destroy = strcmp(env_value, "0") != 0;

if (getenv("RDMAV_ALLOW_DISASSOC_DESTROY"))
verbs_allow_disassociate_destroy = true;
verbs_allow_disassociate_destroy = check_env("RDMAV_ALLOW_DISASSOC_DESTROY")
/* Backward compatibility for the mlx4 driver env */
|| check_env("MLX4_DEVICE_FATAL_CLEANUP");

if (!ibv_get_sysfs_path())
return -errno;
Expand Down
8 changes: 8 additions & 0 deletions util/util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* GPLv2 or OpenIB.org BSD (MIT) See COPYING file */
#include <stdlib.h>
#include <string.h>
#include <sys/random.h>
#include <sys/types.h>
#include <time.h>
Expand Down Expand Up @@ -45,3 +46,10 @@ unsigned int get_random(void)

return rand_r(&seed);
}

bool check_env(const char *var)
{
const char *env_value = getenv(var);

return env_value && (strcmp(env_value, "0") != 0);
}
2 changes: 2 additions & 0 deletions util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ int set_fd_nonblock(int fd, bool nonblock);
int open_cdev(const char *devname_hint, dev_t cdev);

unsigned int get_random(void);

bool check_env(const char *var);
#endif

0 comments on commit 5a02100

Please sign in to comment.