Skip to content

Commit

Permalink
Flush all streams at exit
Browse files Browse the repository at this point in the history
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
  • Loading branch information
komh committed Jun 17, 2024
1 parent d551f33 commit 8360dee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
5 changes: 0 additions & 5 deletions builtin/credential-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions compat/os2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 0 additions & 16 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8360dee

Please sign in to comment.