json-stream: do not take ownership of passed fds on failure
This makes json_stream_attach_fds() and json_stream_connect_fd_pair() leave the passed file descriptors with the caller on failure. Callers should call TAKE_FD() only after a successful call. Also make qmp_client_connect_fd() always take ownership of the passed file descriptor, including on failure. Previously, ownership of the passed file descriptor on failure was unclear and depended on where the function failed.
This commit is contained in:
@@ -123,12 +123,11 @@ TEST(qmp_client_qemu_handshake_and_schema) {
|
||||
ASSERT_OK(start_qemu(qemu, qmp_fds[1], &pidref));
|
||||
qmp_fds[1] = safe_close(qmp_fds[1]);
|
||||
|
||||
r = qmp_client_connect_fd(&client, qmp_fds[0]);
|
||||
r = qmp_client_connect_fd(&client, TAKE_FD(qmp_fds[0]));
|
||||
if (r < 0) {
|
||||
log_tests_skipped_errno(r, "QMP connect failed (QEMU may not support -machine none)");
|
||||
return;
|
||||
}
|
||||
TAKE_FD(qmp_fds[0]);
|
||||
|
||||
ASSERT_OK(qmp_client_attach_event(client, event, SD_EVENT_PRIORITY_NORMAL));
|
||||
|
||||
@@ -187,12 +186,11 @@ TEST(qmp_client_qemu_query_status) {
|
||||
ASSERT_OK(start_qemu(qemu, qmp_fds[1], &pidref));
|
||||
qmp_fds[1] = safe_close(qmp_fds[1]);
|
||||
|
||||
r = qmp_client_connect_fd(&client, qmp_fds[0]);
|
||||
r = qmp_client_connect_fd(&client, TAKE_FD(qmp_fds[0]));
|
||||
if (r < 0) {
|
||||
log_tests_skipped_errno(r, "QMP connect failed");
|
||||
return;
|
||||
}
|
||||
TAKE_FD(qmp_fds[0]);
|
||||
|
||||
ASSERT_OK(qmp_client_attach_event(client, event, SD_EVENT_PRIORITY_NORMAL));
|
||||
|
||||
@@ -277,12 +275,11 @@ TEST(qmp_client_qemu_add_fd) {
|
||||
ASSERT_OK(start_qemu(qemu, qmp_fds[1], &pidref));
|
||||
qmp_fds[1] = safe_close(qmp_fds[1]);
|
||||
|
||||
r = qmp_client_connect_fd(&client, qmp_fds[0]);
|
||||
r = qmp_client_connect_fd(&client, TAKE_FD(qmp_fds[0]));
|
||||
if (r < 0) {
|
||||
log_tests_skipped_errno(r, "QMP connect failed");
|
||||
return;
|
||||
}
|
||||
TAKE_FD(qmp_fds[0]);
|
||||
|
||||
ASSERT_OK(qmp_client_attach_event(client, event, SD_EVENT_PRIORITY_NORMAL));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user