Example #1
0
void debug_message (const char *fmt, ...)
{
    static char deb_buf[1024];
    static char *deb = deb_buf;
    va_list args;

    if (!debug_message_fp) {
  /*
   * check whether config file specified this option
   */
  if (strlen(DEBUG_LOG_FILE))
      sprintf(deb, "%s/%s", LOG_DIR, DEBUG_LOG_FILE);
  else
      sprintf(deb, "%s/debug.log", LOG_DIR);
  while (*deb == '/')
      deb++;
  debug_message_fp = fopen(deb, "w");
  if (!debug_message_fp) {
      /* darn.  We're in trouble */
      perror(deb);
      abort();
  }
    }

    V_START(args, fmt);
    V_VAR(char *, fmt, args);
    vfprintf(debug_message_fp, fmt, args);
    fflush(debug_message_fp);
    va_end(args);
    V_START(args, fmt);
    V_VAR(char *, fmt, args);
    vfprintf(stderr, fmt, args);
    fflush(stderr);
    va_end(args);
}
Example #2
0
void debug_message P1V(char *, fmt)
{
    static int append = 0;
    static char deb_buf[100];
    static char *deb = deb_buf;
    va_list args;
    FILE *fp = NULL;
    V_DCL(char *fmt);

    if (!append) {
	/*
	 * check whether config file specified this option
	 */
	if (strlen(DEBUG_LOG_FILE))
	    sprintf(deb, "%s/%s", LOG_DIR, DEBUG_LOG_FILE);
	else
	    sprintf(deb, "%s/debug.log", LOG_DIR);
	while (*deb == '/')
	    deb++;
    }
    fp = fopen(deb, append ? "a" : "w");

    /*
     * re-use stdout's file descriptor if system or process runs out
     * 
     * OS/2 doesn't have ENFILE.
     */
    if (!fp && (errno == EMFILE 
#ifdef ENFILE
		|| errno == ENFILE
#endif
		)) {
	fp = freopen(deb, append ? "a" : "w", stdout);
	append = 2;
    }
    if (!fp) {
	/* darn.  We're in trouble */
	perror(deb);
	abort();
    }
    V_START(args, fmt);
    V_VAR(char *, fmt, args);
    vfprintf(fp, fmt, args);
    fflush(fp);
    vfprintf(stderr, fmt, args);
    fflush(stderr);
    va_end(args);

    /*
     * don't close stdout
     */
    if (append != 2)
	(void) fclose(fp);

    /*
     * append to debug.log next time thru
     */
    if (!append)
	append = 1;
}
Example #3
0
void debug_message(char *fmt, ...)
{
    static char deb_buf[1024];
    static char *deb = deb_buf;
    va_list args;

    V_START(args, fmt);
    V_VAR(char *, fmt, args);
    vfprintf(stderr, fmt, args);
    fflush(stderr);
    va_end(args);
}