Exemplo n.º 1
0
PRIVATE int printer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}
Exemplo n.º 2
0
static size_t FileWriterWriteF(Writer *writer, const char *fmt, va_list ap)
{
    return vfprintf(writer->file, fmt, ap);
}
Exemplo n.º 3
0
void ERR_PRINT_LOG(LogClientTmp *LogClientHd, enum DebugLogLevel PrtLevel, const char *FileName, const char *FuncName, int32_t LineNum, const char *fmt, ...)
{
	static pthread_mutex_t logMutex = PTHREAD_MUTEX_INITIALIZER;
	FILE *fp = NULL;
	char LogFileName[256];
	int32_t LogFileLen = 0;
	va_list ap;
	time_t curr;

	char strTime[256];
    struct tm *p;
	int32_t TmpLen = 0;
   

	memset(LogFileName, 0, sizeof(LogFileName));
	sprintf(LogFileName, "%s", NAME_FILE_MEDIA_LOG);
	
	time(&curr);
    p=localtime(&curr);
	memset(strTime, 0, sizeof(strTime));
    TmpLen = sprintf(strTime, "%04d-%02d-%02d %02d:%02d:%02d ",
            (1900+p->tm_year), (1+p->tm_mon), p->tm_mday,
            p->tm_hour, p->tm_min, p->tm_sec);

	if((NULL != FileName) && (NULL != FuncName))
	{
		sprintf(strTime+TmpLen, "[%s] [%s] [%d] ", FileName, FuncName, LineNum);
	}
	
	pthread_mutex_lock(&logMutex);
	fp = fopen(LogFileName, "a+");
	if(NULL == fp)
	{
		pthread_mutex_unlock(&logMutex);
		fprintf(stderr, "WriteMediaLog open log file error\n");
		return;
	}

	fseek(fp, 0L, SEEK_END);
	LogFileLen = ftell(fp);

	if(LogFileLen >= LENGTH_LOG_MAX)
	{
		fclose(fp);
		fp = NULL;
		fp = fopen(LogFileName, "w+");
		if(NULL == fp)
		{
			pthread_mutex_unlock(&logMutex);
			fprintf(stderr, "WriteMediaLog create log file error\n");
			return;
		}
	}

	fprintf(fp, "%s ", strTime);
	va_start(ap, fmt);
	vfprintf(fp, fmt, ap);
	va_end(ap);
	fprintf(fp, "\n");
	fclose(fp);
	fp = NULL;
	pthread_mutex_unlock(&logMutex);
}
Exemplo n.º 4
0
void __attribute__((noreturn)) t_vfatal(char *err, va_list args)
{
	endwin();
	vfprintf(stderr, err, args);
	exit(TUI_FAIL);
}
Exemplo n.º 5
0
static void
common_print(char *fmt, va_list ap)
{
    vfprintf(stdout, fmt, ap);
    fflush(stdout);
}
Exemplo n.º 6
0
static void vprintf_stderr_common(const char* format, va_list args)
{
#if USE(CF) && !OS(WINDOWS)
    if (strstr(format, "%@")) {
        CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);

#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
        CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
        CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
        char* buffer = (char*)malloc(length + 1);

        CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);

#if USE(APPLE_SYSTEM_LOG)
        asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
        fputs(buffer, stderr);

        free(buffer);
        CFRelease(str);
        CFRelease(cfFormat);
        return;
    }

#if USE(APPLE_SYSTEM_LOG)
    va_list copyOfArgs;
    va_copy(copyOfArgs, args);
    asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
    va_end(copyOfArgs);
#endif

    // Fall through to write to stderr in the same manner as other platforms.

#elif PLATFORM(BLACKBERRY)
    BBLOGV(BlackBerry::Platform::LogLevelCritical, format, args);
#elif HAVE(ISDEBUGGERPRESENT)
    if (IsDebuggerPresent()) {
        size_t size = 1024;

        do {
            char* buffer = (char*)malloc(size);

            if (buffer == NULL)
                break;

            if (_vsnprintf(buffer, size, format, args) != -1) {
#if OS(WINCE)
                // WinCE only supports wide chars
                wchar_t* wideBuffer = (wchar_t*)malloc(size * sizeof(wchar_t));
                if (wideBuffer == NULL)
                    break;
                for (unsigned int i = 0; i < size; ++i) {
                    if (!(wideBuffer[i] = buffer[i]))
                        break;
                }
                OutputDebugStringW(wideBuffer);
                free(wideBuffer);
#else
                OutputDebugStringA(buffer);
#endif
                free(buffer);
                break;
            }

            free(buffer);
            size *= 2;
        } while (size > 1024);
    }
#endif
#if !PLATFORM(BLACKBERRY)
    vfprintf(stderr, format, args);
#endif
}
Exemplo n.º 7
0
	void Logger::logv(const int64_t lv, const char* fmt, va_list vl){
		if(lv < m_level) return;
		// prepare out
		FILE* out =stdout;
		if(m_szName){
			_open_file();
			if(m_file){
				out =m_file;
			}
		}

		// tm
		struct tm t;
		int microsecs =0;
		struct timeval tv;
		if(0 == gettimeofday(&tv, 0)){
			if(struct tm* tmp =localtime_r(&tv.tv_sec, &t)){
				t =*tmp;
				microsecs =tv.tv_usec;
			}
			else{
				memset(&t, 0, sizeof(t));
			}
		}
		else{
			memset(&t, 0, sizeof(t));
		}

		// out
		const char* tag =0;
		switch(lv){
		case Logger::INFO:
			tag ="INFO "; break;
		case Logger::WARN:
			tag ="WARN "; break;
		case Logger::ERROR:
			tag ="ERROR"; break;
		case Logger::FATAL:
			tag ="FATAL"; break;
		case Logger::DEBUG:
			tag ="DEBUG"; break;
		}
		if(tag){
			fprintf(out, "[%04d-%02d-%02d %02d:%02d:%02d.%06d] %s > ", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, microsecs, tag);
		}
		else{
			fprintf(out, "[%04d-%02d-%02d %02d:%02d:%02d.%06d] %.5lld > ", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, microsecs, (long long)lv);
		}

		/*
		char x[1024] ={0};
		vsprintf(x, fmt, vl);
		if(strcmp(x, "fail to call a1, arg test invalid") == 0){
			ASSERT(0);
		}
		*/
		vfprintf(out, fmt, vl);
		fprintf(out, "\n");
		if(FLUSH_MODE_FLUSH == m_flush_mode){
			fflush(out);
		}
	}
Exemplo n.º 8
0
/* _log function */
void _log(const char * msg,va_list args)
{
    time_t tm;
    struct tm *p;

    /* For the stderr print */
    va_list args2;

    FILE *fp;

    tm = time(NULL);
    p = localtime(&tm);

    /* Duplicating args */
    va_copy(args2, args);


    /* If under chroot, log directly to /logs/ossec.log */
    if(chroot_flag == 1)
    {
        fp = fopen(LOGFILE, "a");
    }
    else
    {
        char _logfile[256];
        #ifndef WIN32
        snprintf(_logfile, 256, "%s%s", DEFAULTDIR, LOGFILE);
        #else
        snprintf(_logfile, 256, "%s", LOGFILE);
        #endif
        fp = fopen(_logfile, "a");
    }

    /* Maybe log to syslog if the log file is not available. */
    if(fp)
    {
        (void)fprintf(fp,"%d/%02d/%02d %02d:%02d:%02d ",
                      p->tm_year+1900,p->tm_mon+1,
                      p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
        (void)vfprintf(fp, msg, args);
        #ifdef WIN32
        (void)fprintf(fp, "\r\n");
        #else
        (void)fprintf(fp, "\n");
        #endif
        fflush(fp);
        fclose(fp);
    }


    /* Only if not in daemon mode */
    if(daemon_flag == 0)
    {
        /* Print to stderr */		
        (void)fprintf(stderr,"%d/%02d/%02d %02d:%02d:%02d ",
                      p->tm_year+1900,p->tm_mon+1 ,p->tm_mday,
                      p->tm_hour,p->tm_min,p->tm_sec);
        (void)vfprintf(stderr, msg, args2);
        #ifdef WIN32
        (void)fprintf(stderr, "\r\n");
        #else
        (void)fprintf(stderr, "\n");
        #endif
    }


    /* args2 must be ended here */
    va_end(args2);
}
Exemplo n.º 9
0
Arquivo: log.c Projeto: onny/sway
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
#else
void _sway_log(log_importance_t verbosity, const char* format, ...) {
#endif
	if (verbosity <= v) {
		unsigned int c = verbosity;
		if (c > sizeof(verbosity_colors) / sizeof(char *)) {
			c = sizeof(verbosity_colors) / sizeof(char *) - 1;
		}

		if (colored && isatty(STDERR_FILENO)) {
			fprintf(stderr, "%s", verbosity_colors[c]);
		}

		va_list args;
		va_start(args, format);
#ifndef NDEBUG
		char *file = strdup(filename);
		fprintf(stderr, "[%s:%d] ", basename(file), line);
		free(file);
#endif
		vfprintf(stderr, format, args);
		va_end(args);

		if (colored && isatty(STDERR_FILENO)) {
			fprintf(stderr, "\x1B[0m");
		}
		fprintf(stderr, "\n");
	}
}

void sway_log_errno(log_importance_t verbosity, char* format, ...) {
	if (verbosity <= v) {
		unsigned int c = verbosity;
		if (c > sizeof(verbosity_colors) / sizeof(char *)) {
			c = sizeof(verbosity_colors) / sizeof(char *) - 1;
		}

		if (colored && isatty(STDERR_FILENO)) {
			fprintf(stderr, "%s", verbosity_colors[c]);
		}

		va_list args;
		va_start(args, format);
		vfprintf(stderr, format, args);
		va_end(args);

		fprintf(stderr, ": ");
		fprintf(stderr, "%s", strerror(errno));

		if (colored && isatty(STDERR_FILENO)) {
			fprintf(stderr, "\x1B[0m");
		}
		fprintf(stderr, "\n");
	}
}

bool _sway_assert(bool condition, const char* format, ...) {
	if (condition) {
		return true;
	}

	va_list args;
	va_start(args, format);
	sway_log(L_ERROR, format, args);
	va_end(args);

#ifndef NDEBUG
	raise(SIGABRT);
#endif

	return false;
}

void error_handler(int sig) {
#if SWAY_Backtrace_FOUND
	int i;
	int max_lines = 20;
	void *array[max_lines];
	char **bt;
	size_t bt_len;
	char maps_file[256];
	char maps_buffer[1024];
	FILE *maps;

	sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig);
	bt_len = backtrace(array, max_lines);
	bt = backtrace_symbols(array, bt_len);
	if (!bt) {
		sway_log(L_ERROR, "Could not allocate sufficient memory for backtrace_symbols(), falling back to stderr");
		backtrace_symbols_fd(array, bt_len, STDERR_FILENO);
		exit(1);
	}

	for (i = 0; (size_t)i < bt_len; i++) {
		sway_log(L_ERROR, "Backtrace: %s", bt[i]);
	}

	sway_log(L_ERROR, "Maps:");
	pid_t pid = getpid();
	if (snprintf(maps_file, 255, "/proc/%zd/maps", (size_t)pid) < 255) {
		maps = fopen(maps_file, "r");
		while (!feof(maps)) {
			char *m = read_line_buffer(maps, maps_buffer, 1024);
			if (!m) {
				fclose(maps);
				sway_log(L_ERROR, "Unable to allocate memory to show maps");
				break;
			}
			sway_log(L_ERROR, "%s", m);
		}
		fclose(maps);
	}
#else
	sway_log(L_ERROR, "Error: Signal %d.", sig);
#endif
	exit(1);
}
Exemplo n.º 10
0
void LogError(FILE *fp, const int mode, const char *fmt, ...) {
	/* uses global variable logged to indicate that a log message
	 * was sent to output, which can be used to inform user, etc.
	 *
	 *  9-Dec-03 (cwb) Modified to accept argument list similar
	 *           to fprintf() so sprintf(errstr...) doesn't need
	 *           to be called each time replacement args occur.
	 */

	char outfmt[50 + strlen(fmt)]; /* to prepend err type str */
	va_list args;
#ifdef RSOILWAT
	char *message;
	message = R_alloc(strlen(fmt) + 121, sizeof(char));
#endif

	va_start(args, fmt);
#ifndef RSOILWAT
	if (LOGNOTE & mode)
		strcpy(outfmt, "NOTE: ");
	else if (LOGWARN & mode)
		strcpy(outfmt, "WARNING: ");
	else if (LOGERROR & mode)
		strcpy(outfmt, "ERROR: ");

	strcat(outfmt, fmt);
	strcat(outfmt, "\n");

	if (EOF == vfprintf(fp, outfmt, args))
		fprintf(stderr, "SYSTEM: Cannot write to FILE *fp in LogError()\n");
	fflush(fp);
#else
	if (RlogIndex == 150) {
			Rprintf("Error Log Full. Increase limit from %i", RlogIndex);
	} else {
		if ((LOGNOTE & mode) && logNote) {
			strcpy(outfmt, "NOTE: ");
			strcat(outfmt, fmt);
			strcat(outfmt, "\n");
			vsnprintf(message, 120 + strlen(fmt), outfmt, args);
			SET_STRING_ELT(Rlogfile, RlogIndex, mkChar(message));
			RlogIndex++;
		} else if ((LOGWARN & mode) && logWarn) {
			strcpy(outfmt, "WARNING: ");
			strcat(outfmt, fmt);
			strcat(outfmt, "\n");
			vsnprintf(message, 120 + strlen(fmt), outfmt, args);
			SET_STRING_ELT(Rlogfile, RlogIndex, mkChar(message));
			RlogIndex++;
		} else if ((LOGERROR & mode) && logFatl) {
			strcpy(outfmt, "ERROR: ");
			strcat(outfmt, fmt);
			strcat(outfmt, "\n");
			vsnprintf(message, 120 + strlen(fmt), outfmt, args);
			SET_STRING_ELT(Rlogfile, RlogIndex, mkChar(message));
			RlogIndex++;
		}
	}
#endif

	logged = TRUE;

	va_end(args);

	if (LOGEXIT & mode) {
#ifndef RSOILWAT
		exit(-1);
#else
		//strcpy(outfmt, "ERROR: ");
		//strcat(outfmt, fmt);
		//vsnprintf(message, 80 + strlen(fmt), outfmt, args);
		Rprintf("Exit.. %s",message);
		error("@ generic.c LogError");
#endif
	}

}
Exemplo n.º 11
0
void config_printf_noskip (const char *fmt, ...)
{
	va_list arg; va_start(arg, fmt);
	vfprintf (config_file_out, fmt, arg);
	fputc('\n', config_file_out);
}
Exemplo n.º 12
0
int error_proc(FMSG *errmsg, ...)
{
    char *tmp_errmsg;
    va_list marker;

#if SFX_LEVEL>=ARJ
    /* Check if the message could have a standard error code */
    if(errno!=0&&is_std_error(errmsg))
    {
        msg_cprintf(0, lf);
        error_report();
    }
#endif
#if SFX_LEVEL>=ARJSFXV
    if(quiet_mode==ARJ_SILENT)
        freopen(dev_con, m_w, stdout);
#endif
#if SFX_LEVEL>=ARJ
    file_settype(stdout, ARJT_TEXT);
#endif
    /* For SFX archives, don't forget to display our logo */
#if SFX_LEVEL==ARJSFXV
    show_sfx_logo();
#elif SFX_LEVEL==ARJSFX
    if(!logo_shown)
    {
        msg_cprintf(0, M_ARJSFX_BANNER, exe_name);
        msg_cprintf(0, M_PROCESSING_ARCHIVE, archive_name);
    }
#endif
#if SFX_LEVEL>=ARJ
    nputlf();
#elif SFX_LEVEL>=ARJSFXV
    fputc(LF, new_stdout);
#else
    fputc(LF, stdout);
#endif
    /* Format and print the error message */
    va_start(marker, errmsg);
#ifdef CUSTOM_PRINTF
    vcprintf(H_ERR, errmsg, marker);
#else
    tmp_errmsg=malloc_fmsg(errmsg);
#if SFX_LEVEL>=ARJSFXV
    vfprintf(new_stdout, (FMSG *)tmp_errmsg, marker);
#else
    vprintf(tmp_errmsg, marker);
#endif
    free_fmsg(tmp_errmsg);
#endif
    va_end(marker);
#if SFX_LEVEL>=ARJ
    nputlf();
#elif SFX_LEVEL>=ARJSFXV
    fputc(LF, new_stdout);
#else
    fputc(LF, stdout);
#endif
    /* Terminate the execution with a specific errorlevel */
#if SFX_LEVEL>=ARJSFXV
    /* If there's no errorlevel yet, select errorlevel by message class */
    if(errorlevel==0)
        errorlevel=subclass_errors(errmsg);
    /* If the error was the lack of memory, display final memory statistics to
       find memory leaks */
#if SFX_LEVEL>=ARJ
    if(errorlevel==ARJ_ERL_NO_MEMORY)
        mem_stats();
#endif
    error_occured=1;
    exit(errorlevel);
#elif defined(REARJ)
    exit(REARJ_ERL_WARNING);
#elif defined(REGISTER)
    exit(REGISTER_ERL_ERROR);
#elif SFX_LEVEL>=ARJSFX
    exit(ARJSFX_ERL_ERROR);
#else
    exit(1);
#endif
    return(0);
}
Exemplo n.º 13
0
static int TEST_vprintf(const char *fmt, va_list ap)
{
	return vfprintf(GetLogFile(), fmt, ap);
}
Exemplo n.º 14
0
PRIVATE int tracer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stderr, fmt, pArgs));
}
Exemplo n.º 15
0
int vprintf(const char *fmt, va_list ap)
{
	return vfprintf(stdout, fmt, ap);
}
Exemplo n.º 16
0
void
minierr_vdie( int line, const char *func, const char *file, int wraplines, mas_minierr_type_t et, int fexit, unsigned flags, const char *sid, const char *fmt,
              va_list args )
{
  char *pf = strrchr( file, '/' );
  char buffer[1024] = "";
  size_t prefwidth = 10;
  int a = 0, b = 0;

  if ( !( disabled_flags & ( 1UL << et ) ) )
  {
    if ( pf )
      pf++;
#define MAS_MIER_PRN(...) { size_t l=strlen( buffer ); snprintf( buffer + l, sizeof( buffer ) - l, __VA_ARGS__); }

/* MAS_MIER_PRN( "[%ld] ", prefwidth ); */
/* MAS_MIER_PRN( "[%lx] %x %x", ( long ) flags, MAS_MIER_FLAG_EXIT, MAS_MIER_FLAG_SLEEP ); */
    if ( flags &
         ( MAS_MIER_FLAG_EXIT | MAS_MIER_FLAG_ASSERT | MAS_MIER_FLAG_LINE | MAS_MIER_FLAG_FUNC | MAS_MIER_FLAG_FILE | MAS_MIER_FLAG_COLPREF ) )
    {
      a = 33;
      if ( flags & ( MAS_MIER_FLAG_EXIT | MAS_MIER_FLAG_ASSERT ) )
        b = 41;
      else if ( flags & MAS_MIER_FLAG_COLPREF )
        b = 46;
      else
        b = 44;
    }
    if ( a || b )
      MAS_MIER_PRN( "\x1b[0;1;7;%d;%dm", a, b );
    MAS_MIER_PRN( "-=%4s=-", sid ? sid : ( fexit ? "DIE" : "WARN" ) );
#if 1
    if ( flags & ( MAS_MIER_FLAG_EXIT | MAS_MIER_FLAG_ASSERT | MAS_MIER_FLAG_LINE | MAS_MIER_FLAG_FUNC | MAS_MIER_FLAG_FILE ) )
    {
      if ( a || b )
      {
        a = 49;
        b = 36;
      }
      if ( a || b )
        MAS_MIER_PRN( "\x1b[0;1;%d;%dm", a, b );
    }
#endif
    if ( flags & MAS_MIER_FLAG_FUNC )
    {
      prefwidth += 43;
      MAS_MIER_PRN( "%s( )", func );
    }
    if ( flags & MAS_MIER_FLAG_FILE )
    {
      prefwidth += 43;
      MAS_MIER_PRN( " @ %s", pf );
    }
    if ( flags & MAS_MIER_FLAG_LINE )
    {
      prefwidth += 5;
      MAS_MIER_PRN( ":%d ", line );
    }
    if ( a || b )
      MAS_MIER_PRN( "\x1b[%dm", 0 );
    {
      size_t len = strlen( buffer );
      char *p = buffer + len;

    /* *p++ = '{'; */
    /* justify: */
      while ( p && len < prefwidth && len < sizeof( buffer ) - 4 )
      {
        *p++ = '.';
        len++;
      }
    /* *p++ = '}'; */
      *p = 0;
    }
    if ( flags & ( MAS_MIER_FLAG_LINE | MAS_MIER_FLAG_FUNC | MAS_MIER_FLAG_FILE ) )
      MAS_MIER_PRN( " --" );
    MAS_MIER_PRN( " " );
    for (int i=0;i<wraplines;i++)fputs( "\n", stderr );
    fputs( buffer, stderr );
/* fprintf( stderr, "%-50s", buffer ); */
    vfprintf( stderr, fmt, args );
//  fprintf( stderr, "\n" );
    for (int i=0;i<wraplines+1;i++)fputs( "\n", stderr );

#ifdef MAS_TRACEMEM
    if ( flags & MAS_MIER_FLAG_EXIT )
    {
      extern int mas_mem_disable_print_usage __attribute__ ( ( weak ) );

      if ( &mas_mem_disable_print_usage )
        mas_mem_disable_print_usage = 1;
    }
#endif

    if ( flags & MAS_MIER_FLAG_SLEEP )
      sleep( 5 );
    if ( flags & MAS_MIER_FLAG_ASSERT )
      assert( 0 );
    if ( flags & MAS_MIER_FLAG_EXIT )
      exit( fexit );
  }
}
Exemplo n.º 17
0
void dbg_printf(char* fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
    fprintf(stderr, "DBG: ");
    vfprintf(stderr, fmt, ap);
}
Exemplo n.º 18
0
Arquivo: mp3.c Projeto: hjelmn/upod
void mp3_debug (char *format, ...) {
  va_list arg;
  va_start (arg, format);
  vfprintf (stderr, format, arg);
  va_end (arg);
}
Exemplo n.º 19
0
/* routine via which the dot file is written */
void write_dot(const char * prefix, const char * figpath,
	       int id, const char *fmt, ...)
{
	static int flag = 0;
	static FILE * dotf[MAX_DOTF_NR];
	static char dotfilename[MAX_DOTF_NR][FILENAME_MAX];
	char cmd[CMD_MAX];

	va_list args;
	va_start(args, fmt);

	assert(id >= 0 && id < MAX_DOTF_NR);
	if (id < LOWEST_DOT_ID)
		return;

	if (!flag) {
		int i;
		for (i = 0; i < MAX_DOTF_NR; i++)
			dotf[i] = 0;
		flag = 1;
	}
	if (!dotf[id]) {
		sprintf(dotfilename[id], "%s%s%s (%03d).%s",
			figpath,
			figpath[strlen(figpath) - 1] == '/' ? "" : "/",
			prefix, id, GRAPHVIZ_FILE_EXT);

		mkdir_if_needed(dotfilename[id], 0);

		fprintf(stderr, "%sdot file: %s%s\n", INFO_COLOR,
			dotfilename[id], NOCOLOR);

		dotf[id] = fopen(dotfilename[id], "w");
		assert(dotf[id] != 0);

		fprintf(dotf[id], "digraph G {\n");

		fprintf(dotf[id],
			"\tsize=\"9,9\";"
			"\n");

		fprintf(dotf[id],
			"\tnode [shape=record"
			", fontname=Courier New"
			", penwidth=0.5"
			/* ", fixedsize=true" */
			/* ", width=0.6" */
			/* ", height=0.7" */
			", splines=\"compound\""
			"];\n");
	}

	assert(dotf[id] != 0);

	/* if the dot file becomes big, something must be wrong */
	int dot_f_max_size = 32*1024;
	if (ftell(dotf[id]) > dot_f_max_size) {
		fprintf(stderr,
			"%sdot file too big: %s"
			"%s%s%s"
			"%s, something must be wrong.\n%s",
			YELLOW, NOCOLOR,
			RED, dotfilename[id], NOCOLOR,
			YELLOW, NOCOLOR);
		assert(ftell(dotf[id]) <= dot_f_max_size);
	}

	if (!fmt[0]) {
		fprintf(dotf[id], "}\n");
		fclose(dotf[id]);
		dotf[id] = 0;
		snprintf(cmd, (size_t)CMD_MAX, "%s -T%s \"%s\" -o "
			 "\"%s%s%s (%03d).%s\"",
			 GRAPHVIZ_CMD, GRAPHVIZ_FIG_TYPE, dotfilename[id],
			 figpath,
			 figpath[strlen(figpath) - 1] == '/' ? "" : "/",
			 prefix, id, GRAPHVIZ_FIG_TYPE);
		printf("%s$ %s%s%s\n", WHITE, WHITE, cmd, NOCOLOR);
		/* printf("%s$ %s%s%s\n", WHITE, GREEN, cmd, NOCOLOR); */
		assert(system(cmd) == 0);
	} else {
		fprintf(dotf[id], "\t");
		vfprintf(dotf[id], fmt, args);
	}

	va_end(args);
}
Exemplo n.º 20
0
                  error("too many output files or filename is too long (> %d)", NAME_MAX);
	
		    
        free(filename);
        
}

static int tcpdump_printf(netdissect_options *ndo _U_,
			  const char *fmt, ...)
{
  
  va_list args;
  int ret;

  va_start(args, fmt);
  ret=vfprintf(stdout, fmt, args);
  va_end(args);

  return ret;
}


void getInterfaces()
{
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "getInterfaces");
#ifdef HAVE_PCAP_FINDALLDEVS
	printf("inside getInterfaces()");
	pcap_if_t *devpointer;
	char ebuf[PCAP_ERRBUF_SIZE];
	int devnum;
	int i;
Exemplo n.º 21
0
void _xlog(int type, const char* fmt, ...)
{
	va_list ap;
        time_t t = time(NULL);
        struct tm tm = *localtime(&t);

	/* lock tty before printing */
        pthread_mutex_lock(&tty_mutex);

#ifdef DEBUG
        fprintf(cfg->logfile_fd,
                "%.4d/%.2d/%.2d ",
                tm.tm_year + 1900,
                tm.tm_mon + 1,
                tm.tm_mday);
#endif

        fprintf(cfg->logfile_fd,
                "%.2d:%.2d:%.2d-",
                tm.tm_hour, tm.tm_min,
                tm.tm_sec);


	switch (type) {
		case LOG_CRITICAL:
			if (cfg->use_color) fprintf(cfg->logfile_fd, DARK);
			fprintf(cfg->logfile_fd, "CRITICAL");
			break;

		case LOG_ERROR:
			if (cfg->use_color) fprintf(cfg->logfile_fd, RED);
			fprintf(cfg->logfile_fd, "ERROR");
			break;

		case LOG_WARNING:
			if (cfg->use_color) fprintf(cfg->logfile_fd, YELLOW);
			fprintf(cfg->logfile_fd, "WARNING");
			break;

		case LOG_DEBUG:
			if (cfg->use_color) fprintf(cfg->logfile_fd, BLUE);
			fprintf(cfg->logfile_fd, "DEBUG");
			break;

		case LOG_INFO:
		default:
			if (cfg->use_color) fprintf(cfg->logfile_fd, GREEN);
			fprintf(cfg->logfile_fd, "INFO");
			break;
	}


        if (cfg->use_color)
                fprintf(cfg->logfile_fd, NOCOLOR);

        fprintf(cfg->logfile_fd, "-");

#ifdef DEBUG
#if defined __LINUX__
	fprintf(cfg->logfile_fd, "tid-%lu ", pthread_self());
#elif defined __FREEBSD__ || defined __DARWIN__
        fprintf(cfg->logfile_fd, "tid-%p ", pthread_self());
#endif
#endif

	va_start(ap, fmt);
	vfprintf(cfg->logfile_fd, fmt, ap);
	fflush(cfg->logfile_fd);
	va_end(ap);

	/* release lock */
        pthread_mutex_unlock(&tty_mutex);
}
Exemplo n.º 22
0
static void osmo4_do_log(void *cbk, u32 level, u32 tool, const char *fmt, va_list list)
{
	FILE *logs = (FILE *) cbk;
    vfprintf(logs, fmt, list);
	fflush(logs);
}
Exemplo n.º 23
0
void WOLog(int level, const char *format, ...)
{
   FILE *log;
   va_list ap;
   int do_it;
#if defined(TIMESTAMP_LOG_MESSAGES)
   struct tm *t;
   time_t now;
   char timestamp[64];
#endif

   if (level < baselevel)
      return;

   if (! initialized )
	   return;

   do_it = shouldLog();
   if ( do_it ) {
      /*
       * plenty of people have complained that we need to timestamp
       * the log entries.  the problem is that mktime & friends aren't
       * reentrant.
       */
#if defined(TIMESTAMP_LOG_MESSAGES)
      WA_lock(logMutex);
      time(&now);
      t = localtime(&now);
      strftime(timestamp, sizeof(timestamp), "%d-%b-%Y %T - ", t);
      WA_unlock(logMutex);
#endif
      log = fopen(logPath, "a+");
      if (log != NULL) {
#if defined(TIMESTAMP_LOG_MESSAGES)
         fprintf(log, timestamp);
#endif
         fprintf(log,"%s: ", WOLogLevel[level]);
         va_start(ap, format);
         vfprintf(log, format, ap);
         va_end(ap);
         fprintf(log,"\n");
         fclose(log);
      }else{
// TODO - figure out how to report this for other web servers
#if defined(APACHE)
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, _webobjects_server, "Failed to append to log file '%s'.  This can occur when the file is not writable by the child httpd process.  A workaround is to change the ownership of the file to match the child httpd process.", logPath);
#endif
      }
   }


   /*
    *	if the error is serious, include it into the server's log
    */
#if	defined(Netscape) || defined(APACHE) || defined(IIS)
   if (level == WO_ERR) {
      String *str;
      str = str_create(NULL, 128);
      va_start(ap,format);
      str_vappendf(str, format, ap);
      va_end(ap);
#if defined(Netscape)
      log_error(0,"WebObjects",NULL,NULL,str->text);
#elif defined(APACHE)
      ap_log_error(APLOG_MARK, APLOG_ERR, 0, _webobjects_server, str->text);
#elif defined(IIS)
      /*
       *	again, we're stymied because we don't have a ptr to the
       *	server struct
       * /
       {
          LPDWORD len = strlen(logstr);
          ServerSupportFunction(p->ConnID, HSE_APPEND_LOG_PARAMETER,
                                str->text, &len, (LPDWORD)NULL);
       }
       */
#endif
      str_free(str);
   }
#endif
}
Exemplo n.º 24
0
static void
__vsyslogex_chk(int pri, int flag, pid_t cpid, pid_t ctid, const char *fmt, va_list ap) {
    struct tm now_tm;
    time_t now;
    int fd;
    FILE *f;
    char *buf = 0;
    size_t bufsize = 0;
    size_t prioff, msgoff;
#ifndef NO_SIGPIPE
    struct sigaction action, oldaction;
    int sigpipe;
#endif
    int saved_errno = errno;
    char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"];
    const int LogMask = setlogmask(0);

#ifdef _DEBUGFLAGS_H_
    {
        static unsigned int registered = 0;
        if (unlikely(0 == registered)) {
            registered = 1; /* dirty work around to avoid deadlock: syslogex->register->syslogex */
            registered = (registerLibraryDebugFlags(&debugFlags) == EXIT_SUCCESS);
        }
    }
#endif /*_DEBUGFLAGS_H_*/

#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
    /* Check for invalid bits. */
    if (unlikely(pri & ~(LOG_PRIMASK | LOG_FACMASK))) {
        /*syslog(INTERNALLOG,
               "syslog: unknown facility/priority: %x", pri);*/
        WARNING_MSG("unknown facility/priority: %x", pri);
        pri &= LOG_PRIMASK | LOG_FACMASK;
    }

    /* Check priority against setlogmask values. */
    if (unlikely((LOG_MASK(LOG_PRI(pri)) & LogMask) == 0))
        return;

    /* Set default facility if none specified. */
    if (unlikely((pri & LOG_FACMASK) == 0))
        pri |= LogFacility;

    /* Build the message in a memory-buffer stream.  */
    f = open_memstream(&buf, &bufsize);
    if (unlikely(f == NULL)) {
        /* We cannot get a stream.  There is not much we can do but
           emitting an error messages with the Process ID.  */
        char numbuf[3 * sizeof (pid_t)];
        char *nump;
        char *endp = __stpcpy(failbuf, "out of memory [");
        pid_t pid = getpid();

        nump = numbuf + sizeof (numbuf);
        /* The PID can never be zero.  */
        do {
            *--nump = '0' + pid % 10;
        } while ((pid /= 10) != 0);

        endp = mempcpy((void*) endp, (const void*) nump, (size_t) ((numbuf + sizeof (numbuf)) - nump));
        *endp++ = ']';
        *endp = '\0';
        buf = failbuf;
        bufsize = endp - failbuf;
        msgoff = 0;
    } else {
        __fsetlocking(f, FSETLOCKING_BYCALLER);
        prioff = fprintf(f, "<%d>", pri);
        (void) time(&now);
        f->_IO_write_ptr += strftime(f->_IO_write_ptr,
                f->_IO_write_end - f->_IO_write_ptr,
                "%h %e %T ",
                localtime_r(&now, &now_tm));
        /*f->_IO_write_ptr += strftime_l (f->_IO_write_ptr,
                                          f->_IO_write_end - f->_IO_write_ptr,
                                          "%h %e %T ",
                                          localtime_r (&now, &now_tm));*/
        msgoff = ftell(f);
        if (LogTag == NULL)
            LogTag = __progname;
        if (LogTag != NULL)
            fputs_unlocked(LogTag, f);
        if (LogStat & LOG_PID) {
            const pid_t pid = ((0 == cpid) ? getpid() : cpid);
            if (LogStat & LOG_TID) {
                const pid_t tid = ((0 == ctid) ? gettid() : ctid);
                fprintf(f, "[%d:%d]", (int) pid, (int) tid);
            } else {
                fprintf(f, "[%d]", (int) pid);
            }
        }

        if (LogStat & LOG_RDTSC) {
            const unsigned long long int t = rdtsc();
            fprintf(f, "(%llu)", t);
        } /* (LogStat & LOG_RDTSC) */

        if (LogStat & LOG_CLOCK) {
            #if HAVE_CLOCK_GETTIME
                struct timespec timeStamp;
                if (clock_gettime(CLOCK_MONOTONIC,&timeStamp) == 0) {
                    fprintf(f,"(%lu.%.9d)",timeStamp.tv_sec,timeStamp.tv_nsec);
                } else {
                    const int error = errno;
                    ERROR_MSG("clock_gettime CLOCK_MONOTONIC error %d (%m)",error);
            }
            #else
                static unsigned int alreadyPrinted = 0;
                if (unlikely(0 == alreadyPrinted)) {
                    ERROR_MSG("clock_gettime  not available on this system");
                    alreadyPrinted = 1;
                }
            #endif
        }  /* (LogStat & LOG_CLOCK) */

        if (LogStat & LOG_LEVEL) {
            switch (LOG_PRI(pri)) {
                case LOG_EMERG:
                    fprintf(f, "[EMERG]");
                    break;
                case LOG_ALERT:
                    fprintf(f, "[ALERT]");
                    break;
                case LOG_CRIT:
                    fprintf(f, "[CRIT]");
                    break;
                case LOG_ERR:
                    fprintf(f, "[ERROR]");
                    break;
                case LOG_WARNING:
                    fprintf(f, "[WARNING]");
                    break;
                case LOG_NOTICE:
                    fprintf(f, "[NOTICE]");
                    break;
                case LOG_INFO:
                    fprintf(f, "[INFO]");
                    break;
                case LOG_DEBUG:
                    fprintf(f, "[DEBUG]");
                    break;
            } /* switch(LOG_PRI(pri))*/
        } /* (LogStat & LOG_LEVEL) */

        if (LogTag != NULL) {
            putc_unlocked(':', f);
            putc_unlocked(' ', f);
        }

        /* Restore errno for %m format.  */
        __set_errno(saved_errno);

        /* We have the header.  Print the user's format into the
         buffer.  */
        if (flag == -1) {
            vfprintf(f, fmt, ap);
        } else {
            __vfprintf_chk(f, flag, fmt, ap);
        }

        /* Close the memory stream; this will finalize the data
           into a malloc'd buffer in BUF.  */
        fclose(f);
    }

    /* Output to stderr if requested. */
    if (LogStat & LOG_PERROR) {
        struct iovec iov[2];
        register struct iovec *v = iov;

        v->iov_base = buf + msgoff;
        v->iov_len = bufsize - msgoff;
        /* Append a newline if necessary.  */
        if (buf[bufsize - 1] != '\n') {
            ++v;
            v->iov_base = (char *) "\n";
            v->iov_len = 1;
        }

        pthread_cleanup_push(free, buf == failbuf ? NULL : buf);

        /* writev is a cancellation point.  */
        (void) writev(STDERR_FILENO, iov, v - iov + 1);

        pthread_cleanup_pop(0);
    }

    /* Prepare for multiple users.  We have to take care: open and
  write are cancellation points.  */
    struct cleanup_arg clarg;
    clarg.buf = buf;
    clarg.oldaction = NULL;
    pthread_cleanup_push(cancel_handler, &clarg);
    pthread_mutex_lock(&syslogex_lock);

#ifndef NO_SIGPIPE
    /* Prepare for a broken connection.  */
    memset(&action, 0, sizeof (action));
    action.sa_handler = sigpipe_handler;
    sigemptyset(&action.sa_mask);
    sigpipe = __sigaction(SIGPIPE, &action, &oldaction);
    if (sigpipe == 0)
        clarg.oldaction = &oldaction;
#endif

    /* Get connected, output the message to the local logger. */
    if (!connected) {
        openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);
    }

    /* If we have a SOCK_STREAM connection, also send ASCII NUL as
  a record terminator.  */
    if (LogType == SOCK_STREAM) {
        ++bufsize;
    }

    if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) {
        if (connected) {
            /* Try to reopen the syslog connection.  Maybe it went
          down.  */
            closelog_internal();
            openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);
        }

        if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) {
            closelog_internal(); /* attempt re-open next time */
            /*
             * Output the message to the console; don't worry
             * about blocking, if console blocks everything will.
             * Make sure the error reported is the one from the
             * syslogd failure.
             */
            if (LogStat & LOG_CONS &&
                    (fd = __open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY, 0)) >= 0) {
                dprintf(fd, "%s\r\n", buf + msgoff);
                (void) __close(fd);
            }
        }
    }

#ifndef NO_SIGPIPE
    if (sigpipe == 0)
        __sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL);
#endif

    /* End of critical section.  */
    pthread_cleanup_pop(0);
    pthread_mutex_unlock(&syslogex_lock);

    if (buf != failbuf) {
        free(buf);
    }
}
Exemplo n.º 25
0
void gregorio_messagef(const char *function_name,
        gregorio_verbosity verbosity, int line_number,
        const char *format, ...)
{
    va_list args;
    const char *verbosity_str;

    if (!debug_messages && verbosity != VERBOSITY_ASSERTION) {
        line_number = 0;
        function_name = NULL;
    }

    /* if these assertions fail, the program is not using this code correctly */
    assert(error_out);
    assert(verbosity_mode);

    if (verbosity < verbosity_mode) {
        return;
    }
    if (verbosity == VERBOSITY_ASSERTION && return_value) {
        /* if something has already caused the system to fail, demote any
         * assertions coming after to warnings */
        verbosity = VERBOSITY_WARNING;
    }
    verbosity_str = verbosity_to_str(verbosity);
    if (line_number) {
        /* if line number is specified, function_name must be specified */
        assert(function_name);
        if (function_name) {
            fprintf(error_out, "%d: in function `%s': %s", line_number,
                    function_name, verbosity_str);
        }
    } else {
        if (function_name) {
            fprintf(error_out, "in function `%s': %s", function_name,
                    verbosity_str);
        } else {
            fprintf(error_out, "%s", verbosity_str);
        }
    }
    va_start(args, format);
    vfprintf(error_out, format, args);
    va_end(args);
    fprintf(error_out, "\n");

    switch (verbosity) {
    case VERBOSITY_DEPRECATION:
        /* if there is no deprecation, these lines will not be hit */
        /* LCOV_EXCL_START */
        if (deprecation_is_warning) {
            break;
        }
        /* LCOV_EXCL_STOP */
        /* else fall through */
    case VERBOSITY_ERROR:
    case VERBOSITY_ASSERTION:
        return_value = 1;
        break;
    case VERBOSITY_FATAL:
        /* all fatal errors should not be reasonably testable */
        /* LCOV_EXCL_START */
        gregorio_exit(1);
        break;
        /* LCOV_EXCL_STOP */
    default:
        break;
    }
}
Exemplo n.º 26
0
void info(const char *args, ...) {
  va_list ap;
  va_start(ap, args);
  vfprintf(stdout, args, ap);
  fflush(stdout);
}
Exemplo n.º 27
0
void xa_dbprint(char* format, ...) {
    va_list args;
    va_start(args, format);
    vfprintf(stdout, format, args);
    va_end(args);
}
Exemplo n.º 28
0
int vprintf(const char *format,va_list list)
{ /*Write to the stdout.*/
   return vfprintf(stdout,format,list);
}
Exemplo n.º 29
0
void mame_file_output_callback(FILE *param, const char *format, va_list argptr)
{
	vfprintf(param, format, argptr);
}
Exemplo n.º 30
0
Arquivo: live.c Projeto: Bevara/GPAC
static void on_logs(void *cbk, u32 ll, u32 lm, const char *fmt, va_list list)
{
	FILE *logs = cbk;
	vfprintf(logs, fmt, list);
	fflush(logs);
}