2017-03-15 Florian Weimer <fweimer@redhat.com>
+ [BZ #21244]
+ * support/xclose.c: New file.
+ * support/Makefile (libsupport-routines): Add xclose.
+ * support/xunistd.h (xclose): Declare.
+ * support/resolv_test.c (server_thread_tcp_client)
+ (server_thread_tcp, make_server_sockets, resolv_test_start)
+ (resolv_test_end): Call xclose instead of close.
+ * support/support_enter_network_namespace.c
+ (support_enter_network_namespace): Likewise.
+ * support/support_run_diff.c (write_to_temp_file): Likewise.
+
+2017-03-15 Florian Weimer <fweimer@redhat.com>
+
* support/support_format_dns_packet.c (support_format_dns_packet):
Handle CNAME records in the response. Extract RDATA names from
rdata, not the whole packet. Check AAAA record length.
xasprintf \
xbind \
xcalloc \
+ xclose \
xconnect \
xfclose \
xfopen \
#include <support/test-driver.h>
#include <support/xsocket.h>
#include <support/xthread.h>
+#include <support/xunistd.h>
#include <unistd.h>
-/* Response builder. */
+/* Response builder. */
enum
{
break;
}
- close (closure->client_socket);
+ xclose (closure->client_socket);
free (closure);
return NULL;
}
if (obj->termination_requested)
{
xpthread_mutex_unlock (&obj->lock);
- close (client_socket);
+ xclose (client_socket);
break;
}
xpthread_mutex_unlock (&obj->lock);
next local UDP address randomly. */
if (errno == EADDRINUSE)
{
- close (server->socket_udp);
- close (server->socket_tcp);
+ xclose (server->socket_udp);
+ xclose (server->socket_tcp);
continue;
}
FAIL_EXIT1 ("TCP bind: %m");
struct resolv_test_server *server = obj->servers + server_index;
if (config.servers[server_index].disable_udp)
{
- close (server->socket_udp);
+ xclose (server->socket_udp);
server->socket_udp = -1;
}
else if (!config.single_thread_udp)
server_thread_udp);
if (config.servers[server_index].disable_tcp)
{
- close (server->socket_tcp);
+ xclose (server->socket_tcp);
server->socket_tcp = -1;
}
else
xsendto (sock, "", 1, 0,
(struct sockaddr *) &obj->servers[server_index].address,
sizeof (obj->servers[server_index].address));
- close (sock);
+ xclose (sock);
}
if (!obj->config.servers[server_index].disable_tcp)
{
xconnect (sock,
(struct sockaddr *) &obj->servers[server_index].address,
sizeof (obj->servers[server_index].address));
- close (sock);
+ xclose (sock);
}
}
{
if (!obj->config.single_thread_udp)
xpthread_join (obj->servers[server_index].thread_udp);
- close (obj->servers[server_index].socket_udp);
+ xclose (obj->servers[server_index].socket_udp);
}
if (!obj->config.servers[server_index].disable_tcp)
{
xpthread_join (obj->servers[server_index].thread_tcp);
- close (obj->servers[server_index].socket_tcp);
+ xclose (obj->servers[server_index].socket_tcp);
}
}
#include <stdio.h>
#include <string.h>
#include <support/check.h>
+#include <support/xsocket.h>
+#include <support/xunistd.h>
#include <sys/ioctl.h>
#include <unistd.h>
-#include <xsocket.h>
static bool in_uts_namespace;
req.ifr_flags |= IFF_UP | IFF_RUNNING;
TEST_VERIFY_EXIT (ioctl (fd, SIOCSIFFLAGS, &req) == 0);
}
- close (fd);
+ xclose (fd);
return !already_up;
}
#include <support/check.h>
#include <support/support.h>
#include <support/temp_file.h>
+#include <support/xunistd.h>
#include <sys/wait.h>
-#include <xunistd.h>
static char *
write_to_temp_file (const char *prefix, const char *str)
TEST_VERIFY_EXIT (fd >= 0);
free (template);
xwrite (fd, str, strlen (str));
- TEST_VERIFY_EXIT (close (fd) == 0);
+ xclose (fd);
return name;
}
--- /dev/null
+/* close with error checking.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/xunistd.h>
+#include <support/check.h>
+#include <errno.h>
+
+void
+xclose (int fd)
+{
+ if (close (fd) < 0 && errno != EINTR)
+ FAIL_EXIT1 ("close of descriptor %d failed: %m", fd);
+}
pid_t xfork (void);
pid_t xwaitpid (pid_t, int *status, int flags);
+/* Close the file descriptor. Ignore EINTR errors, but terminate the
+ process on other errors. */
+void xclose (int);
+
/* Write the buffer. Retry on short writes. */
void xwrite (int, const void *, size_t);