From 17bb5643aec1ec67d7a0c45bfc91ad806b842a75 Mon Sep 17 00:00:00 2001 From: mazunki Date: Tue, 9 Nov 2021 18:38:07 +0100 Subject: [PATCH] explicitly checking for errors to silence unused variable warnings when writing to fd --- include/util/command.hpp | 4 +++- src/modules/sway/ipc/client.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/util/command.hpp b/include/util/command.hpp index 3a38da3..d3a1e43 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -68,7 +68,9 @@ inline int close(FILE* fp, pid_t pid) { inline FILE* open(const std::string& cmd, int& pid) { if (cmd == "") return nullptr; int fd[2]; - pipe(fd); + if (pipe(fd) != 0){ + throw std::runtime_error("Couldn't open a file descriptor"); + } pid_t child_pid = fork(); diff --git a/src/modules/sway/ipc/client.cpp b/src/modules/sway/ipc/client.cpp index 58aed60..1111746 100644 --- a/src/modules/sway/ipc/client.cpp +++ b/src/modules/sway/ipc/client.cpp @@ -14,12 +14,16 @@ Ipc::~Ipc() { if (fd_ > 0) { // To fail the IPC header - write(fd_, "close-sway-ipc", 14); + if (write(fd_, "close-sway-ipc", 14) == -1) { + std::runtime_error("Couldn't close Sway IPC through fd"); + } close(fd_); fd_ = -1; } if (fd_event_ > 0) { - write(fd_event_, "close-sway-ipc", 14); + if (write(fd_event_, "close-sway-ipc", 14) == -1) { + std::runtime_error("Couldn't close Sway IPC through fd_event"); + } close(fd_event_); fd_event_ = -1; }