Skip to content

Commit

Permalink
check the life time of subprocesses before freeing vis
Browse files Browse the repository at this point in the history
Currently there is now way for long running subprocesses like language
servers to gracefully shutdown.
When reacting to the QUIT event and invalidating the process handle
the subprocess will never be killed and destroyed because the
subprocesses are only checked during vis_run.

Collecting and killing subprocesses with invalid handles after the
QUIT event allows graceful shutdown.
  • Loading branch information
fischerling committed Oct 25, 2024
1 parent 1281549 commit d1a4411
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vis-subprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,19 @@ void vis_process_tick(Vis *vis, fd_set *readfds) {
}
}
}

/**
* Checks if each subprocess from the pool is dead or needs to be
* killed then raises an event or kills it if necessary.
*/
void vis_process_waitall(Vis *vis) {
for (Process **pointer = &process_pool; *pointer; ) {
Process *current = *pointer;
if (!wait_or_kill_process(vis, current)) {
pointer = &current->next;
} else {
/* update our iteration pointer */
*pointer = destroy_process(current);
}
}
}
1 change: 1 addition & 0 deletions vis-subprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Process *vis_process_communicate(Vis *, const char *command, const char *name,
Invalidator **invalidator);
int vis_process_before_tick(fd_set *);
void vis_process_tick(Vis *, fd_set *);
void vis_process_waitall(Vis *);
#endif
1 change: 1 addition & 0 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ void vis_free(Vis *vis) {
while (vis->windows)
vis_window_close(vis->windows);
vis_event_emit(vis, VIS_EVENT_QUIT);
vis_process_waitall(vis);
file_free(vis, vis->command_file);
file_free(vis, vis->search_file);
file_free(vis, vis->error_file);
Expand Down

0 comments on commit d1a4411

Please sign in to comment.