Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smc_run: bugfix for concurrent socket creation #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions smc-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <errno.h>
#include <search.h>
#include <ctype.h>
#include <pthread.h>

#define DLOPEN_FLAG RTLD_LAZY

Expand All @@ -34,8 +35,9 @@
#define SMCPROTO_SMC6 1 /* SMC protocol, IPv6 */
#endif

int (*orig_socket)(int domain, int type, int protocol);
int (*orig_socket)(int domain, int type, int protocol) = NULL;
static void *dl_handle = NULL;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

static void initialize(void);

Expand Down Expand Up @@ -97,7 +99,7 @@ int socket(int domain, int type, int protocol)
{
int rc;

if (!dl_handle)
if (!orig_socket)
initialize();

/* check if socket is eligible for AF_SMC */
Expand Down Expand Up @@ -135,10 +137,17 @@ static void set_debug_mode(const char *var_name)

static void initialize(void)
{
pthread_mutex_lock(&mutex);
if (orig_socket) {
pthread_mutex_unlock(&mutex);
return;
}

set_debug_mode("SMC_DEBUG");

dl_handle = dlopen(LIBC_SO, DLOPEN_FLAG);
if (!dl_handle)
dbg_msg(stderr, "dlopen failed: %s\n", dlerror());
GET_FUNC(socket);
pthread_mutex_unlock(&mutex);
}