mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Merge pull request #3389 from sigiesec/fix-issue-3387
Problem: close always fails with wildcard bind, since directory is no…
This commit is contained in:
commit
0b4bb92395
@ -249,11 +249,17 @@ int zmq::ipc_listener_t::close ()
|
|||||||
_s = retired_fd;
|
_s = retired_fd;
|
||||||
|
|
||||||
if (_has_file && options.use_fd == -1) {
|
if (_has_file && options.use_fd == -1) {
|
||||||
rc = 0;
|
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 && !_tmp_socket_dirname.empty ()) {
|
if (rc == 0) {
|
||||||
rc = ::rmdir (_tmp_socket_dirname.c_str ());
|
rc = ::rmdir (_tmp_socket_dirname.c_str ());
|
||||||
_tmp_socket_dirname.clear ();
|
_tmp_socket_dirname.clear ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
|
@ -44,20 +44,8 @@ void tearDown ()
|
|||||||
|
|
||||||
void test_rebind_ipc ()
|
void test_rebind_ipc ()
|
||||||
{
|
{
|
||||||
char my_endpoint[32], random_file[16];
|
char my_endpoint[32];
|
||||||
strcpy (random_file, "tmpXXXXXX");
|
make_random_ipc_endpoint (my_endpoint);
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
void *sb0 = test_context_socket (ZMQ_PUSH);
|
void *sb0 = test_context_socket (ZMQ_PUSH);
|
||||||
void *sb1 = 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)
|
void test_reconnect_ivl_ipc (void)
|
||||||
{
|
{
|
||||||
char my_endpoint[256];
|
char my_endpoint[256];
|
||||||
size_t len = sizeof (my_endpoint);
|
make_random_ipc_endpoint (my_endpoint);
|
||||||
|
|
||||||
void *sb = test_context_socket (ZMQ_PAIR);
|
void *sb = test_context_socket (ZMQ_PAIR);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*"));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, my_endpoint));
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (
|
|
||||||
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
|
||||||
|
|
||||||
test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
|
test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
|
||||||
test_context_socket_close (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_);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user