⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error.c

📁 网站压力测试的工具
💻 C
字号:
/** * Error handling * Library: joedog * * Copyright (C) 2000, 2001, 2002 by * Jeffrey Fulmer - <jdfulmer@armstrong.com> * This file is distributed as part of Siege  * * 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., 675 Mass Ave, Cambridge, MA 02139, USA.    *   */#ifdef  HAVE_CONFIG_H# include <config.h>#endif/*HAVE_CONFIG_H*/#include <stdlib.h>#include <stdio.h>#include <syslog.h>#include <stdarg.h>#include <string.h>#include <errno.h>#define BUFSIZE 4096static void   log_message( int status, const char *mode, const char *fmt, va_list ap );static void error_message( int status, const char *mode, const char *fmt, va_list ap );voidjoe_openlog( char *program ){  openlog( program, LOG_PID, LOG_DAEMON );   return;}void joe_closelog( void ){  closelog();  return;}/** *  error_message    program centric error message */void log_message( int status, const char *mode, const char *fmt, va_list ap ){  char buf[BUFSIZE];  vsprintf( buf, fmt, ap );  if( errno == 0 )    sprintf( buf + strlen( buf ), "\n" );  else    sprintf( buf + strlen( buf ), ": %s\n", strerror(errno));   syslog( LOG_ERR, "%s: %s", mode, buf );  if( status >= 0 ){ exit( status ); }  return;}/** *  error_message    program centric error message */voiderror_message( int status, const char *mode, const char *fmt, va_list ap ){  char buf[BUFSIZE/2];  char msg[BUFSIZE];  vsprintf( buf, fmt, ap );  if( errno == 0 || errno == ENOSYS )    snprintf( msg, sizeof( msg ), "%s\n", buf );  else    snprintf( msg, sizeof( msg ), "%s: %s\n", buf, strerror(errno));  fflush( stdout );  fprintf( stderr, "%s: %s", mode, msg );  if( status >= 0 ){ exit( status ); }  return;}/** *  log_warning but continue... */void log_warning( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );    /**    * -1, no exit    */  log_message( -1, "warning", fmt, ap );  va_end( ap );    return;}/** *  joe_warning warn the user but continue to run */voidjoe_warning( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );  /**    * -1, no exit    */  error_message( -1, "warning", fmt, ap );  va_end( ap );  return;}/**  * log_error    signal error but continue to run */void log_error( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );  /**    * -1, no exit    */  log_message( -1, "Error", fmt, ap );  va_end( ap );  return;}/**  * joe_error    signal error but continue to run */voidjoe_error( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );  /**    * -1, no exit    */  error_message( -1, "Error", fmt, ap );  va_end( ap );  return;}/** *  log_fatal   EXIT on fatal condition */void log_fatal( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );  /**    * 1, print message and exit    */  log_message( 1, "FATAL", fmt, ap );  va_end( ap );  return;}/** *  joe_fatal   EXIT on fatal condition */voidjoe_fatal( const char *fmt, ... ){  va_list ap;  va_start( ap, fmt );  /**    * 1, print message and exit    */  error_message( 1, "FATAL", fmt, ap );  va_end( ap );  return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -