From 952453480f6764eb583b2507c7af83e242e0630a Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sat, 15 Sep 2018 10:15:30 +0100 Subject: [PATCH] swaybar: invalidate file descriptors upon closing --- swaybar/status_line.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/swaybar/status_line.c b/swaybar/status_line.c index 688e5947..09ed2375 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -7,12 +7,24 @@ #include #include #include "swaybar/config.h" +#include "swaybar/event_loop.h" #include "swaybar/status_line.h" #include "readline.h" +static void status_line_close_fds(struct status_line *status) { + if (status->read_fd != -1) { + remove_event(status->read_fd); + close(status->read_fd); + status->read_fd = -1; + } + if (status->write_fd != -1) { + close(status->write_fd); + status->write_fd = -1; + } +} + void status_error(struct status_line *status, const char *text) { - close(status->read_fd); - close(status->write_fd); + status_line_close_fds(status); status->protocol = PROTOCOL_ERROR; status->text = text; } @@ -123,8 +135,7 @@ struct status_line *status_line_init(char *cmd) { } void status_line_free(struct status_line *status) { - close(status->read_fd); - close(status->write_fd); + status_line_close_fds(status); kill(status->pid, SIGTERM); switch (status->protocol) { case PROTOCOL_I3BAR: {