On Mon, Mar 10, 2014 at 02:12:13PM +0200, Marcel Apfelbaum wrote:
> @@ -123,6 +125,11 @@ QTestState *qtest_init(const char *extra_args)
> sock = init_socket(socket_path);
> qmpsock = init_socket(qmp_socket_path);
>
> + setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&socket_timeout,
> + sizeof(socket_timeout));
> + setsockopt(qmpsock, SOL_SOCKET, SO_RCVTIMEO, (void *)&socket_timeout,
> + sizeof(socket_timeout));
> +
Please move this into socket_accept() so qtest_init() doesn't need to
know about setsockopt() details. It should just get an fd or -errno
return value from socket_accept()...
> s->fd = socket_accept(sock);
> - s->qmp_fd = socket_accept(qmpsock);
> + if (s->fd >= 0) {
> + s->qmp_fd = socket_accept(qmpsock);
> + }
> unlink(socket_path);
> unlink(qmp_socket_path);
...then you can ensure that we unlink the sockets even on failure.
And then something like g_assert(s->fd >= 0 && s->qmp_fd >= 0) would be
fine. The process can abort() at this point.