aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/status_line.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/status_line.c')
-rw-r--r--swaybar/status_line.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index ecd91032..e542e606 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 1#include <assert.h>
3#include <fcntl.h> 2#include <fcntl.h>
4#include <sys/ioctl.h> 3#include <sys/ioctl.h>
@@ -117,11 +116,11 @@ bool status_handle_readable(struct status_line *status) {
117 status->text = status->buffer; 116 status->text = status->buffer;
118 // intentional fall-through 117 // intentional fall-through
119 case PROTOCOL_TEXT: 118 case PROTOCOL_TEXT:
120 errno = 0;
121 while (true) { 119 while (true) {
122 if (status->buffer[read_bytes - 1] == '\n') { 120 if (status->buffer[read_bytes - 1] == '\n') {
123 status->buffer[read_bytes - 1] = '\0'; 121 status->buffer[read_bytes - 1] = '\0';
124 } 122 }
123 errno = 0;
125 read_bytes = getline(&status->buffer, 124 read_bytes = getline(&status->buffer,
126 &status->buffer_size, status->read); 125 &status->buffer_size, status->read);
127 if (errno == EAGAIN) { 126 if (errno == EAGAIN) {
@@ -157,7 +156,12 @@ struct status_line *status_line_init(char *cmd) {
157 assert(!getenv("WAYLAND_SOCKET") && "display must be initialized before " 156 assert(!getenv("WAYLAND_SOCKET") && "display must be initialized before "
158 " starting `status-command`; WAYLAND_SOCKET should not be set"); 157 " starting `status-command`; WAYLAND_SOCKET should not be set");
159 status->pid = fork(); 158 status->pid = fork();
160 if (status->pid == 0) { 159 if (status->pid < 0) {
160 sway_log_errno(SWAY_ERROR, "fork failed");
161 exit(1);
162 } else if (status->pid == 0) {
163 setpgid(0, 0);
164
161 dup2(pipe_read_fd[1], STDOUT_FILENO); 165 dup2(pipe_read_fd[1], STDOUT_FILENO);
162 close(pipe_read_fd[0]); 166 close(pipe_read_fd[0]);
163 close(pipe_read_fd[1]); 167 close(pipe_read_fd[1]);
@@ -185,8 +189,8 @@ struct status_line *status_line_init(char *cmd) {
185 189
186void status_line_free(struct status_line *status) { 190void status_line_free(struct status_line *status) {
187 status_line_close_fds(status); 191 status_line_close_fds(status);
188 kill(status->pid, status->cont_signal); 192 kill(-status->pid, status->cont_signal);
189 kill(status->pid, SIGTERM); 193 kill(-status->pid, SIGTERM);
190 waitpid(status->pid, NULL, 0); 194 waitpid(status->pid, NULL, 0);
191 if (status->protocol == PROTOCOL_I3BAR) { 195 if (status->protocol == PROTOCOL_I3BAR) {
192 struct i3bar_block *block, *tmp; 196 struct i3bar_block *block, *tmp;