Exemple #1
0
int debug(char * fmt, ...)
{
	va_list ap;
	int ret;

	if (!cfg.debug)
		return 0;

	va_start(ap, fmt);
	if (cfg.syslog)
	{
		openlog(NAME, LOG_PID | LOG_CONS, LOG_DAEMON);
		vsyslog(LOG_DEBUG, fmt, ap);
		closelog();
		ret = 0;
	}
	else
		ret = vfprintf(stderr, fmt, ap);
	va_end(ap);

	return ret;
}
Exemple #2
0
void icmsg_print(ICMSG_LEVEL lvl, const char *format, ...)
{
	va_list ap;
	int priority;

	va_start(ap, format);
	vprintf(format, ap);
	va_end(ap);

	if (use_syslog) {
		va_start(ap, format);
		switch (lvl) {
		case ICMSG_ERROR: priority = LOG_ERR; break;
		case ICMSG_WARNING: priority = LOG_WARNING; break;
		case ICMSG_NOTICE: priority = LOG_NOTICE; break;
		case ICMSG_DEBUG: priority = LOG_DEBUG; break;
		default: priority = LOG_INFO; break;
		}
		vsyslog(priority, format, ap);
		va_end(ap);
	}
}
Exemple #3
0
void Log0(const char * file,int line,const int level,char *fmt,...){
	assert(file);
	assert(line);

	if(level >= debug_level)
		return;

	if(debug_flags != 0){
		va_list ap;
		if(debug_flags & DEBUG_STDOUT)
		{
			va_start(ap, fmt);
			switch(level){
				case LOG_EMERG:
				case LOG_ALERT:
				case LOG_CRIT:
				case LOG_ERR:
				case LOG_WARNING:
					fprintf(stderr, "%s:%d->",file,line);
	    			vfprintf(stderr, fmt, ap);
	    			break;					
				case LOG_NOTICE:
				case LOG_INFO:
				case LOG_DEBUG:
					fprintf(stdout, "%s:%d->",file,line);
					vfprintf(stdout, fmt, ap);
					break;
			};
			va_end(ap);
		}

		if(debug_flags & DEBUG_SYSLOG)
		{
			va_start(ap, fmt);
			vsyslog(level, fmt, ap);
		    va_end(ap);
		}
	}
}
Exemple #4
0
// write_log: call to log a message. If syslog is not enabled then error
// message are written to STDERR, other messages are written to STDOUT.  If
// syslog is enabled then error messages are sent with LOG_ERR, other messages
// with LOG_INFO. syslog messages are sent with the LOG_USER facility.
void write_log(int e,                // If set this is an error message
               const char *fmt, ...) // printf style
{
    // Note the use of [] here. When syslogging, syslog will strip them off and
    // create a message using that as the name of the program.

    char * name = "[kssl_server] ";
    char * newfmt;
    va_list l;

    if ((silent && !use_syslog) || (!e && !verbose)) {
        return;
    }

    // +1 for the terminating 0
    // +1 for the \n we append in non-syslog mode

    newfmt = (char *)malloc(strlen(fmt)+1+strlen(name)+1);
    strcpy(newfmt, name);
    strcat(newfmt, fmt);

    va_start(l, fmt);

    // Note the syntax abuse below. Be careful to look at the dandling
    // } else

#if PLATFORM_WINDOWS == 0
    if (use_syslog) {
        vsyslog(LOG_USER | (e?LOG_ERR:LOG_INFO), newfmt, l);
    } else
#endif
    {
        strcat(newfmt, "\n");
        vfprintf(e?stderr:stdout, newfmt, l);
    }

    va_end(l);
    free(newfmt);
}
Exemple #5
0
void
log_info(const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    if (rpcapd_opt.use_syslog) {
#ifdef WIN32
        char msg[1024];
        char *pmsg = msg;
        vsnprintf(msg, sizeof(msg), fmt, ap);
        ReportEvent(event_source, EVENTLOG_INFORMATION_TYPE, 0, MSG_INFO, NULL,
                    1, 0, &pmsg, NULL);
#else
        vsyslog(LOG_MAKEPRI(LOG_DAEMON, LOG_INFO), fmt, ap);
#endif
    }
    else {
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, "\n");
    }
    va_end(ap);
}
/**
 * Log a message to the system log file (e.g. syslog on Unix).
 *
 * @param severity a severity value
 * @param msg a printf-style format string
 * @param args arguments for the format string
 *
 * If the FATAL severity is given, this function will terminate the program
 * with an error code.
 */
void
_dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
{
#ifdef HAVE_SYSLOG_H
  int flags;
  switch (severity)
    {
      case DBUS_SYSTEM_LOG_INFO:
        flags =  LOG_DAEMON | LOG_NOTICE;
        break;
      case DBUS_SYSTEM_LOG_SECURITY:
        flags = LOG_AUTH | LOG_NOTICE;
        break;
      case DBUS_SYSTEM_LOG_FATAL:
        flags = LOG_DAEMON|LOG_CRIT;
        break;
      default:
        return;
    }

  vsyslog (flags, msg, args);
#endif

#if !defined(HAVE_SYSLOG_H) || !HAVE_DECL_LOG_PERROR
    {
      /* vsyslog() won't write to stderr, so we'd better do it */
      va_list tmp;

      DBUS_VA_COPY (tmp, args);
      fprintf (stderr, "dbus[" DBUS_PID_FORMAT "]: ", _dbus_getpid ());
      vfprintf (stderr, msg, tmp);
      fputc ('\n', stderr);
      va_end (tmp);
    }
#endif

  if (severity == DBUS_SYSTEM_LOG_FATAL)
    exit (1);
}
Exemple #7
0
void
log_Printf(int lev, const char *fmt,...)
{
  va_list ap;
  struct prompt *prompt;

  if (log_IsKept(lev)) {
    char nfmt[200];

    va_start(ap, fmt);
    if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
      if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
	         LogTunno, log_Name(lev), fmt);
      else
        snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);

      if (log_PromptContext && lev == LogWARN)
        /* Warnings just go to the current prompt */
        prompt_vPrintf(log_PromptContext, nfmt, ap);
      else for (prompt = promptlist; prompt; prompt = prompt->next)
        if (lev > LogMAXCONF || (prompt->logmask & MSK(lev)))
          prompt_vPrintf(prompt, nfmt, ap);
    }
    va_end(ap);

    va_start(ap, fmt);
    if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
        (lev != LogWARN || !log_PromptContext)) {
      if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
	         LogTunno, log_Name(lev), fmt);
      else
        snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
      vsyslog(syslogLevel(lev), nfmt, ap);
    }
    va_end(ap);
  }
}
Exemple #8
0
void log_message (int priority, const char *format, ...)
{
	va_list args;
	static int udev_log = -1;

	if (udev_log == -1) {
		const char *value;

		value = getenv("UDEV_LOG");
		if (value)
			udev_log = log_priority(value);
		else
			udev_log = LOG_ERR;
	}

	if (priority > udev_log)
		return;

	va_start(args, format);
	vsyslog(priority, format, args);
	va_end(args);
}
void nhrp_log(int level, const char *format, ...)
{
	va_list va;
	int l;

	switch (level) {
	case NHRP_LOG_ERROR:
		l = LOG_ERR;
		break;
	case NHRP_LOG_INFO:
		l = LOG_INFO;
		break;
	case NHRP_LOG_DEBUG:
	default:
		l = LOG_DEBUG;
		break;
	}

	va_start(va, format);
	vsyslog(l, format, va);
	va_end(va);
}
Exemple #10
0
void
error(int fatal, const char *fmt,...)
{
	va_list ap;

	if (dflag) {
		if (fatal)
			(void) fprintf(stderr, "rarpd: error: ");
		else
			(void) fprintf(stderr, "rarpd: warning: ");
		va_start(ap, fmt);
		(void) vfprintf(stderr, fmt, ap);
		va_end(ap);
		(void) fprintf(stderr, "\n");
	}
	va_start(ap, fmt);
	vsyslog(LOG_ERR, fmt, ap);
	va_end(ap);
	if (fatal)
		exit(1);
	/* NOTREACHED */
}
Exemple #11
0
void log_access( const char *fmt, ... )
{
	va_list args;

	if(stdaccess) {
		log_date(stdaccess);

		va_start( args, fmt );
		vfprintf( stdaccess, fmt, args );
		va_end( args );
		fprintf( stdaccess, "\n");
#ifdef NETDATA_INTERNAL_CHECKS
		fflush( stdaccess );
#endif
	}

	if(access_log_syslog) {
		va_start( args, fmt );
		vsyslog(LOG_INFO,  fmt, args );
		va_end( args );
	}
}
Exemple #12
0
void
lsass_vsyslog(
    int priority,
    const char *format,
    va_list ap
    )
{
#if defined(HAVE_VSYSLOG)
    vsyslog(priority, format, ap);
#else
    DWORD dwError;
    PSTR buffer = NULL;

    dwError = LwAllocateStringPrintfV(&buffer, format, ap);
    if (!dwError)
    {
        syslog(priority, "%s", buffer);
    }

    LW_SAFE_FREE_STRING(buffer);
#endif /* ! HAVE_VSYSLOG */
}
Exemple #13
0
static void
zfs_util_log(const char *format, ...)
{
	if (zfs_util_debug == 0)
		return;

	va_list args;
	char buf[1024];

	setlogmask(LOG_UPTO(LOG_NOTICE));

	va_start(args, format);
	(void) vsnprintf(buf, sizeof (buf), format, args);
	fputs(buf, stderr);
	va_end(args);

	if (*(&buf[strlen(buf) - 1]) == '\n')
		*(&buf[strlen(buf) - 1]) = '\0';
	va_start(args, format);
	vsyslog(LOG_NOTICE, format, args);
	va_end(args);
}
static void error(const char *fmt, ...)
{
	va_list va;

	if (xdebug) {
		va_start(va, fmt);
		vfprintf(stderr, fmt, va);
		va_end(va);
	}

	if (!xnolog) {
		openlog("request-key", 0, LOG_AUTHPRIV);

		va_start(va, fmt);
		vsyslog(LOG_ERR, fmt, va);
		va_end(va);

		closelog();
	}

	exit(1);
}
Exemple #15
0
int printf(FAR const IPTR char *fmt, ...)
{
  va_list ap;
  int     ret;

  va_start(ap, fmt);
#if CONFIG_NFILE_STREAMS > 0
  ret = vfprintf(stdout, fmt, ap);
#elif CONFIG_NFILE_DESCRIPTORS > 0
  ret = vsyslog(LOG_INFO, fmt, ap);
#elif defined(CONFIG_ARCH_LOWPUTC)
  ret = lowvsyslog(LOG_INFO, fmt, ap);
#else
# ifdef CONFIG_CPP_HAVE_WARNING
#   warning "printf has no data sink"
# endif
  ret = 0;
#endif
  va_end(ap);

  return ret;
}
Exemple #16
0
inline void lispd_log(
        int         log_level,
        char        *log_name,
        const char  *format,
        va_list     args)
{
    if (daemonize){
#ifdef ANDROID
    	fprintf(fp,"%s: ",log_name);
    	vfprintf(fp,format,args);
    	fprintf(fp,"\n");
    	fflush(fp);
#else
        vsyslog(log_level,format,args);
#endif

    }else{
        printf("%s: ",log_name);
        vfprintf(stdout,format,args);
        printf("\n");
    }
}
Exemple #17
0
void
dhcpmsg(int errlevel, const char *fmt, ...)
{
	va_list		ap;
	char		buf[512];
	char		*errmsg;

	if ((errlevel == MSG_DEBUG2 && (debug_level < 2)) ||
	    (errlevel == MSG_DEBUG && (debug_level < 1)) ||
	    (errlevel == MSG_VERBOSE && !is_verbose))
		return;

	va_start(ap, fmt);

	/*
	 * either log to stderr, or log to syslog.  print out unix
	 * error message if errlevel is MSG_ERR and errno is set
	 */

	if (is_daemon) {
		(void) snprintf(buf, sizeof (buf), (errlevel == MSG_ERR &&
		    errno != 0) ? "%s: %%m\n" : "%s\n", gettext(fmt));
		(void) vsyslog(err_to_syslog(errlevel), buf, ap);
	} else {
		errmsg = strerror(errno);
		if (errmsg == NULL)
			errmsg = dgettext(TEXT_DOMAIN, "<unknown error>");

		(void) snprintf(buf, sizeof (buf), (errlevel == MSG_ERR &&
		    errno != 0) ? "%s: %s: %s: %s\n" : "%s: %s: %s\n", program,
		    dgettext(TEXT_DOMAIN, err_to_string(errlevel)),
		    gettext(fmt), errmsg);

		(void) vfprintf(stderr, buf, ap);
	}

	va_end(ap);
}
Exemple #18
0
EXTERNAL void
surfman_vmessage(surfman_loglvl level, const char *fmt, va_list ap)
{
  va_list ap2;
  int syslog_lvl = LOG_DEBUG;

  va_copy(ap2, ap);

  switch (level)
    {
      case SURFMAN_DEBUG:
        syslog_lvl = LOG_DEBUG;
        break;
      case SURFMAN_INFO:
        syslog_lvl = LOG_INFO;
        break;
      case SURFMAN_WARNING:
        syslog_lvl = LOG_WARNING;
        break;
      case SURFMAN_ERROR:
        syslog_lvl = LOG_ERR;
        break;
      case SURFMAN_FATAL:
        syslog_lvl = LOG_EMERG;
        break;
    }

  // TODO: Make that configurable (output logfile/syslog or not/stderr or not)
  vsyslog(syslog_lvl, fmt, ap);

  vfprintf(stderr, fmt, ap2);

  if (level == MESSAGE_FATAL)
    {
      bt();
      abort();
    }
}
Exemple #19
0
void pool_error(const char *fmt,...)
{
	va_list		ap;
#ifdef HAVE_ASPRINTF
	char		*fmt2;
    int         len;
#endif

#ifdef HAVE_SIGPROCMASK
	sigset_t oldmask;
#else
	int	oldmask;
#endif
	/* Write error message to syslog */
	if (pool_config->logsyslog == 1) {
	   va_start(ap, fmt);
	   vsyslog(pool_config->syslog_facility | LOG_ERR, fmt, ap);
	   va_end(ap);
	   return;
	}

	POOL_SETMASK2(&BlockSig, &oldmask);
	/*TODO
	if (pool_config->print_timestamp)*/
#ifdef HAVE_ASPRINTF
	  len = asprintf(&fmt2, "%s ERROR: pid %d: %s\n", nowsec(), (int)getpid(), fmt);

   if (len >= 0 && fmt2)
   {
     va_start(ap, fmt);
     vfprintf(stderr, fmt2, ap);
     va_end(ap);
     fflush(stderr);
	 free(fmt2);
   }
#else
	  fprintf(stderr, "%s ERROR: pid %d: ", nowsec(), (int)getpid());
	else
Exemple #20
0
void
logmsg(int level, char *fmt, ...)
{
  va_list ap;
  FILE *where = stdout;

  va_start(ap, fmt);

  if (console)
    {
      switch (level)
	{
	  case LOG_INFO:
	    fprintf(where, "I: ");
	    break;

	  case LOG_WARNING:
	    fprintf(where, "W: ");
	    break;

	  case LOG_ERR:
	    where = stderr;
	    fprintf(where, "E: ");
	    break;

	  default:
	    break;
	}
      vfprintf(where, fmt, ap);
      fprintf(where, "\n");
    }
  else
    {
      vsyslog(level | LOG_DAEMON, fmt, ap);
    }

  va_end(ap);
}
Exemple #21
0
/** @internal
Do not use directly, use the debug macro */
void
_debug(char *filename, int line, int level, char *format, ...)
{
    char buf[28];
    va_list vlist;
    s_config *config = config_get_config();
    time_t ts;

    time(&ts);

    if (config->debuglevel >= level) {

        if (level <= LOG_WARNING) {
            fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
                    filename, line);
            va_start(vlist, format);
            vfprintf(stderr, format, vlist);
            va_end(vlist);
            fputc('\n', stderr);
        } else if (!config->daemon) {
            fprintf(stdout, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
                    filename, line);
            va_start(vlist, format);
            vfprintf(stdout, format, vlist);
            va_end(vlist);
            fputc('\n', stdout);
            fflush(stdout);
        }

        if (config->log_syslog) {
            openlog("wifidog", LOG_PID, config->syslog_facility);
            va_start(vlist, format);
            vsyslog(level, format, vlist);
            va_end(vlist);
            closelog();
        }
    }
}
Exemple #22
0
void
vlog(int pri, const char *fmt, va_list ap)
{
	char	*nfmt;
	int ret;

	if (__log_debug != TBLOG_SYSLOG) {
		if (__log_debug == TBLOG_TRACE)
			ret = asprintf(&nfmt, "%05d: %s\n", __log_pid, fmt);
		else
			ret = asprintf(&nfmt, "%s\n", fmt);
		/* best effort in out of mem situations */
		if (ret == -1) {
			vfprintf(stderr, fmt, ap);
			fprintf(stderr, "\n");
		} else {
			vfprintf(stderr, nfmt, ap);
			free(nfmt);
		}
		fflush(stderr);
	} else
		vsyslog(pri, fmt, ap);
}
Exemple #23
0
void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    log_date(stderr);

    va_start( args, fmt );
    if(debug_flags) fprintf(stderr, "FATAL (%[email protected]%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
    else            fprintf(stderr, "FATAL: %s: ", program_name);
    vfprintf( stderr, fmt, args );
    va_end( args );

    perror(" # ");
    fputc('\n', stderr);

    if(error_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_CRIT,  fmt, args );
        va_end( args );
    }

    netdata_cleanup_and_exit(1);
}
Exemple #24
0
void info_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... )
{
    va_list args;

    // prevent logging too much
    if(error_log_limit(0)) return;

    log_date(stderr);

    va_start( args, fmt );
    if(debug_flags) fprintf(stderr, "INFO (%[email protected]%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
    else            fprintf(stderr, "INFO: %s: ", program_name);
    vfprintf( stderr, fmt, args );
    va_end( args );

    fputc('\n', stderr);

    if(error_log_syslog) {
        va_start( args, fmt );
        vsyslog(LOG_INFO,  fmt, args );
        va_end( args );
    }
}
Exemple #25
0
static int transact( int pri, char* fmt, ... )
{
    va_list ap;
    DWORD r;

    va_start( ap, fmt );
    vsyslog( pri, fmt, ap );
    va_end( ap );
    r = WaitForSingleObject( hRxEvent, 2000 );
    if( WAIT_TIMEOUT == r )
    {
        fprintf( stderr, "timeout\n" );
        return -1;
    }
    if( WAIT_FAILED == r )
    {
        fprintf( stderr, "wait failed, error %lu\n", GetLastError() );
        return -1;
    }
    printf( "*** %s\n", buffer );
    SetEvent( hAckEvent );
    return 0;
}
/*
 * This message means an internal bug in exFAT implementation.
 */
void exfat_bug(const char* format, ...)
{
	va_list ap, aq;

	va_start(ap, format);
	va_copy(aq, ap);

	fflush(stdout);
	fputs("BUG: ", stderr);
	vfprintf(stderr, format, ap);
	va_end(ap);
	fputs(".\n", stderr);

	if (!isatty(STDERR_FILENO))
		vsyslog(LOG_CRIT, format, aq);
	va_end(aq);

#if defined(__ANDROID__)
    exit(-1);
#else
	abort();
#endif
}
Exemple #27
0
void userlog(int priority, const char* format, ...) {
  va_list ap;

  va_start(ap, format);
  vsyslog(priority, format, ap);
  va_end(ap);

  if (self_test) {
    const char* level = "debug";
    switch (priority) {
      case LOG_ERR:  level = "error"; break;
      case LOG_WARNING:  level = " warn"; break;
      case LOG_INFO:  level = " info"; break;
    }
    printf("fsnotifier[%d] %s: ", getpid(), level);

    va_start(ap, format);
    vprintf(format, ap);
    va_end(ap);

    printf("\n");
  }
}
Exemple #28
0
void quit_daemon (char *format, ...) {
	va_list args;

	va_start(args, format);


	if (MFC.syslog) {
		vsyslog(LOG_ERR, format, args);
		closelog();
	}

	if (MFC.stdout) {
		vprintf(format, args);
		printf("\n");
	}

	va_end(args);

	if (MFC.pidfile) {
		unlink(PIDFILE);
	}
	exit(EXIT_FAILURE);
}
Exemple #29
0
void applog(int prio, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	if (use_syslog) {
		vsyslog(prio, fmt, ap);
	} else {
		char *f;
		int len;
		struct timeval tv = { };

		gettimeofday(&tv, NULL);

		len = 40 + strlen(fmt) + 2;
		f = alloca(len);
		sprintf(f, "[%.6f] %s\n",
			tv.tv_sec +
			tv.tv_usec/1000000.0, fmt);
		vfprintf(stderr, f, ap);	/* atomic write to stderr */
	}
	va_end(ap);
}
Exemple #30
0
void error(const char *fmt, ...)
{
	va_list va;

	va_start(va, fmt);
	if (isatty(2)) {
		vfprintf(stderr, fmt, va);
		fputc('\n', stderr);
	} else {
		vsyslog(LOG_ERR, fmt, va);
	}
	va_end(va);

	/*
	 * on error, negatively instantiate the key ourselves so that we can
	 * make sure the kernel doesn't hang it off of a searchable keyring
	 * and interfere with the next attempt to instantiate the key.
	 */
	if (!debug_mode)
		keyctl_negate(key, 1, KEY_REQKEY_DEFL_DEFAULT);

	exit(1);
}