95 lines
2.3 KiB
C
95 lines
2.3 KiB
C
/* monitor.c - monitors the wmaker process
|
|
*
|
|
* Window Maker window manager
|
|
*
|
|
* Copyright (c) 1997-2004 Alfredo K. Kojima
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#include "wconfig.h"
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <signal.h>
|
|
#include <sys/wait.h>
|
|
#ifdef __FreeBSD__
|
|
#include <sys/signal.h>
|
|
#endif
|
|
|
|
|
|
#include "WindowMaker.h"
|
|
#include "screen.h"
|
|
#include "window.h"
|
|
#include "dialog.h"
|
|
#include "main.h"
|
|
|
|
|
|
|
|
int MonitorLoop(int argc, char **argv)
|
|
{
|
|
pid_t pid, exited;
|
|
char **child_argv = wmalloc(sizeof(char *) * (argc + 2));
|
|
int i, status;
|
|
time_t last_start;
|
|
Bool error = False;
|
|
|
|
for (i = 0; i < argc; i++)
|
|
child_argv[i] = argv[i];
|
|
child_argv[i++] = "--for-real";
|
|
child_argv[i] = NULL;
|
|
|
|
for (;;) {
|
|
last_start = time(NULL);
|
|
|
|
/* Start Window Maker */
|
|
pid = fork();
|
|
if (pid == 0) {
|
|
execvp(child_argv[0], child_argv);
|
|
werror(_("Error respawning Window Maker"));
|
|
exit(1);
|
|
} else if (pid < 0) {
|
|
werror(_("Error respawning Window Maker"));
|
|
exit(1);
|
|
}
|
|
|
|
do {
|
|
exited = waitpid(-1, &status, 0);
|
|
if (exited < 0) {
|
|
werror(_("Error during monitoring of Window Maker process."));
|
|
error = True;
|
|
break;
|
|
}
|
|
} while (exited != pid);
|
|
|
|
if (error)
|
|
break;
|
|
|
|
child_argv[argc] = "--for-real-";
|
|
|
|
/* Check if the wmaker process exited due to a crash */
|
|
if (WIFSIGNALED(status) &&
|
|
(WTERMSIG(status) == SIGSEGV ||
|
|
WTERMSIG(status) == SIGBUS ||
|
|
WTERMSIG(status) == SIGILL || WTERMSIG(status) == SIGABRT || WTERMSIG(status) == SIGFPE)) {
|
|
wwarning(_("Window Maker exited due to a crash (signal %i) — exiting"),
|
|
WTERMSIG(status));
|
|
}
|
|
break;
|
|
}
|
|
wfree(child_argv);
|
|
return 0;
|
|
}
|