1 /* monitor.c - monitors the wmaker process
3 * Window Maker window manager
5 * Copyright (c) 1997-2004 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/signal.h>
33 #include <X11/Xutil.h>
34 #include <X11/Xproto.h>
36 #include "WindowMaker.h"
43 static int showCrashDialog(int sig
)
47 dpy
= XOpenDisplay(NULL
);
49 /* XXX TODO make sure that window states are saved and restored via netwm */
52 crashAction
= wShowCrashingDialogPanel(sig
);
56 werror(_("cannot open connection for crashing dialog panel. Aborting."));
57 crashAction
= WMAbort
;
60 if (crashAction
== WMStartAlternate
) {
63 wmessage(_("trying to start alternate window manager..."));
65 for (i
= 0; i
< WMGetArrayItemCount(wPreferences
.fallbackWMs
); i
++) {
66 Restart(WMGetFromArray(wPreferences
.fallbackWMs
, i
), False
);
69 wfatal(_("failed to start alternate window manager. Aborting."));
72 } else if (crashAction
== WMAbort
)
78 int MonitorLoop(int argc
, char **argv
)
81 char **child_argv
= wmalloc(sizeof(char *) * (argc
+ 2));
86 for (i
= 0; i
< argc
; i
++)
87 child_argv
[i
] = argv
[i
];
88 child_argv
[i
++] = "--for-real";
92 last_start
= time(NULL
);
94 /* Start Window Maker */
97 execvp(child_argv
[0], child_argv
);
98 werror(_("Error respawning Window Maker"));
100 } else if (pid
< 0) {
101 werror(_("Error respawning Window Maker"));
106 exited
= waitpid(-1, &status
, 0);
108 werror(_("Error during monitoring of Window Maker process."));
112 } while (exited
!= pid
);
117 child_argv
[argc
] = "--for-real-";
119 /* Check if the wmaker process exited due to a crash */
120 if (WIFSIGNALED(status
) &&
121 (WTERMSIG(status
) == SIGSEGV
||
122 WTERMSIG(status
) == SIGBUS
||
123 WTERMSIG(status
) == SIGILL
|| WTERMSIG(status
) == SIGABRT
|| WTERMSIG(status
) == SIGFPE
)) {
124 /* If so, we check when was the last restart.
125 * If it was less than 3s ago, it's a bad sign, so we show
126 * the crash panel and ask the user what to do */
127 if (time(NULL
) - last_start
< 3) {
128 if (showCrashDialog(WTERMSIG(status
)) == 0) {
133 wwarning(_("Window Maker exited due to a crash (signal %i) and will be restarted."),