From 210148b223643753a234a0d999baf805655ee05f Mon Sep 17 00:00:00 2001 From: Michal Bursa Date: Sun, 19 Jan 2020 20:48:20 +0100 Subject: [PATCH] implement a check if tty device is working --- src/serial.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/serial.cc b/src/serial.cc index 85bae8d..3d6e3ce 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,7 @@ struct SerialDeviceTTY : public SerialDeviceImp void close(); void checkIfShouldReopen(); bool send(vector &data); + bool working(); SerialCommunicationManager *manager() { return manager_; } private: @@ -300,6 +302,20 @@ bool SerialDeviceTTY::send(vector &data) return rc; } +bool SerialDeviceTTY::working() +{ + // test if the device is working by checking if the virtual file has been deleted using stat + struct statvfs sb; + int working = (statvfs(device_.c_str(), &sb) == 0); + + if (!working) { + debug("(serial) device %s is gone\n", device_.c_str()); + } + + return working; +} + + struct SerialDeviceCommand : public SerialDeviceImp { SerialDeviceCommand(string command, vector args, vector envs,