Unverified Commit 0b4bb923 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3389 from sigiesec/fix-issue-3387

Problem: close always fails with wildcard bind, since directory is no…
parents b14bb2d8 8d784f26
......@@ -249,11 +249,17 @@ int zmq::ipc_listener_t::close ()
_s = retired_fd;
if (_has_file && options.use_fd == -1) {
rc = 0;
if (rc == 0 && !_tmp_socket_dirname.empty ()) {
rc = ::rmdir (_tmp_socket_dirname.c_str ());
_tmp_socket_dirname.clear ();
if (!_tmp_socket_dirname.empty ()) {
// TODO review this behaviour, it is inconsistent with the use of
// unlink in open since 656cdb959a7482c45db979c1d08ede585d12e315;
// however, we must at least remove the file before removing the
// directory, otherwise it will always fail
rc = ::unlink (_filename.c_str ());
if (rc == 0) {
rc = ::rmdir (_tmp_socket_dirname.c_str ());
_tmp_socket_dirname.clear ();
}
}
if (rc != 0) {
......
......@@ -44,20 +44,8 @@ void tearDown ()
void test_rebind_ipc ()
{
char my_endpoint[32], random_file[16];
strcpy (random_file, "tmpXXXXXX");
#ifdef HAVE_MKDTEMP
TEST_ASSERT_TRUE (mkdtemp (random_file));
strcat (random_file, "/ipc");
#else
int fd = mkstemp (random_file);
TEST_ASSERT_TRUE (fd != -1);
close (fd);
#endif
strcpy (my_endpoint, "ipc://");
strcat (my_endpoint, random_file);
char my_endpoint[32];
make_random_ipc_endpoint (my_endpoint);
void *sb0 = test_context_socket (ZMQ_PUSH);
void *sb1 = test_context_socket (ZMQ_PUSH);
......
......@@ -72,12 +72,10 @@ void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_,
void test_reconnect_ivl_ipc (void)
{
char my_endpoint[256];
size_t len = sizeof (my_endpoint);
make_random_ipc_endpoint (my_endpoint);
void *sb = test_context_socket (ZMQ_PAIR);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, my_endpoint));
test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
test_context_socket_close (sb);
......
......@@ -326,3 +326,23 @@ void bind_loopback_ipv6 (void *socket_, char *my_endpoint_, size_t len_)
{
bind_loopback (socket_, true, my_endpoint_, len_);
}
// utility function to create a random IPC endpoint, similar to what a ipc://*
// wildcard binding does, but in a way it can be reused for multiple binds
void make_random_ipc_endpoint (char *out_endpoint_)
{
char random_file[16];
strcpy (random_file, "tmpXXXXXX");
#ifdef HAVE_MKDTEMP
TEST_ASSERT_TRUE (mkdtemp (random_file));
strcat (random_file, "/ipc");
#else
int fd = mkstemp (random_file);
TEST_ASSERT_TRUE (fd != -1);
close (fd);
#endif
strcpy (out_endpoint_, "ipc://");
strcat (out_endpoint_, random_file);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment