Skip to content

Commit

Permalink
bmlipc: use the abstract namespace instead of a filesystem entry
Browse files Browse the repository at this point in the history
This lets us avoid the call to the not recommended mktemp() function.
Fixes #51
  • Loading branch information
ensonic committed Jun 22, 2015
1 parent 708b3a1 commit 710420b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/lib/bml/bml.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ bmpipc_connect (void)
return FALSE;
}
address.sun_family = PF_LOCAL;
strcpy (address.sun_path, socket_file);
strcpy (&address.sun_path[1], socket_file);
while (retries < 3) {
int res;
if ((res =
connect (server_socket, (struct sockaddr *) &address,
sizeof (address))) == 0) {
sizeof (sa_family_t) + strlen (socket_file) + 1)) == 0) {
TRACE ("server connected after %d retries\n", retries);
break;
} else {
Expand Down Expand Up @@ -750,12 +750,10 @@ bml_setup (void)
#ifdef DEV_BUILD
if (getenv ("BMLIPC_DEBUG")) {
// allows to run this manually, we will then not spawn a new one here
snprintf (socket_file, (SOCKET_PATH_MAX - 1), "/tmp/bml.sock");
snprintf (socket_file, (SOCKET_PATH_MAX - 1), "bml.sock");
} else {
#endif
snprintf (socket_file, (SOCKET_PATH_MAX - 1), "/tmp/bml.%d.XXXXXX",
(int) getpid ());
mktemp (socket_file);
snprintf (socket_file, (SOCKET_PATH_MAX - 1), "bml.%d", (int) getpid ());
#ifdef DEV_BUILD
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions src/lib/bml/bmlhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ main (int argc, char **argv)
int server_socket, client_socket;
socklen_t addrlen;
ssize_t size;
struct sockaddr_un address;
struct sockaddr_un address = { 0, };
int running = TRUE;
BmlIpcBuf bo = IPC_BUF_INIT, bi = IPC_BUF_INIT;
BmAPI id;
Expand All @@ -426,8 +426,9 @@ main (int argc, char **argv)

unlink (socket_file);
address.sun_family = PF_LOCAL;
strcpy (address.sun_path, socket_file);
if (bind (server_socket, (struct sockaddr *) &address, sizeof (address)) != 0) {
strcpy (&address.sun_path[1], socket_file);
if (bind (server_socket, (struct sockaddr *) &address,
sizeof (sa_family_t) + strlen (socket_file) + 1) != 0) {
TRACE ("socket path already in use!\n");
}
listen (server_socket, /* backlog of pending connections */ 5);
Expand Down

0 comments on commit 710420b

Please sign in to comment.