2005-09-20 13:26:39 +00:00
|
|
|
/** \file sanity.c
|
|
|
|
Functions for performing sanity checks on the program state
|
|
|
|
*/
|
2006-08-11 01:18:35 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
|
2006-02-28 13:17:16 +00:00
|
|
|
#include "fallback.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "util.h"
|
2006-02-28 13:17:16 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "sanity.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "history.h"
|
|
|
|
#include "reader.h"
|
|
|
|
#include "kill.h"
|
|
|
|
#include "wutil.h"
|
2006-07-19 22:55:49 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Status from earlier sanity checks
|
|
|
|
*/
|
|
|
|
static int insane;
|
|
|
|
|
|
|
|
void sanity_lose()
|
|
|
|
{
|
2012-02-06 09:45:16 +00:00
|
|
|
debug( 0, _(L"Errors detected, shutting down. Break on sanity_lose() to debug.") );
|
2005-09-20 13:26:39 +00:00
|
|
|
insane = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sanity_check()
|
|
|
|
{
|
|
|
|
if( !insane )
|
2012-02-26 02:54:49 +00:00
|
|
|
if( get_is_interactive() )
|
2005-09-20 13:26:39 +00:00
|
|
|
history_sanity_check();
|
|
|
|
if( !insane )
|
|
|
|
reader_sanity_check();
|
|
|
|
if( !insane )
|
|
|
|
kill_sanity_check();
|
|
|
|
if( !insane )
|
|
|
|
proc_sanity_check();
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
return insane;
|
|
|
|
}
|
|
|
|
|
|
|
|
void validate_pointer( const void *ptr, const wchar_t *err, int null_ok )
|
|
|
|
{
|
2011-12-27 03:18:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Test if the pointer data crosses a segment boundary.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2006-06-01 19:42:31 +00:00
|
|
|
if( (0x00000003l & (long)ptr) != 0 )
|
2005-09-20 13:26:39 +00:00
|
|
|
{
|
2006-01-11 14:17:35 +00:00
|
|
|
debug( 0, _(L"The pointer '%ls' is invalid"), err );
|
2011-12-27 03:18:46 +00:00
|
|
|
sanity_lose();
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
if((!null_ok) && (ptr==0))
|
|
|
|
{
|
2006-01-11 14:17:35 +00:00
|
|
|
debug( 0, _(L"The pointer '%ls' is null"), err );
|
2011-12-27 03:18:46 +00:00
|
|
|
sanity_lose();
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|