aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-11 12:43:34 -0500
committerLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-06-11 12:43:34 -0500
commit2298143d09ce8810d9772f95e1cb605fb6b08536 (patch)
treed1b4fb33848d09c71602005c57919a903ce3d72d /common
parentMerge branch 'master' into assign-command (diff)
downloadsway-2298143d09ce8810d9772f95e1cb605fb6b08536.tar.gz
sway-2298143d09ce8810d9772f95e1cb605fb6b08536.tar.zst
sway-2298143d09ce8810d9772f95e1cb605fb6b08536.zip
cleanup + add timeouts for pid_workspace list
Diffstat (limited to 'common')
-rw-r--r--common/util.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/common/util.c b/common/util.c
index e760443a..12cb7470 100644
--- a/common/util.c
+++ b/common/util.c
@@ -74,30 +74,22 @@ pid_t get_parent_pid(pid_t child) {
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;
77 const char sep[2] = " "; 77 const char *sep = " ";
78 FILE *stat = NULL; 78 FILE *stat = NULL;
79 79
80 sway_log(L_DEBUG, "trying to get parent pid for child pid %d", child);
81
82 sprintf(file_name, "/proc/%d/stat", child); 80 sprintf(file_name, "/proc/%d/stat", child);
83 81
84 if (!(stat = fopen(file_name, "r")) || !(buffer = read_line(stat))) { 82 if ((stat = fopen(file_name, "r")) && (buffer = read_line(stat))) {
85 return -1; 83 fclose(stat);
86 }
87
88 fclose(stat);
89 84
90 sway_log(L_DEBUG, "buffer string is %s", buffer); 85 token = strtok(buffer, sep); // pid
86 token = strtok(NULL, sep); // executable name
87 token = strtok(NULL, sep); // state
88 token = strtok(NULL, sep); // parent pid
91 89
92 token = strtok(buffer, sep); 90 parent = strtol(token, NULL, 10);
93 91 return (parent == child) ? -1 : parent;
94 for (int i = 0; i < 3; i++) {
95 token = strtok(NULL, sep);
96 } 92 }
97 93
98 parent = strtol(token, NULL, 10); 94 return -1;
99
100 sway_log(L_DEBUG, "found parent pid %d for child pid %d", parent, child);
101
102 return (parent == child) ? -1 : parent;
103} 95}