diff --git a/sockssrv.c b/sockssrv.c index d59fc27..3193606 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -35,6 +35,8 @@ #include #include "server.h" #include "sblist.h" +#include +#include /* timeout in microseconds on resource exhaustion to prevent excessive cpu usage. */ @@ -111,7 +113,20 @@ struct thread { /* we log to stderr because it's not using line buffering, i.e. malloc which would need locking when called from different threads. for the same reason we use dprintf, which writes directly to an fd. */ -#define dolog(...) do { if(!quiet) dprintf(2, __VA_ARGS__); } while(0) +static inline void dolog(const char *fmt, ...) { + char t[32] = {}; + struct tm tm_buf; + time_t secs = time(NULL); + + va_list args; + va_start(args, fmt); + + strftime(t, sizeof(t), "[%Y-%m-%d %T] ", localtime_r(&secs, &tm_buf)); + dprintf(fileno(stderr), "%s", t); + vdprintf(fileno(stderr), fmt, args); + + va_end(args); +} #else static void dolog(const char* fmt, ...) { } #endif @@ -479,6 +494,7 @@ int main(int argc, char** argv) { return 1; } server = &s; + dolog("Listening on %s:%d\n", listenip, port); while(1) { collect(threads);