Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Alb0t opened this issue Sep 1, 2021 · 0 comments
Open

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

Alb0t opened this issue Sep 1, 2021 · 0 comments

Comments

@Alb0t
Copy link

Alb0t commented Sep 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant