Skip to content

Commit

Permalink
Move signal registraion earlier
Browse files Browse the repository at this point in the history
In case the service is stopped while Xorg is still starting up (and
gui-agent still waits for the Xorg connectin in mkghandles), gui-agent
would exit before killing Xorg and Xorg would try connecting back to the
gui-agent forever, delaying the shutdown.

Fix this by moving signal registration earlier, before Xorg startup.
Since ghandles_for_vchan_reinitialize is now set before its fully
initialized, initialize x_pid field explicitly and leave all the other
fields zeroed (instead of random stack rubble).

(cherry picked from commit 0806e2f)
  • Loading branch information
marmarek committed Dec 27, 2024
1 parent 18e56f3 commit 0157424
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions gui-agent/vmside.c
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ int main(int argc, char **argv)
{
int i;
int xfd;
Ghandles g;
Ghandles g = { .x_pid = -1 };

g.created_input_device = access("/run/qubes-service/gui-agent-virtual-input-device", F_OK) == 0;

Expand Down Expand Up @@ -2441,10 +2441,21 @@ int main(int argc, char **argv)
libvchan_wait(g.vchan);
saved_argv = argv;
vchan_register_at_eof(handle_guid_disconnect);

ghandles_for_vchan_reinitialize = &g;
signal(SIGCHLD, SIG_IGN);
struct sigaction sigterm_handler = {
.sa_sigaction = handle_sigterm,
.sa_flags = SA_SIGINFO,
};
sigemptyset(&sigterm_handler.sa_mask);
if (sigaction(SIGTERM, &sigterm_handler, NULL))
err(1, "sigaction");

handshake(&g);
g.x_pid = get_xconf_and_run_x(&g);

mkghandles(&g);
ghandles_for_vchan_reinitialize = &g;
/* Turn on Composite for all children of root window. This way X server
* keeps separate buffers for each (root child) window.
* There are two modes:
Expand Down Expand Up @@ -2484,14 +2495,6 @@ int main(int argc, char **argv)
fprintf(stderr, "XFixes not available, cursor shape handling off\n");

XAutoRepeatOff(g.display);
signal(SIGCHLD, SIG_IGN);
struct sigaction sigterm_handler = {
.sa_sigaction = handle_sigterm,
.sa_flags = SA_SIGINFO,
};
sigemptyset(&sigterm_handler.sa_mask);
if (sigaction(SIGTERM, &sigterm_handler, NULL))
err(1, "sigaction");
windows_list = list_new();
embeder_list = list_new();
XSetErrorHandler(dummy_handler);
Expand Down

0 comments on commit 0157424

Please sign in to comment.