summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-06-11 15:29:04 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-06-11 15:29:04 -0500
commit9ecb43ea3b772b7c0e088343b530ab374af3bb9e (patch)
tree3c429a61e9e56bd1adb7ac95f375ac78ae09e888
parentcleanup + add timeouts for pid_workspace list (diff)
downloadsway-9ecb43ea3b772b7c0e088343b530ab374af3bb9e.tar.gz
sway-9ecb43ea3b772b7c0e088343b530ab374af3bb9e.tar.zst
sway-9ecb43ea3b772b7c0e088343b530ab374af3bb9e.zip
couple small fixes
-rw-r--r--common/util.c20
-rw-r--r--sway/config.c2
2 files changed, 14 insertions, 8 deletions
diff --git a/common/util.c b/common/util.c
index 12cb7470..31a75a9b 100644
--- a/common/util.c
+++ b/common/util.c
@@ -70,7 +70,7 @@ int get_modifier_names(const char **names, uint32_t modifier_masks) {
70} 70}
71 71
72pid_t get_parent_pid(pid_t child) { 72pid_t get_parent_pid(pid_t child) {
73 pid_t parent; 73 pid_t parent = -1;
74 char file_name[100]; 74 char file_name[100];
75 char *buffer = NULL; 75 char *buffer = NULL;
76 char *token = NULL; 76 char *token = NULL;
@@ -79,15 +79,19 @@ pid_t get_parent_pid(pid_t child) {
79 79
80 sprintf(file_name, "/proc/%d/stat", child); 80 sprintf(file_name, "/proc/%d/stat", child);
81 81
82 if ((stat = fopen(file_name, "r")) && (buffer = read_line(stat))) { 82 if ((stat = fopen(file_name, "r"))) {
83 fclose(stat); 83 if ((buffer = read_line(stat))) {
84 token = strtok(buffer, sep); // pid
85 token = strtok(NULL, sep); // executable name
86 token = strtok(NULL, sep); // state
87 token = strtok(NULL, sep); // parent pid
88 parent = strtol(token, NULL, 10);
89 }
84 90
85 token = strtok(buffer, sep); // pid 91 fclose(stat);
86 token = strtok(NULL, sep); // executable name 92 }
87 token = strtok(NULL, sep); // state
88 token = strtok(NULL, sep); // parent pid
89 93
90 parent = strtol(token, NULL, 10); 94 if (parent) {
91 return (parent == child) ? -1 : parent; 95 return (parent == child) ? -1 : parent;
92 } 96 }
93 97
diff --git a/sway/config.c b/sway/config.c
index 819a70ce..766d2b23 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -101,6 +101,7 @@ static void pid_workspace_cleanup() {
101 pw = config->pid_workspaces->items[i]; 101 pw = config->pid_workspaces->items[i];
102 102
103 if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) { 103 if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
104 free_pid_workspace(config->pid_workspaces->items[i]);
104 list_del(config->pid_workspaces, i); 105 list_del(config->pid_workspaces, i);
105 } 106 }
106 } 107 }
@@ -126,6 +127,7 @@ void pid_workspace_add(struct pid_workspace *pw) {
126 list_pw = config->pid_workspaces->items[i]; 127 list_pw = config->pid_workspaces->items[i];
127 128
128 if (pw->pid == list_pw->pid) { 129 if (pw->pid == list_pw->pid) {
130 free_pid_workspace(config->pid_workspaces->items[i]);
129 list_del(config->pid_workspaces, i); 131 list_del(config->pid_workspaces, i);
130 } 132 }
131 } 133 }