Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sockssrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <limits.h>
#include "server.h"
#include "sblist.h"
#include <time.h>
#include <stdarg.h>

/* timeout in microseconds on resource exhaustion to prevent excessive
cpu usage. */
Expand Down Expand Up @@ -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, ...) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your code ignores the quiet flag. also inline inserts the code at every callsite, bloating the binary. since logging is not performance sensitive, this should only be static. also localtime_r isn't available on all platforms afaik (even though it's in my POSIX 2008 manpages).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the findings. I'll close this PR to open a new one.

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
Expand Down Expand Up @@ -481,6 +496,7 @@ int main(int argc, char** argv) {
return 1;
}
server = &s;
dolog("Listening on %s:%d\n", listenip, port);

while(1) {
collect(threads);
Expand Down