diff --git a/client/tarantool/tc.c b/client/tarantool/tc.c index 44bd9eac7673ea73534fabedb7cdf3afc9a03091..ec9afd90e3b230bac1eb1a9833d76318f31f3cc2 100644 --- a/client/tarantool/tc.c +++ b/client/tarantool/tc.c @@ -59,7 +59,7 @@ struct tc tc; static void tc_init(void) { memset(&tc, 0, sizeof(tc)); setlocale(LC_ALL, ""); - tc.pager_fd = fileno(stdout); + tc.pager_stream = stdout; tc.pager_pid = 0; } diff --git a/client/tarantool/tc.h b/client/tarantool/tc.h index f001346125bcb8e3e57cc9639a8a71c32af92807..cd6cdac81f87552953c2659b2641734141116a17 100644 --- a/client/tarantool/tc.h +++ b/client/tarantool/tc.h @@ -33,7 +33,7 @@ struct tc { struct tc_opt opt; struct tc_admin admin; struct tnt_stream *net; - int pager_fd; + FILE *pager_stream; pid_t pager_pid; }; diff --git a/client/tarantool/tc_pager.c b/client/tarantool/tc_pager.c index a97b50dc00ab65e3ef4654377115253b8764511d..94ee5a8d17a9e07c8b5f0f25b63f613c1dca1899 100644 --- a/client/tarantool/tc_pager.c +++ b/client/tarantool/tc_pager.c @@ -18,7 +18,7 @@ void tc_pager_start() { if (tc.pager_pid != 0) tc_pager_kill(); if (tc.opt.pager == NULL) { - tc.pager_fd = fileno(stdout); + tc.pager_stream = stdout; return; } int pipefd[2]; @@ -36,7 +36,7 @@ void tc_pager_start() { tc_error("Can't start pager! Errno: %s", strerror(errno)); } else { close(pipefd[0]); - tc.pager_fd = pipefd[1]; + tc.pager_stream = fdopen(pipefd[1], "a"); tc.pager_pid = pid; } return; @@ -44,8 +44,8 @@ void tc_pager_start() { void tc_pager_stop () { if (tc.pager_pid != 0) { - close(tc.pager_fd); - tc.pager_fd = fileno(stdout); + fclose(tc.pager_stream); + tc.pager_stream = stdout; waitpid(tc.pager_pid, NULL, 0); tc.pager_pid = 0; } diff --git a/client/tarantool/tc_print.c b/client/tarantool/tc_print.c index 381f17c3fa273c3e35a722ce85149a252a7fde08..5aac085775b7cbb16f66e8089d50c8eaecc524d3 100644 --- a/client/tarantool/tc_print.c +++ b/client/tarantool/tc_print.c @@ -57,18 +57,12 @@ void tc_print_buf(char *buf, size_t size) { } void tc_printf(char *fmt, ...) { - char *str; va_list args; va_start(args, fmt); - ssize_t str_len = vasprintf(&str, fmt, args); - if (str_len == -1) - tc_error("Error in vasprintf - %d", errno); - ssize_t stat = write(tc.pager_fd, str, str_len); - if (stat == -1) + int stat = vfprintf(tc.pager_stream, fmt, args); + if (stat < 0) tc_error("Can't write into pager - %d", errno); va_end(args); - if (str) - free(str); return; }