From ad9a011a075ae2ff64c5110c6ea9c288fa3bfe17 Mon Sep 17 00:00:00 2001 From: Harshit Jain Date: Fri, 4 May 2018 14:54:37 +0530 Subject: [PATCH] wayne: light: Throw a warning if path stream ain't valid --- light/Light.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/light/Light.cpp b/light/Light.cpp index c170ae2a..786e8c24 100644 --- a/light/Light.cpp +++ b/light/Light.cpp @@ -39,7 +39,14 @@ namespace implementation { */ static void set(std::string path, std::string value) { std::ofstream file(path); - file << value; + /* Only write brightness value if stream is open, alive & well */ + if (file.is_open()) { + file << value; + } else { + /* Fire a warning a bail out */ + ALOGE("failed to write %s to %s", value.c_str(), path.c_str()); + return; + } } static void set(std::string path, int value) {