mirror of
https://github.com/bol-van/zapret.git
synced 2025-03-15 04:41:37 +03:00
nfqws,tpws: always use line buffering for console IO
Forces stdout and stderr to always use line buffering. Note that glibc does automatically flush on newline iff connected to a terminal, but that is not the case when running under systemd. See also https://www.gnu.org/software/libc/manual/html_node/Buffering-Concepts.html https://www.gnu.org/software/libc/manual/html_node/Controlling-Buffering.html
This commit is contained in:
parent
756603338b
commit
a1d29b0c3a
@ -391,6 +391,12 @@ void fill_random_az09(uint8_t *p,size_t sz)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disable_console_io_buffering(void)
|
||||||
|
{
|
||||||
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
setvbuf(stderr, NULL, _IOLBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool set_env_exedir(const char *argv0)
|
bool set_env_exedir(const char *argv0)
|
||||||
{
|
{
|
||||||
char *s,*d;
|
char *s,*d;
|
||||||
|
@ -92,6 +92,7 @@ void fill_random_bytes(uint8_t *p,size_t sz);
|
|||||||
void fill_random_az(uint8_t *p,size_t sz);
|
void fill_random_az(uint8_t *p,size_t sz);
|
||||||
void fill_random_az09(uint8_t *p,size_t sz);
|
void fill_random_az09(uint8_t *p,size_t sz);
|
||||||
|
|
||||||
|
void disable_console_io_buffering(void);
|
||||||
bool set_env_exedir(const char *argv0);
|
bool set_env_exedir(const char *argv0);
|
||||||
|
|
||||||
|
|
||||||
|
11
nfq/nfqws.c
11
nfq/nfqws.c
@ -499,7 +499,6 @@ static int win_main(const char *windivert_filter)
|
|||||||
if (!logical_net_filter_match())
|
if (!logical_net_filter_match())
|
||||||
{
|
{
|
||||||
DLOG_CONDUP("logical network is not present. waiting it to appear.\n");
|
DLOG_CONDUP("logical network is not present. waiting it to appear.\n");
|
||||||
fflush(stdout);
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (bQuit)
|
if (bQuit)
|
||||||
@ -512,7 +511,6 @@ static int win_main(const char *windivert_filter)
|
|||||||
}
|
}
|
||||||
while (!logical_net_filter_match());
|
while (!logical_net_filter_match());
|
||||||
DLOG_CONDUP("logical network now present\n");
|
DLOG_CONDUP("logical network now present\n");
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!windivert_init(windivert_filter))
|
if (!windivert_init(windivert_filter))
|
||||||
@ -523,10 +521,6 @@ static int win_main(const char *windivert_filter)
|
|||||||
|
|
||||||
DLOG_CONDUP("windivert initialized. capture is started.\n");
|
DLOG_CONDUP("windivert initialized. capture is started.\n");
|
||||||
|
|
||||||
// cygwin auto flush fails when piping
|
|
||||||
fflush(stdout);
|
|
||||||
fflush(stderr);
|
|
||||||
|
|
||||||
for (id=0;;id++)
|
for (id=0;;id++)
|
||||||
{
|
{
|
||||||
len = sizeof(packet);
|
len = sizeof(packet);
|
||||||
@ -589,10 +583,6 @@ static int win_main(const char *windivert_filter)
|
|||||||
default:
|
default:
|
||||||
DLOG("packet: id=%u drop\n", id);
|
DLOG("packet: id=%u drop\n", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cygwin auto flush fails when piping
|
|
||||||
fflush(stdout);
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
win_dark_deinit();
|
win_dark_deinit();
|
||||||
@ -1424,6 +1414,7 @@ void check_dp(const struct desync_profile *dp)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
disable_console_io_buffering();
|
||||||
set_env_exedir(argv[0]);
|
set_env_exedir(argv[0]);
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
|
@ -383,6 +383,11 @@ bool pf_is_empty(const port_filter *pf)
|
|||||||
return !pf->neg && !pf->from && !pf->to;
|
return !pf->neg && !pf->from && !pf->to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disable_console_io_buffering(void)
|
||||||
|
{
|
||||||
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
setvbuf(stderr, NULL, _IOLBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool set_env_exedir(const char *argv0)
|
bool set_env_exedir(const char *argv0)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +82,7 @@ bool pf_in_range(uint16_t port, const port_filter *pf);
|
|||||||
bool pf_parse(const char *s, port_filter *pf);
|
bool pf_parse(const char *s, port_filter *pf);
|
||||||
bool pf_is_empty(const port_filter *pf);
|
bool pf_is_empty(const port_filter *pf);
|
||||||
|
|
||||||
|
void disable_console_io_buffering(void);
|
||||||
bool set_env_exedir(const char *argv0);
|
bool set_env_exedir(const char *argv0);
|
||||||
|
|
||||||
#ifndef IN_LOOPBACK
|
#ifndef IN_LOOPBACK
|
||||||
|
@ -1707,6 +1707,7 @@ int main(int argc, char *argv[])
|
|||||||
struct salisten_s list[MAX_BINDS];
|
struct salisten_s list[MAX_BINDS];
|
||||||
char ip_port[48];
|
char ip_port[48];
|
||||||
|
|
||||||
|
disable_console_io_buffering();
|
||||||
set_env_exedir(argv[0]);
|
set_env_exedir(argv[0]);
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
mask_from_preflen6_prepare();
|
mask_from_preflen6_prepare();
|
||||||
|
@ -1755,8 +1755,6 @@ int event_loop(const int *listen_fd, size_t listen_fd_ct)
|
|||||||
// at least one leg was removed. recount legs
|
// at least one leg was removed. recount legs
|
||||||
print_legs();
|
print_legs();
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stderr); fflush(stdout); // for console messages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ex:
|
ex:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user