dovecot-2.2: dsync: Wait for child process to close only after c...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 16 07:16:58 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/44eda990f757
changeset: 15765:44eda990f757
user: Timo Sirainen <tss at iki.fi>
date: Sat Feb 16 07:12:18 2013 +0200
description:
dsync: Wait for child process to close only after closing the stdin/out/err to it.
Otherwise the ssh process doesn't shutdown.
diffstat:
src/doveadm/dsync/doveadm-dsync.c | 31 +++++++++++++++++++------------
1 files changed, 19 insertions(+), 12 deletions(-)
diffs (69 lines):
diff -r fb367a977077 -r 44eda990f757 src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c Wed Feb 13 12:43:34 2013 +0200
+++ b/src/doveadm/dsync/doveadm-dsync.c Sat Feb 16 07:12:18 2013 +0200
@@ -333,24 +333,23 @@
return 0;
}
-static void
-cmd_dsync_run_remote(struct dsync_cmd_context *ctx, struct mail_user *user)
+static void cmd_dsync_wait_remote(struct dsync_cmd_context *ctx)
{
int status;
- i_set_failure_prefix("dsync-local(%s): ", user->username);
- io_loop_run(current_ioloop);
-
/* wait for the remote command to finish to see any final errors.
don't wait very long though. */
alarm(DSYNC_REMOTE_CMD_EXIT_WAIT_SECS);
- if (wait(&status) == -1) {
- if (errno != EINTR)
- i_error("wait() failed: %m");
- else {
+ if (waitpid(ctx->remote_pid, &status, 0) == -1) {
+ if (errno != EINTR) {
+ i_error("waitpid(%ld) failed: %m",
+ (long)ctx->remote_pid);
+ } else {
i_error("Remote command process isn't dying, killing it");
- if (kill(ctx->remote_pid, SIGKILL) < 0 && errno != ESRCH)
- i_error("kill() failed: %m");
+ if (kill(ctx->remote_pid, SIGKILL) < 0 && errno != ESRCH) {
+ i_error("kill(%ld, SIGKILL) failed: %m",
+ (long)ctx->remote_pid);
+ }
}
} else if (WIFSIGNALED(status))
i_error("Remote command died with signal %d", WTERMSIG(status));
@@ -358,6 +357,12 @@
i_error("Remote command returned error %d", WEXITSTATUS(status));
}
+static void cmd_dsync_run_remote(struct mail_user *user)
+{
+ i_set_failure_prefix("dsync-local(%s): ", user->username);
+ io_loop_run(current_ioloop);
+}
+
static const char *const *
parse_ssh_location(struct dsync_cmd_context *ctx,
const char *location, const char *username)
@@ -439,7 +444,7 @@
if (cmd_dsync_run_local(ctx, user, brain, ibc2) < 0)
ret = -1;
} else {
- cmd_dsync_run_remote(ctx, user);
+ cmd_dsync_run_remote(user);
}
if (ctx->state_input != NULL) {
@@ -466,6 +471,8 @@
}
if (ctx->fd_err != -1)
i_close_fd(&ctx->fd_err);
+ if (ctx->remote)
+ cmd_dsync_wait_remote(ctx);
return ret;
}
More information about the dovecot-cvs
mailing list