Пример #1
0
void ls_write_log( ChannelLog *cl, const char *fmt, ... )
{
	static char log_buf[BUFSIZE];
	va_list ap;
	
	/* format the string to write */
	va_start( ap, fmt );
	ircvsnprintf( log_buf, BUFSIZE, fmt, ap );
	va_end( ap );
	                                
	/* if the FD isn't opened yet, lets open a log file */
	if( cl->logfile == NULL  ) {
		if( ls_open_log( cl ) != NS_SUCCESS ) {
			return;
		}
	}
	/* ok, file is opened. write the string to it */
#ifdef DEBUG
	dlog( DEBUG1, "%s\n", log_buf );
#endif
	os_fprintf( cl->logfile, "%s", log_buf );
	cl->writecount++;
#ifdef DEBUG
	/* only flush the logfile in debug mode */
	os_fflush( cl->logfile );
#endif
	/* ok, now stat the file to check size */
	if( cl->writecount >= DOSIZE ) { 
		os_fflush( cl->logfile );
		ls_stat_file( cl );
	}
}
Пример #2
0
void
ilog(ilogfile dest, const char *format, ...)
{
    FILE *logfile = *log_table[dest].logfile;
    char buf[BUFSIZE];
    char buf2[BUFSIZE];
    va_list args;

    if(logfile == NULL)
        return;

    va_start(args, format);
    ircvsnprintf(buf, sizeof(buf), format, args);
    va_end(args);

    ircsnprintf(buf2, sizeof(buf2), "%s %s\n", smalldate(), buf);

    if(fputs(buf2, logfile) < 0)
    {
        fclose(logfile);
        *log_table[dest].logfile = NULL;
    }

    fflush(logfile);
}
Пример #3
0
void fatal_perror(const char *fmt, ...)
{
    va_list args;
    char *buf, buf2[4096];
    int errno_save = errno;
#ifdef _WIN32
    char errbuf[256];
#else
    char *errbuf;
#endif

#ifdef _WIN32
    strerror_s(errbuf, sizeof(errbuf), errno_save);
#else
    errbuf = strerror(errno_save);
#endif

    checkday();

    buf = log_gettimestamp();

    va_start(args, fmt);
    ircvsnprintf(buf2, sizeof(buf2), fmt, args);
    va_end(args);
    if (!NoLogs && logfile)
        fprintf(logfile, "%sFATAL: %s: %s\n", buf, buf2, errbuf);

    if (stderr)
        fprintf(stderr, "%sFATAL: %s: %s\n", buf, buf2, errbuf);

    if (servsock >= 0)
        denora_cmd_global(NULL, langstring(GLOBAL_FATAL_ERROR), buf2,
                          errbuf);
    exit(1);
}
Пример #4
0
void alog(int type, const char *fmt, ...)
{
    va_list args;
    int errno_save = errno;
    char str[BUFSIZE];
    char *buf;
    *str = '\0';

    if (!fmt) {
        return;
    }

    if ((type == LOG_DEBUG || type == LOG_EXTRADEBUG
         || type == LOG_NONEXISTANT) && !denora->debug) {
        return;
    }
    if ((type == LOG_PROTOCOL) && !denora->protocoldebug) {
        return;
    }
    if (type == LOG_SQLDEBUG && !denora->sqldebug) {
        return;
    }
    if (LOG_EXTRADEBUG == type && denora->debug <= 1) {
        return;
    }
    if ((type == LOG_DEBUGSOCK || type == LOG_ADNS)
        && !denora->socketdebug) {
        return;
    }

    checkday();

    va_start(args, fmt);
    ircvsnprintf(str, sizeof(str), fmt, args);
    va_end(args);

    buf = log_gettimestamp();

    if (!NoLogs && logfile) {
        fprintf(logfile, "%s %s\n", buf, str);
    }

    if (denora->nofork) {
        fprintf(stderr, "%s %s\n", buf, str);
    }

    if (!BadPtr(LogChannel) && denora->debug < 2 && findchan(LogChannel)) {
        if (type == LOG_NORMAL || type == LOG_NONEXISTANT
            || type == LOG_ERROR) {
            privmsg(s_StatServ, LogChannel, "%s", str);
        }
    }
    errno = errno_save;
}
Пример #5
0
void load_module_error( const Client *target, const char *module_name, const char *fmt, ... )
{
	static char buf[BUFSIZE];
	va_list ap;

	va_start( ap, fmt );
	ircvsnprintf( buf, BUFSIZE, fmt, ap );
	va_end( ap );
	if( target ) {
		irc_prefmsg( ns_botptr, target, __( "Unable to load module %s: %s", u ), module_name, buf );
	}
	nlog( LOG_WARNING, buf );
}
Пример #6
0
/*
 * fd_note() - set the fd note
 *
 * Note: must be careful not to overflow fd_table[fd].desc when
 *       calling.
 */
void
fd_note(int fd, const char *format, ...)
{
	va_list args;

	if(format)
	{
		va_start(args, format);
		ircvsnprintf(fd_table[fd].desc, FD_DESC_SZ, format, args);
		va_end(args);
	}
	else
		fd_table[fd].desc[0] = '\0';
}
Пример #7
0
void log_perror(const char *fmt, ...)
{
    va_list args;
    int errno_save = errno;
    char str[BUFSIZE];
    char *buf;
#ifdef _WIN32
    char errbuf[256];
#else
    char *errbuf;
#endif

#ifdef _WIN32
    strerror_s(errbuf, sizeof(errbuf), errno_save);
#else
    errbuf = strerror(errno_save);
#endif

    checkday();

    if (!fmt) {
        return;
    }
    buf = log_gettimestamp();

    va_start(args, fmt);
    ircvsnprintf(str, sizeof(str), fmt, args);
    va_end(args);

    if (!NoLogs && logfile) {
        fprintf(logfile, "%s %s : %s\n", buf, str, errbuf);
    }
    if (denora->nofork) {
        fprintf(stderr, "%s %s : %s\n", buf, str, errbuf);
    }
    errno = errno_save;
}
Пример #8
0
/* irc logs.. */
void ircd_log(int flags, char *format, ...)
{
static int last_log_file_warning = 0;
static char recursion_trap=0;

	va_list ap;
	ConfigItem_log *logs;
	char buf[2048], timebuf[128];
	struct stat fstats;
	int written = 0, write_failure = 0;
	int n;

	/* Trap infinite recursions to avoid crash if log file is unavailable,
	 * this will also avoid calling ircd_log from anything else called
	 */
	if (recursion_trap == 1)
		return;

	recursion_trap = 1;
	va_start(ap, format);
	ircvsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);
	snprintf(timebuf, sizeof(timebuf), "[%s] - ", myctime(TStime()));

	RunHook3(HOOKTYPE_LOG, flags, timebuf, buf);
	strlcat(buf, "\n", sizeof(buf));

	if (!loop.ircd_forked && (flags & LOG_ERROR))
		fprintf(stderr, "%s", buf);

	for (logs = conf_log; logs; logs = (ConfigItem_log *) logs->next) {
#ifdef HAVE_SYSLOG
		if (!stricmp(logs->file, "syslog") && logs->flags & flags) {
			syslog(LOG_INFO, "%s", buf);
			written++;
			continue;
		}
#endif
		if (logs->flags & flags)
		{
			if (stat(logs->file, &fstats) != -1 && logs->maxsize && fstats.st_size >= logs->maxsize)
			{
				char oldlog[512];
				if (logs->logfd != -1)
				{
					write(logs->logfd, "Max file size reached, starting new log file\n", 45);
					fd_close(logs->logfd);
				}
				
				/* Rename log file to xxxxxx.old */
				snprintf(oldlog, sizeof(oldlog), "%s.old", logs->file);
				rename(logs->file, oldlog);
				
				logs->logfd = fd_fileopen(logs->file, O_CREAT|O_WRONLY|O_TRUNC);
				if (logs->logfd == -1)
					continue;
			}
			else if (logs->logfd == -1) {
#ifndef _WIN32
				logs->logfd = fd_fileopen(logs->file, O_CREAT|O_APPEND|O_WRONLY);
#else
				logs->logfd = fd_fileopen(logs->file, O_CREAT|O_APPEND|O_WRONLY);
#endif
				if (logs->logfd == -1)
				{
					if (!loop.ircd_booted)
					{
						config_status("WARNING: Unable to write to '%s': %s", logs->file, strerror(ERRNO));
					} else {
						if (last_log_file_warning + 300 < TStime())
						{
							config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", logs->file, strerror(ERRNO));
							last_log_file_warning = TStime();
						}
					}
					write_failure = 1;
					continue;
				}
			}
			/* this shouldn't happen, but lets not waste unnecessary syscalls... */
			if (logs->logfd == -1)
				continue;
			write(logs->logfd, timebuf, strlen(timebuf));
			n = write(logs->logfd, buf, strlen(buf));
			if (n == strlen(buf))
			{
				written++;
			}
			else
			{
				if (!loop.ircd_booted)
				{
					config_status("WARNING: Unable to write to '%s': %s", logs->file, strerror(ERRNO));
				} else {
					if (last_log_file_warning + 300 < TStime())
					{
						config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", logs->file, strerror(ERRNO));
						last_log_file_warning = TStime();
					}
				}

				write_failure = 1;
			}
#ifndef _WIN32
			fsync(logs->logfd);
#endif
		}
	}

	recursion_trap = 0;
}
Пример #9
0
/* irc logs.. */
void ircd_log(int flags, char *format, ...)
{
static int last_log_file_warning = 0;

	va_list ap;
	ConfigItem_log *logs;
	char buf[2048], timebuf[128];
	struct stat fstats;
	int written = 0, write_failure = 0;

	va_start(ap, format);
	ircvsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);
	snprintf(timebuf, sizeof(timebuf), "[%s] - ", myctime(TStime()));
	RunHook3(HOOKTYPE_LOG, flags, timebuf, buf);
	strlcat(buf, "\n", sizeof(buf));

	for (logs = conf_log; logs; logs = (ConfigItem_log *) logs->next) {
#ifdef HAVE_SYSLOG
		if (!stricmp(logs->file, "syslog") && logs->flags & flags) {
			syslog(LOG_INFO, "%s", buf);
			written++;
			continue;
		}
#endif
		if (logs->flags & flags)
		{
			if (stat(logs->file, &fstats) != -1 && logs->maxsize && fstats.st_size >= logs->maxsize)
			{
				if (logs->logfd != -1)
					fd_close(logs->logfd);
				logs->logfd = fd_fileopen(logs->file, O_CREAT|O_WRONLY|O_TRUNC);
				if (logs->logfd == -1)
					continue;
				if (write(logs->logfd, "Max file size reached, starting new log file\n", 45) < 0)
				{
					write_failure = 1;
					continue;
				}
			}
			else if (logs->logfd == -1) {
				logs->logfd = fd_fileopen(logs->file, O_CREAT|O_APPEND|O_WRONLY);
				if (logs->logfd == -1)
				{
					if (!loop.ircd_booted)
					{
						config_status("WARNING: Unable to write to '%s': %s", logs->file, strerror(ERRNO));
					}
					else
					{
						if (last_log_file_warning + 300 < TStime())
						{
							config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", logs->file, strerror(ERRNO));
							last_log_file_warning = TStime();
						}
					}
					write_failure = 1;
					continue;
				}
			}
			/* this shouldn't happen, but lets not waste unnecessary syscalls... */
			if (logs->logfd == -1)
				continue;
			if (write(logs->logfd, timebuf, strlen(timebuf)) < 0)
			{
				if (!loop.ircd_booted)
				{
					config_status("WARNING: Unable to write to '%s': %s", logs->file, strerror(ERRNO));
				}
				else
				{
					if (last_log_file_warning + 300 < TStime())
					{
						config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", logs->file, strerror(ERRNO));
						last_log_file_warning = TStime();
					}
				}
				write_failure = 1;
			}
			if (write(logs->logfd, buf, strlen(buf)) == strlen(buf))
			{
				written++;
			}
			else
			{
				if (!loop.ircd_booted)
				{
					config_status("WARNING: Unable to write to '%s': %s", logs->file, strerror(ERRNO));
				}
				else
				{
					if (last_log_file_warning + 300 < TStime())
					{
						config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", logs->file, strerror(ERRNO));
						last_log_file_warning = TStime();
					}
				}
				write_failure = 1;
			}
			fsync(logs->logfd);
		}
	}

	/* If nothing got written at all AND we had a write failure AND we are booting, then exit.
	 * Note that we can't just fail when nothing got written, as we might have been called for
	 * 'tkl' for example, which might not be in our log block.
	 */
	if (!written && write_failure && !loop.ircd_booted)
	{
		config_status("ERROR: Unable to write to any log file. Please check your log { } blocks and file permissions!");
		exit(9);
	}
}