|
Revision 1292, 1.6 kB
(checked in by till, 2 years ago)
|
- safe signal handling through per-process signal pipes
- increased verbosity of debug log messages during initialization phase
- silly pitfalls during build process removed
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
#include <stdio.h> |
|---|
| 14 |
#include <stdarg.h> |
|---|
| 15 |
#include <fcntl.h> |
|---|
| 16 |
#include <unistd.h> |
|---|
| 17 |
#include <string.h> |
|---|
| 18 |
#include <strings.h> |
|---|
| 19 |
|
|---|
| 20 |
#include "honeytrap.h" |
|---|
| 21 |
#include "logging.h" |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
void logmsg(int level, int add_time, const char *format, ...) { |
|---|
| 25 |
char logline[LOGLINE_SIZE]; |
|---|
| 26 |
va_list ap; |
|---|
| 27 |
int bytes_written, logline_size; |
|---|
| 28 |
time_t timeval; |
|---|
| 29 |
|
|---|
| 30 |
if(level <= log_level) { |
|---|
| 31 |
bzero(&logline, LOGLINE_SIZE); |
|---|
| 32 |
va_start(ap, format); |
|---|
| 33 |
if (add_time) { |
|---|
| 34 |
time(&timeval); |
|---|
| 35 |
strftime(logline, 23, "[%F %T] ", localtime(&timeval)); |
|---|
| 36 |
if (log_level == LOG_DEBUG) |
|---|
| 37 |
snprintf(logline + strlen(logline), LOGLINE_SIZE - strlen(logline), "%5d ", getpid()); |
|---|
| 38 |
} |
|---|
| 39 |
vsnprintf(logline + strlen(logline), LOGLINE_SIZE - strlen(logline), format, ap); |
|---|
| 40 |
logline_size = strlen(logline); |
|---|
| 41 |
|
|---|
| 42 |
if ((bytes_written = write(logfile_fd, logline, logline_size)) != logline_size) |
|---|
| 43 |
perror("Error while writing logfile"); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
if ((STDOUT_FILENO != logfile_fd) && (daemonize != 1)) { |
|---|
| 47 |
if ((bytes_written = write(STDOUT_FILENO, logline, logline_size)) != logline_size) |
|---|
| 48 |
perror("Error while logging to stdout"); |
|---|
| 49 |
} |
|---|
| 50 |
va_end(ap); |
|---|
| 51 |
} |
|---|
| 52 |
return; |
|---|
| 53 |
} |
|---|