"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libhfcommon/log.c" between
honggfuzz-2.1.tar.gz and honggfuzz-2.2.tar.gz

About: honggfuzz is a security oriented, feedback-driven, evolutionary, easy-to-use fuzzer with powerful analysis options.

log.c  (honggfuzz-2.1):log.c  (honggfuzz-2.2)
skipping to change at line 51 skipping to change at line 51
#if defined(_HF_ARCH_LINUX) #if defined(_HF_ARCH_LINUX)
#include <sys/syscall.h> #include <sys/syscall.h>
#define __hf_pid() (pid_t) syscall(__NR_gettid) #define __hf_pid() (pid_t) syscall(__NR_gettid)
#elif defined(_HF_ARCH_NETBSD) #elif defined(_HF_ARCH_NETBSD)
#include <lwp.h> #include <lwp.h>
#define __hf_pid() _lwp_self() #define __hf_pid() _lwp_self()
#else #else
#define __hf_pid() getpid() #define __hf_pid() getpid()
#endif #endif
static int log_fd = STDERR_FILENO; static int hf_log_fd = STDERR_FILENO;
static bool log_fd_isatty = false; static bool hf_log_fd_isatty = false;
enum llevel_t log_level = INFO; enum llevel_t hf_log_level = INFO;
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
__attribute__((constructor)) static void log_init(void) { __attribute__((constructor)) static void log_init(void) {
log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0); hf_log_fd = fcntl(hf_log_fd, F_DUPFD_CLOEXEC, 0);
if (log_fd == -1) { if (hf_log_fd == -1) {
log_fd = STDERR_FILENO; hf_log_fd = STDERR_FILENO;
} }
log_fd_isatty = isatty(log_fd); hf_log_fd_isatty = isatty(hf_log_fd);
} }
/* /*
* Log to stderr by default. Use a dup()d fd, because in the future we'll associ ate the * Log to stderr by default. Use a dup()d fd, because in the future we'll associ ate the
* connection socket with fd (0, 1, 2). * connection socket with fd (0, 1, 2).
*/ */
void logInitLogFile(const char* logfile, int fd, enum llevel_t ll) { void logInitLogFile(const char* logfile, int fd, enum llevel_t ll) {
log_level = ll; hf_log_level = ll;
if (logfile) { if (logfile) {
log_fd = TEMP_FAILURE_RETRY(open(logfile, O_CREAT | O_RDWR | O_TRUNC, 06 hf_log_fd = TEMP_FAILURE_RETRY(open(logfile, O_CREAT | O_RDWR | O_TRUNC,
40)); 0640));
if (log_fd == -1) { if (hf_log_fd == -1) {
log_fd = STDERR_FILENO; hf_log_fd = STDERR_FILENO;
PLOG_E("Couldn't open logfile open('%s')", logfile); PLOG_E("Couldn't open logfile open('%s')", logfile);
} }
} }
if (fd != -1) { if (fd != -1) {
log_fd = fd; hf_log_fd = fd;
} }
log_fd_isatty = (isatty(log_fd) == 1 ? true : false); hf_log_fd_isatty = (isatty(hf_log_fd) == 1 ? true : false);
} }
void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt , ...) { void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt , ...) {
int saved_errno = errno; int saved_errno = errno;
char strerr[512]; char strerr[512];
if (perr == true) { if (perr == true) {
snprintf(strerr, sizeof(strerr), "%s", strerror(saved_errno)); snprintf(strerr, sizeof(strerr), "%s", strerror(saved_errno));
} }
struct ll_t { struct ll_t {
const char* descr; const char* descr;
skipping to change at line 119 skipping to change at line 119
localtime_r(&ltstamp, &utctime); localtime_r(&ltstamp, &utctime);
char timestr[32]; char timestr[32];
if (strftime(timestr, sizeof(timestr) - 1, "%FT%T%z", &utctime) == 0) { if (strftime(timestr, sizeof(timestr) - 1, "%FT%T%z", &utctime) == 0) {
timestr[0] = '\0'; timestr[0] = '\0';
} }
/* Start printing logs */ /* Start printing logs */
{ {
MX_LOCK(&log_mutex); MX_LOCK(&log_mutex);
if (log_fd_isatty) { if (hf_log_fd_isatty) {
dprintf(log_fd, "%s", logLevels[ll].prefix); dprintf(hf_log_fd, "%s", logLevels[ll].prefix);
} }
if (logLevels[ll].print_time) { if (logLevels[ll].print_time) {
dprintf(log_fd, "[%s][%s][%d] ", timestr, logLevels[ll].descr, __hf_ pid()); dprintf(hf_log_fd, "[%s][%s][%d] ", timestr, logLevels[ll].descr, __ hf_pid());
} }
if (logLevels[ll].print_funcline) { if (logLevels[ll].print_funcline) {
dprintf(log_fd, "%s():%d ", fn, ln); dprintf(hf_log_fd, "%s():%d ", fn, ln);
} }
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vdprintf(log_fd, fmt, args); vdprintf(hf_log_fd, fmt, args);
va_end(args); va_end(args);
if (perr == true) { if (perr == true) {
dprintf(log_fd, ": %s", strerr); dprintf(hf_log_fd, ": %s", strerr);
} }
if (log_fd_isatty) { if (hf_log_fd_isatty) {
dprintf(log_fd, "\033[0m"); dprintf(hf_log_fd, "\033[0m");
} }
dprintf(log_fd, "\n"); dprintf(hf_log_fd, "\n");
MX_UNLOCK(&log_mutex); MX_UNLOCK(&log_mutex);
} }
/* End printing logs */ /* End printing logs */
errno = saved_errno; errno = saved_errno;
if (ll == FATAL) { if (ll == FATAL) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
void logStop(int sig) { void logStop(int sig) {
LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig); LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig);
} }
void logRedirectLogFD(int fd) { void logRedirectLogFD(int fd) {
log_fd = fd; hf_log_fd = fd;
log_fd_isatty = isatty(log_fd); hf_log_fd_isatty = isatty(hf_log_fd);
} }
void logDirectlyToFD(const char* msg) { void logDirectlyToFD(const char* msg) {
dprintf(log_fd, "%s", msg); dprintf(hf_log_fd, "%s", msg);
} }
pthread_mutex_t* logMutexGet(void) { pthread_mutex_t* logMutexGet(void) {
return &log_mutex; return &log_mutex;
} }
void logMutexReset(void) { void logMutexReset(void) {
pthread_mutex_init(&log_mutex, NULL); pthread_mutex_init(&log_mutex, NULL);
} }
bool logIsTTY(void) { bool logIsTTY(void) {
return log_fd_isatty; return hf_log_fd_isatty;
} }
int logFd(void) { int logFd(void) {
return log_fd; return hf_log_fd;
} }
enum llevel_t logGetLevel(void) { enum llevel_t logGetLevel(void) {
return log_level; return hf_log_level;
} }
 End of changes. 19 change blocks. 
29 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)