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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include <sys/signal.h>
34 #include <X11/Xutil.h>
35 #include <X11/Xproto.h>
37 #include "WindowMaker.h"
43 /****** Global Variables ******/
44 extern WPreferences wPreferences
;
46 int showCrashDialog(int sig
)
50 dpy
= XOpenDisplay(NULL
);
52 /* XXX TODO make sure that window states are saved and restored via netwm */
55 crashAction
= wShowCrashingDialogPanel(sig
);
59 werror(_("cannot open connection for crashing dialog panel. Aborting."));
60 crashAction
= WMAbort
;
63 if (crashAction
== WMStartAlternate
) {
66 wmessage(_("trying to start alternate window manager..."));
68 for (i
= 0; i
< WMGetArrayItemCount(wPreferences
.fallbackWMs
); i
++) {
69 Restart(WMGetFromArray(wPreferences
.fallbackWMs
, i
), False
);
72 wfatal(_("failed to start alternate window manager. Aborting."));
75 } else if (crashAction
== WMAbort
)
81 int MonitorLoop(int argc
, char **argv
)
84 char **child_argv
= wmalloc(sizeof(char *) * (argc
+ 2));
89 for (i
= 0; i
< argc
; i
++)
90 child_argv
[i
] = argv
[i
];
91 child_argv
[i
++] = "--for-real";
95 last_start
= time(NULL
);
97 /* Start Window Maker */
100 execvp(child_argv
[0], child_argv
);
101 werror(_("Error respawning Window Maker"));
103 } else if (pid
< 0) {
104 werror(_("Error respawning Window Maker"));
109 if ((exited
= waitpid(-1, &status
, 0)) < 0) {
110 werror(_("Error during monitoring of Window Maker process."));
114 } while (exited
!= pid
);
119 child_argv
[argc
] = "--for-real-";
121 /* Check if the wmaker process exited due to a crash */
122 if (WIFSIGNALED(status
) &&
123 (WTERMSIG(status
) == SIGSEGV
||
124 WTERMSIG(status
) == SIGBUS
||
125 WTERMSIG(status
) == SIGILL
|| WTERMSIG(status
) == SIGABRT
|| WTERMSIG(status
) == SIGFPE
)) {
126 /* If so, we check when was the last restart.
127 * If it was less than 3s ago, it's a bad sign, so we show
128 * the crash panel and ask the user what to do */
129 if (time(NULL
) - last_start
< 3) {
130 if (showCrashDialog(WTERMSIG(status
)) == 0) {
134 wwarning(_("Window Maker exited due to a crash (signal %i) and will be restarted."),