diff mbox series

[RFC,alsa-utils,8/9] alsactl: handle disconnection of sound card

Message ID 20181005144729.21388-9-o-takashi@sakamocchi.jp (mailing list archive)
State New, archived
Headers show
Series alsactl: monitor mode friendly for | expand

Commit Message

Takashi Sakamoto Oct. 5, 2018, 2:47 p.m. UTC
Once sound card becomes disconnection state, corresponding control node
becomes to emit error event for listeners. When catching this type of
event, event dispatcher should stop observation of the node. However,
at present, a mode of monitor can't handle this correctly. As a result,
poll(2) is executed quite frequently in loop with no wait. This results
100% consumption of CPU time.

This commit takes the dispatcher to remove the node from observation
list when detecting the disconnection state.

Reported-by: Thomas Gläßle <thomas@coldfix.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 alsactl/monitor.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/alsactl/monitor.c b/alsactl/monitor.c
index 807963c..4eb1ad1 100644
--- a/alsactl/monitor.c
+++ b/alsactl/monitor.c
@@ -312,6 +312,10 @@  static int run_dispatcher(int epfd, struct src_entry *srcs)
 			struct src_entry *src = (struct src_entry *)ev->data.ptr;
 			if (ev->events & EPOLLIN)
 				print_event(src->handle, src->name);
+			if (ev->events & EPOLLERR) {
+				operate_dispatcher(epfd, EPOLL_CTL_DEL, NULL, src);
+				remove_source_entry(src);
+			}
 		}
 	}