Skip to content

Commit

Permalink
fix killing bspc processes on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyinstarlight committed Jan 2, 2017
1 parent a9af8f1 commit b38e8f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/barline.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "config.h"
#include "format.h"
#include "bspwm.h"

char fname[256];
char * monitor;
Expand Down Expand Up @@ -92,8 +93,7 @@ int main(int argc, char * argv[]) {
run = 0;
}

kill(0, SIGTERM);

bspwm_close();
format_free(format);
config_free(config);
}
35 changes: 35 additions & 0 deletions src/bspwm.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#include <poll.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/wait.h>

#include "bspwm.h"

struct bspwm_pid {
int pid;
struct bspwm_pid * next;
};

struct bspwm_pid seed = {0, NULL};
struct bspwm_pid * bspwm_pids = &seed;

int bspwm_subscribe(const char * events) {
int bspwm[2];

Expand All @@ -26,6 +35,14 @@ int bspwm_subscribe(const char * events) {
// close write end of bspwm
close(bspwm[1]);

// add pid to list
struct bspwm_pid * pid = bspwm_pids;
while (pid->next != NULL)
pid = pid->next;
pid->next = malloc(sizeof(struct bspwm_pid));
pid->next->pid = ret;
pid->next->next = NULL;

// return the read end
return bspwm[0];
}
Expand Down Expand Up @@ -215,3 +232,21 @@ int bspwm_monitor(char ** report, const char * monitor) {

return chars;
}

void bspwm_close() {
// skip first pid
struct bspwm_pid * pid = bspwm_pids->next;
struct bspwm_pid * next = pid;

while (pid != NULL) {
// kill process
kill(pid->pid, SIGTERM);

// free pid
next = pid->next;
free(pid);

// go to next pid
pid = next;
}
}
1 change: 1 addition & 0 deletions src/bspwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ void bspwm_id(enum bspwm_domain domain, const char * name, char * buf, size_t si
int bspwm_readline(int bspwmfd, char * buf, size_t size);
int bspwm_next(char ** report);
int bspwm_monitor(char ** report, const char * monitor);
void bspwm_close();
#endif

0 comments on commit b38e8f8

Please sign in to comment.