+ struct stat st;
+
+ TMTY_LOG(DEBUG, "Initial bind to socket '%s' failed.\n", path);
+
+ /* first check if we have a runtime dir */
+ if (stat(socket_dir, &st) < 0 || !S_ISDIR(st.st_mode)) {
+ TMTY_LOG(ERR, "Cannot access DPDK runtime directory: %s\n", socket_dir);
+ close(sock);
+ return -ENOENT;
+ }
+
+ /* check if current socket is active */
+ if (connect(sock, (void *)&sun, sizeof(sun)) == 0) {
+ close(sock);
+ return -EADDRINUSE;
+ }
+
+ /* socket is not active, delete and attempt rebind */
+ TMTY_LOG(DEBUG, "Attempting unlink and retrying bind\n");
+ unlink(sun.sun_path);
+ if (bind(sock, (void *) &sun, sizeof(sun)) < 0) {
+ TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno));
+ close(sock);
+ return -errno; /* if unlink failed, this will be -EADDRINUSE as above */
+ }