couple small fixes

This commit is contained in:
Zandr Martin 2016-06-11 15:29:04 -05:00
parent 2298143d09
commit 9ecb43ea3b
No known key found for this signature in database
GPG key ID: AA2BB8EF77F7BBDC
2 changed files with 14 additions and 8 deletions

View file

@ -70,7 +70,7 @@ int get_modifier_names(const char **names, uint32_t modifier_masks) {
} }
pid_t get_parent_pid(pid_t child) { pid_t get_parent_pid(pid_t child) {
pid_t parent; pid_t parent = -1;
char file_name[100]; char file_name[100];
char *buffer = NULL; char *buffer = NULL;
char *token = NULL; char *token = NULL;
@ -79,15 +79,19 @@ pid_t get_parent_pid(pid_t child) {
sprintf(file_name, "/proc/%d/stat", child); sprintf(file_name, "/proc/%d/stat", child);
if ((stat = fopen(file_name, "r")) && (buffer = read_line(stat))) { if ((stat = fopen(file_name, "r"))) {
if ((buffer = read_line(stat))) {
token = strtok(buffer, sep); // pid
token = strtok(NULL, sep); // executable name
token = strtok(NULL, sep); // state
token = strtok(NULL, sep); // parent pid
parent = strtol(token, NULL, 10);
}
fclose(stat); fclose(stat);
}
token = strtok(buffer, sep); // pid if (parent) {
token = strtok(NULL, sep); // executable name
token = strtok(NULL, sep); // state
token = strtok(NULL, sep); // parent pid
parent = strtol(token, NULL, 10);
return (parent == child) ? -1 : parent; return (parent == child) ? -1 : parent;
} }

View file

@ -101,6 +101,7 @@ static void pid_workspace_cleanup() {
pw = config->pid_workspaces->items[i]; pw = config->pid_workspaces->items[i];
if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) { if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
free_pid_workspace(config->pid_workspaces->items[i]);
list_del(config->pid_workspaces, i); list_del(config->pid_workspaces, i);
} }
} }
@ -126,6 +127,7 @@ void pid_workspace_add(struct pid_workspace *pw) {
list_pw = config->pid_workspaces->items[i]; list_pw = config->pid_workspaces->items[i];
if (pw->pid == list_pw->pid) { if (pw->pid == list_pw->pid) {
free_pid_workspace(config->pid_workspaces->items[i]);
list_del(config->pid_workspaces, i); list_del(config->pid_workspaces, i);
} }
} }