Skip to content

Commit

Permalink
lib-sieve: util: program-client: Made shutting down output towards pr…
Browse files Browse the repository at this point in the history
…ogram more efficient.

Shutdown is now called only once.
If there is no used input side to the FD, it is now closed entirely.
  • Loading branch information
stephanbosch committed Feb 22, 2016
1 parent 6308045 commit b83db1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/lib-sieve/util/program-client-local.c
Expand Up @@ -260,12 +260,23 @@ static int program_client_local_connect

static int program_client_local_close_output(struct program_client *pclient)
{
int fd_out = pclient->fd_out, fd_in = pclient->fd_in;

pclient->fd_out = -1;

/* Shutdown output; program stdin will get EOF */
if ( pclient->fd_out >= 0 && shutdown(pclient->fd_out, SHUT_WR) < 0 &&
errno != ENOTCONN ) {
i_error("shutdown(%s, SHUT_WR) failed: %m", pclient->path);
return -1;
if ( fd_out >= 0 ) {
if ( fd_in >= 0 ) {
if ( shutdown(fd_out, SHUT_WR) < 0 && errno != ENOTCONN ) {
i_error("shutdown(%s, SHUT_WR) failed: %m", pclient->path);
return -1;
}
} else if ( close(fd_out) < 0 ) {
i_error("close(%s) failed: %m", pclient->path);
return -1;
}
}

return 1;
}

Expand Down
18 changes: 14 additions & 4 deletions src/lib-sieve/util/program-client-remote.c
Expand Up @@ -244,11 +244,21 @@ static int program_client_remote_connect(struct program_client *pclient)

static int program_client_remote_close_output(struct program_client *pclient)
{
int fd_out = pclient->fd_out, fd_in = pclient->fd_in;

pclient->fd_out = -1;

/* Shutdown output; program stdin will get EOF */
if ( pclient->fd_out >= 0 && shutdown(pclient->fd_out, SHUT_WR) < 0 &&
errno != ENOTCONN ) {
i_error("shutdown(%s, SHUT_WR) failed: %m", pclient->path);
return -1;
if ( fd_out >= 0 ) {
if ( fd_in >= 0 ) {
if ( shutdown(fd_out, SHUT_WR) < 0 && errno != ENOTCONN ) {
i_error("shutdown(%s, SHUT_WR) failed: %m", pclient->path);
return -1;
}
} else if ( close(fd_out) < 0 ) {
i_error("close(%s) failed: %m", pclient->path);
return -1;
}
}

return 1;
Expand Down

0 comments on commit b83db1d

Please sign in to comment.