Skip to content

Output is buffered, can't redirect stdout/stderr #1

@Alb0t

Description

@Alb0t

You cannot run netmon and redirect stdout/stderr. This is a desired feature for long running monitoring and if you want to run it as a background task and come back to it for example.
This is because netmon calls printf in C which is buffered by default here in common.h

#define __LOG__(format, loglevel, ...) printf("%s %-5s [%s] [%s:%d] " format "\n", getFormattedTime(), loglevel, __func__, __SHORT_FILE__, __LINE__, ## __VA_ARGS__)
....
#define LOGINFO(format, ...) __LOG__(format, "INFO", ## __VA_ARGS__)

Adding setvbuf(stdout, NULL, _IONBF, 0); to line 82 of netmon.c seems to do the trick, but I have no idea if this is correct/idiomatic to do so. I don't write C.. So I am submitting this as an ask/issue since I don't feel comfortable submitting PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions