Skip to content

Commit ebae647

Browse files
elmarcokraxel
authored andcommitted
chardev: check if the chardev is registered for yanking
Not all chardevs are created via qmp_chardev_open_socket(), and those should not call the yank function registration, as this will eventually assert() not being registered. Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent 3cddb8b commit ebae647

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

chardev/char-socket.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,9 @@ static void tcp_chr_free_connection(Chardev *chr)
417417

418418
tcp_set_msgfds(chr, NULL, 0);
419419
remove_fd_in_watch(chr);
420-
if (s->state == TCP_CHARDEV_STATE_CONNECTING
421-
|| s->state == TCP_CHARDEV_STATE_CONNECTED) {
420+
if (s->registered_yank &&
421+
(s->state == TCP_CHARDEV_STATE_CONNECTING
422+
|| s->state == TCP_CHARDEV_STATE_CONNECTED)) {
422423
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
423424
yank_generic_iochannel,
424425
QIO_CHANNEL(s->sioc));
@@ -940,9 +941,11 @@ static int tcp_chr_add_client(Chardev *chr, int fd)
940941
}
941942
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
942943
tcp_chr_set_client_ioc_name(chr, sioc);
943-
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
944-
yank_generic_iochannel,
945-
QIO_CHANNEL(sioc));
944+
if (s->registered_yank) {
945+
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
946+
yank_generic_iochannel,
947+
QIO_CHANNEL(sioc));
948+
}
946949
ret = tcp_chr_new_client(chr, sioc);
947950
object_unref(OBJECT(sioc));
948951
return ret;
@@ -957,9 +960,11 @@ static void tcp_chr_accept(QIONetListener *listener,
957960

958961
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
959962
tcp_chr_set_client_ioc_name(chr, cioc);
960-
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
961-
yank_generic_iochannel,
962-
QIO_CHANNEL(cioc));
963+
if (s->registered_yank) {
964+
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
965+
yank_generic_iochannel,
966+
QIO_CHANNEL(cioc));
967+
}
963968
tcp_chr_new_client(chr, cioc);
964969
}
965970

@@ -975,9 +980,11 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp)
975980
object_unref(OBJECT(sioc));
976981
return -1;
977982
}
978-
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
979-
yank_generic_iochannel,
980-
QIO_CHANNEL(sioc));
983+
if (s->registered_yank) {
984+
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
985+
yank_generic_iochannel,
986+
QIO_CHANNEL(sioc));
987+
}
981988
tcp_chr_new_client(chr, sioc);
982989
object_unref(OBJECT(sioc));
983990
return 0;
@@ -993,9 +1000,11 @@ static void tcp_chr_accept_server_sync(Chardev *chr)
9931000
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
9941001
sioc = qio_net_listener_wait_client(s->listener);
9951002
tcp_chr_set_client_ioc_name(chr, sioc);
996-
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
997-
yank_generic_iochannel,
998-
QIO_CHANNEL(sioc));
1003+
if (s->registered_yank) {
1004+
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
1005+
yank_generic_iochannel,
1006+
QIO_CHANNEL(sioc));
1007+
}
9991008
tcp_chr_new_client(chr, sioc);
10001009
object_unref(OBJECT(sioc));
10011010
}
@@ -1124,9 +1133,11 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
11241133

11251134
if (qio_task_propagate_error(task, &err)) {
11261135
tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
1127-
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
1128-
yank_generic_iochannel,
1129-
QIO_CHANNEL(sioc));
1136+
if (s->registered_yank) {
1137+
yank_unregister_function(CHARDEV_YANK_INSTANCE(chr->label),
1138+
yank_generic_iochannel,
1139+
QIO_CHANNEL(sioc));
1140+
}
11301141
check_report_connect_error(chr, err);
11311142
goto cleanup;
11321143
}
@@ -1160,9 +1171,11 @@ static void tcp_chr_connect_client_async(Chardev *chr)
11601171
tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING);
11611172
sioc = qio_channel_socket_new();
11621173
tcp_chr_set_client_ioc_name(chr, sioc);
1163-
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
1164-
yank_generic_iochannel,
1165-
QIO_CHANNEL(sioc));
1174+
if (s->registered_yank) {
1175+
yank_register_function(CHARDEV_YANK_INSTANCE(chr->label),
1176+
yank_generic_iochannel,
1177+
QIO_CHANNEL(sioc));
1178+
}
11661179
/*
11671180
* Normally code would use the qio_channel_socket_connect_async
11681181
* method which uses a QIOTask + qio_task_set_error internally

0 commit comments

Comments
 (0)