eliminate excessive journal errors
When the USB gadget is shut down, the application needs to avoid writes
to it in order to avoid lots of errors in the kernel log. Close the file
handle and re-open it when timings are detected again. Also, prevent
logging the failed timings query more than once.
Change-Id: Ic126828fe26ef44ebb0a5cb65cc47b23bb84f7f3
Signed-off-by: Eddie James <eajames@linux.ibm.com>
diff --git a/ikvm_input.cpp b/ikvm_input.cpp
index 202b761..30deea6 100644
--- a/ikvm_input.cpp
+++ b/ikvm_input.cpp
@@ -156,6 +156,36 @@
rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
}
+void Input::restart()
+{
+ if (!keyboardPath.empty() && keyboardFd < 0)
+ {
+ keyboardFd = open(keyboardPath.c_str(), O_RDWR | O_CLOEXEC);
+ if (keyboardFd < 0)
+ {
+ log<level::ERR>("Failed to open input device",
+ entry("PATH=%s", keyboardPath.c_str()),
+ entry("ERROR=%s", strerror(errno)));
+ }
+
+ sendKeyboard = false;
+ }
+
+ if (!pointerPath.empty() && pointerFd < 0)
+ {
+ pointerFd = open(pointerPath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK);
+ if (pointerFd < 0)
+ {
+ log<level::ERR>("Failed to open input device",
+ entry("PATH=%s", pointerPath.c_str()),
+ entry("ERROR=%s", strerror(errno)));
+ }
+
+ pointerError = false;
+ sendPointer = false;
+ }
+}
+
void Input::sendWakeupPacket()
{
uint8_t wakeupReport[KEY_REPORT_LENGTH] = {0};
@@ -209,6 +239,12 @@
{
log<level::ERR>("Failed to write keyboard report",
entry("ERROR=%s", strerror(errno)));
+
+ if (errno == ESHUTDOWN)
+ {
+ close(keyboardFd);
+ keyboardFd = -1;
+ }
}
sendKeyboard = false;
@@ -225,6 +261,16 @@
entry("ERROR=%s", strerror(errno)));
pointerError = true;
}
+
+ if (errno == ESHUTDOWN)
+ {
+ close(pointerFd);
+ pointerFd = -1;
+ }
+ }
+ else
+ {
+ pointerError = false;
}
sendPointer = false;
diff --git a/ikvm_input.hpp b/ikvm_input.hpp
index 394591c..99170ba 100644
--- a/ikvm_input.hpp
+++ b/ikvm_input.hpp
@@ -48,6 +48,8 @@
*/
static void pointerEvent(int buttonMask, int x, int y, rfbClientPtr cl);
+ /* @brief Re-opens USB device in case the endpoint shutdown */
+ void restart();
/* @brief Sends a wakeup data packet to the USB input device */
void sendWakeupPacket();
/* @brief Sends an HID report to the USB input device */
diff --git a/ikvm_video.cpp b/ikvm_video.cpp
index 39947c6..6a5aa6c 100644
--- a/ikvm_video.cpp
+++ b/ikvm_video.cpp
@@ -31,8 +31,8 @@
using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
Video::Video(const std::string& p, Input& input, int fr) :
- resizeAfterOpen(false), fd(-1), frameRate(fr), lastFrameIndex(-1),
- height(600), width(800), input(input), path(p)
+ resizeAfterOpen(false), timingsError(false), fd(-1), frameRate(fr),
+ lastFrameIndex(-1), height(600), width(800), input(input), path(p)
{
}
@@ -153,11 +153,21 @@
rc = ioctl(fd, VIDIOC_QUERY_DV_TIMINGS, &timings);
if (rc < 0)
{
- log<level::ERR>("Failed to query timings",
- entry("ERROR=%s", strerror(errno)));
+ if (!timingsError)
+ {
+ log<level::ERR>("Failed to query timings",
+ entry("ERROR=%s", strerror(errno)));
+ timingsError = true;
+ }
+
restart();
return false;
}
+ else if (timingsError)
+ {
+ timingsError = false;
+ input.restart();
+ }
if (timings.bt.width != width || timings.bt.height != height)
{
diff --git a/ikvm_video.hpp b/ikvm_video.hpp
index faaa57d..fb8c5da 100644
--- a/ikvm_video.hpp
+++ b/ikvm_video.hpp
@@ -129,6 +129,8 @@
* the open operation
*/
bool resizeAfterOpen;
+ /* @brief Indicates whether or not timings query was last sucessful */
+ bool timingsError;
/* @brief File descriptor for the V4L2 video device */
int fd;
/* @brief Desired frame rate of video stream in frames per second */