From 84ef765db3bd05895f9a209b98c08dd6491c24ed Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 24 Jun 2018 15:03:34 +0200 Subject: [PATCH] rcinput: try harder to reacquire input device During lirc package update, the input device was sometimes lost and not reacquired. Try to reacquire also if setKeyRepeatDelay fails. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/2422cecfd1cd70c5eac14786ec8ac508f09020b5 Author: Stefan Seyfried Date: 2018-06-24 (Sun, 24 Jun 2018) ------------------ This commit was generated by Migit --- src/driver/rcinput.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 410527b03..11681319b 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -1775,7 +1775,10 @@ void CRCInput::setKeyRepeatDelay(unsigned int start_ms, unsigned int repeat_ms) _start_ms = start_ms; _repeat_ms = repeat_ms; } - for (std::vector::iterator it = indev.begin(); it != indev.end(); ++it) { + /* iterate backwards or the vector will be corrupted by the indev.erase(i) */ + std::vector::iterator it = indev.end(); + while (it != indev.begin()) { + --it; int fd = (*it).fd; std::string path = (*it).path; if (path == "/tmp/neutrino.input") @@ -1799,8 +1802,17 @@ void CRCInput::setKeyRepeatDelay(unsigned int start_ms, unsigned int repeat_ms) * rcinput loop into accepting the key event... */ ie.value = start_ms + 10; ie.code = REP_DELAY; - if (write(fd, &ie, sizeof(ie)) == -1) + if (write(fd, &ie, sizeof(ie)) == -1) { + if (errno == ENODEV) { + printf("[rcinput:%s] %s(fd %d) ENODEV??\n", __func__, path.c_str(), fd); + /* hot-unplugged? */ + ::close(fd); + it = indev.erase(it); + devinput_mtime.tv_sec = 0; /* force check */ + continue; + } printf("[rcinput:%s] %s(fd %d) write %s: %m\n", __func__, path.c_str(), fd, "REP_DELAY"); + } ie.value = repeat_ms + 10; ie.code = REP_PERIOD;