58 行
1.3 KiB
C
58 行
1.3 KiB
C
/**
|
|
* @PROJECT CGI Bash Shell Interface
|
|
* @COPYRIGHT See COPYING in the top level directory
|
|
* @FILE error.c
|
|
* @PURPOSE Error handling
|
|
* @DEVELOPERS Nathan Angelacos <nangel@users.sourceforge.net>
|
|
* Rafal Kupiec <belliash@asiotec.eu.org>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
|
|
#include "common.h"
|
|
#include "buffer.h"
|
|
#include "subshell.h"
|
|
#include "cbsi.h"
|
|
#include "error.h"
|
|
|
|
char* g_err_msg[] = {
|
|
"",
|
|
"Memory Allocation Failure",
|
|
"Unable to open file %s",
|
|
"%c> before <%c",
|
|
"Missing %c>",
|
|
"Unknown operation",
|
|
"Unable to start subshell",
|
|
"Unspecified Error",
|
|
};
|
|
|
|
void die_with_error(char* msg) {
|
|
fprintf(stderr, "Error: %s\n", msg);
|
|
exit(-1);
|
|
}
|
|
|
|
void die_with_message(void* sp, char* where, const char* s, ...) {
|
|
script_t* script = sp;
|
|
va_list p;
|
|
FILE* fo = stderr;
|
|
|
|
fo = stdout;
|
|
fprintf(fo, "HTTP/1.0 500 Server Error\nContent-Type: text/html\n\n<html><body><b><font color=#CC0000>CBSI Error</font></b><br><pre>\n");
|
|
va_start(p, s);
|
|
vfprintf(fo, s, p);
|
|
va_end(p);
|
|
if(where && sp) {
|
|
fprintf(fo, " near line %d of %s\n",
|
|
count_lines(script->buf, script->size, where),
|
|
script->name);
|
|
}
|
|
printf("\n");
|
|
fprintf(fo, "</pre></body></html>\n");
|
|
exit(-1);
|
|
}
|