From 8360dee022c6d5f8fbca22b92e39e2a033ac1f7d Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Mon, 17 Jun 2024 18:16:48 +0900 Subject: [PATCH] Flush all streams at exit This is a general version of commit d551f3. And I expect this will replace commit 5e8528 and 13c1e9, too. modified: builtin/credential-store.c modified: compat/os2.c modified: run-command.c --- builtin/credential-store.c | 5 ----- compat/os2.c | 15 +++++++++++++++ run-command.c | 16 ---------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/builtin/credential-store.c b/builtin/credential-store.c index b10b4972..4a492411 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -52,11 +52,6 @@ static void print_entry(struct credential *c) { printf("username=%s\n", c->username); printf("password=%s\n", c->password); - /* - * OS/2 kLIBC requires to flush a stream explicitly when it is a socket. - * Otherwise, buffered outputs are lost. - */ - fflush(stdout); } static void print_line(struct strbuf *buf) diff --git a/compat/os2.c b/compat/os2.c index 0ec27f8a..0fb82388 100644 --- a/compat/os2.c +++ b/compat/os2.c @@ -1729,6 +1729,15 @@ static char *toutf8dup(const char *in) return realloc(out, strlen(out) + 1); } +static void flush( void ) +{ + /* + * OS/2 kLIBC requires to flush a stream explicitly when it is a socket. + * Otherwise, buffered outputs are lost. + */ + fflush(NULL); +} + int git_os2_main_prepare (int * p_argc, char ** * p_argv) { _control87(MCW_EM, MCW_EM); /* mask all FPEs */ @@ -1808,6 +1817,12 @@ int git_os2_main_prepare (int * p_argc, char ** * p_argv) */ putenv("PERLIO=perlio"); + /* + * Flush all streams at exit. This prevents buffered outputs from being lost, + * especially in case of a stream fdopen()ed from a socket. + */ + atexit(flush); + #ifdef i_need_debug_output { extern const char *system_path(const char *path); diff --git a/run-command.c b/run-command.c index 8bafa38a..4d85ace9 100644 --- a/run-command.c +++ b/run-command.c @@ -983,22 +983,6 @@ int start_command(struct child_process *cmd) else if (cmd->in) close(cmd->in); -#ifdef __OS2__ - /* - * When socketpair() is used as a back-end for pipe(), reading from - * cmd->out does not wait for it to be filled even if it is in - * blocking-mode if fdout[1] is closed. So, wait here instead before - * closing fdout[1]. - */ - if (need_out && cmd->git_cmd) { - struct pollfd pollfd; - - pollfd.fd = cmd->out; - pollfd.events = POLLIN; - poll(&pollfd, 1, 1500); /* up to 1.5s at most */ - } -#endif - if (need_out) close(fdout[1]); else if (cmd->out)