-
-
Notifications
You must be signed in to change notification settings - Fork 74
gui-agent: die when xorg fails to start #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,15 @@ | |
|
|
||
| #include <assert.h> | ||
| #include <errno.h> | ||
| #include <stdatomic.h> | ||
| #include <stddef.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <unistd.h> | ||
| #include <stdlib.h> | ||
| #include <signal.h> | ||
| #include <fcntl.h> | ||
| #include <pthread.h> | ||
| #include <sys/socket.h> | ||
| #include <sys/un.h> | ||
| #include <sys/stat.h> | ||
|
|
@@ -144,6 +146,7 @@ struct genlist *windows_list; | |
| struct genlist *embeder_list; | ||
| typedef struct _global_handles Ghandles; | ||
| Ghandles *ghandles_for_vchan_reinitialize; | ||
| atomic_bool terminating; | ||
|
|
||
| #define SKIP_NONMANAGED_WINDOW do { \ | ||
| if (!list_lookup(windows_list, window)) { \ | ||
|
|
@@ -1976,13 +1979,32 @@ static pid_t do_execute_xorg( | |
| } | ||
| } | ||
|
|
||
| static void terminate_and_cleanup_xorg(Ghandles *g) { | ||
| /* this cannot be a SIGCHLD signal handler because of signal safety */ | ||
| static void *xorg_waitpid_thread(void *p) { | ||
| Ghandles *g = p; | ||
| int status; | ||
| waitpid(g->x_pid, &status, 0); | ||
| if (atomic_load(&terminating)) { | ||
| exit(0); | ||
|
Comment on lines
+1995
to
+1996
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the exit status really be zero here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens if we get SIGTERM. Not sure if exit(0) is what we should do in this case, but it is what the previous code did. What would you suggest?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure tbh.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we would want to reset the SIGTERM sigaction and send SIGTERM to ourselves, so that the parent gets told we were killed by SIGTERM? Seems like unnecessary complexity though, if I'm being honest. |
||
| } else { | ||
| if (WIFEXITED(status)) { | ||
| fprintf(stderr, "Xorg exited unexpectedly (exit code %d)\n", | ||
| WEXITSTATUS(status)); | ||
| } else if (WIFSIGNALED(status)) { | ||
| fprintf(stderr, "Xorg terminated unexpectedly (signal %d)\n", | ||
| WTERMSIG(status)); | ||
| } else { | ||
| fprintf(stderr, "Xorg terminated unexpectedly\n"); | ||
| } | ||
|
|
||
| exit(1); | ||
| } | ||
| } | ||
|
|
||
| static void terminate_and_cleanup_xorg(Ghandles *g) { | ||
| if (g->x_pid != (pid_t)-1) { | ||
| atomic_store(&terminating, true); | ||
| kill(g->x_pid, SIGTERM); | ||
| waitpid(g->x_pid, &status, 0); | ||
| g->x_pid = -1; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2185,7 +2207,7 @@ static void handle_sigterm() | |
| { | ||
| Ghandles *g = ghandles_for_vchan_reinitialize; | ||
| terminate_and_cleanup_xorg(g); | ||
| exit(0); | ||
| while (1) pause(); | ||
| } | ||
|
|
||
| static void usage() | ||
|
|
@@ -2253,6 +2275,7 @@ int main(int argc, char **argv) | |
| int xfd; | ||
| Ghandles g; | ||
| int wait_fds[2]; | ||
| pthread_t waitpid_thread; | ||
|
|
||
| parse_args(&g, argc, argv); | ||
|
|
||
|
|
@@ -2274,6 +2297,10 @@ int main(int argc, char **argv) | |
| vchan_register_at_eof(handle_guid_disconnect); | ||
| send_protocol_version(g.vchan); | ||
| g.x_pid = get_xconf_and_run_x(&g); | ||
| if (pthread_create(&waitpid_thread, NULL, xorg_waitpid_thread, &g) < 0) { | ||
| perror("pthread_create"); | ||
| exit(1); | ||
| } | ||
|
meithecatte marked this conversation as resolved.
Outdated
|
||
| mkghandles(&g); | ||
| ghandles_for_vchan_reinitialize = &g; | ||
| /* Turn on Composite for all children of root window. This way X server | ||
|
|
@@ -2315,7 +2342,6 @@ int main(int argc, char **argv) | |
| fprintf(stderr, "XFixes not available, cursor shape handling off"); | ||
|
|
||
| XAutoRepeatOff(g.display); | ||
| signal(SIGCHLD, SIG_IGN); | ||
| signal(SIGTERM, handle_sigterm); | ||
| windows_list = list_new(); | ||
| embeder_list = list_new(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.