From 3bdad1b302a3ca1d22b0eaeaca1f8957bec1ffe8 Mon Sep 17 00:00:00 2001 From: Michal Bursa Date: Sun, 19 Jan 2020 22:47:05 +0100 Subject: [PATCH] SerialDeviceTTY::working() now uses fstat() to see if device is working --- src/serial.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/serial.cc b/src/serial.cc index 3d6e3ce..de9890e 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -304,9 +304,11 @@ bool SerialDeviceTTY::send(vector &data) bool SerialDeviceTTY::working() { + if (fd_ == -1) return false; + // 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); + struct stat sb; + int working = (fstat(fd_, &sb) == 0); if (!working) { debug("(serial) device %s is gone\n", device_.c_str());