From 5833dd5dd9b936950d3f52f678a60d638ef33ad8 Mon Sep 17 00:00:00 2001 From: Marcel Alexandru Nitan Date: Tue, 31 Jan 2023 21:22:18 +0200 Subject: [PATCH] util: report write errors in sysfs_write --- src/util.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index a7bc911..f2f7efe 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -59,11 +59,19 @@ void sysfs_write(char *path, char *content) { std::cout << "Write: " << content << " -> " << path << std::endl; int fd; - fd = open(path, O_WRONLY); - write(fd, content, strlen(content)); + if (fd = open(path, O_WRONLY) == -1) + { + perror("Failed to open sysfs file"); + return; + } + if (write(fd, content, strlen(content) == -1)) + { + perror("Failed to write sysfs file"); + } close(fd); } + char *getprop(char *key) { std::array buffer;