diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-09-15 10:15:30 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-09-18 11:36:33 +0100 |
commit | 952453480f6764eb583b2507c7af83e242e0630a (patch) | |
tree | ac0b09f4190951b799940667d9ae43e7a778b44e /swaybar | |
parent | 4cb28de89fa50c2c992702c238d54d16a0269553 (diff) | |
download | sway-952453480f6764eb583b2507c7af83e242e0630a.tar.xz |
swaybar: invalidate file descriptors upon closing
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/status_line.c | 19 |
1 files 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 <unistd.h> #include <wlr/util/log.h> #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: { |