diff options
author | Rob Austein <sra@hactrn.net> | 2011-10-06 19:21:00 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2011-10-06 19:21:00 +0000 |
commit | 50b51d35e66386db91884752ea94b6655ab6ecd0 (patch) | |
tree | e206b04ee7c34021cd3889db4730b45736518727 /rcynic/rcynic.c | |
parent | 7204fbcc07539c98d72a96014caddd877d5cf8e9 (diff) |
Move fcntl(F_SETFL, O_NONBLOCK) to after fork().
svn path=/rcynic/rcynic.c; revision=4017
Diffstat (limited to 'rcynic/rcynic.c')
-rw-r--r-- | rcynic/rcynic.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/rcynic/rcynic.c b/rcynic/rcynic.c index 962248ca..2cc37456 100644 --- a/rcynic/rcynic.c +++ b/rcynic/rcynic.c @@ -1945,19 +1945,6 @@ static void rsync_run(const rcynic_ctx_t *rc, logmsg(rc, log_sys_err, "pipe() failed: %s", strerror(errno)); goto lose; } - ctx->fd = pipe_fds[0]; - - if ((flags = fcntl(ctx->fd, F_GETFL, 0)) == -1) { - logmsg(rc, log_sys_err, "fcntl(F_GETFL) failed: %s", - strerror(errno)); - goto lose; - } - flags |= O_NONBLOCK; - if (fcntl(ctx->fd, F_SETFL, flags) == -1) { - logmsg(rc, log_sys_err, "fcntl(F_SETFL) failed: %s", - strerror(errno)); - goto lose; - } switch ((ctx->pid = vfork())) { @@ -1990,8 +1977,14 @@ static void rsync_run(const rcynic_ctx_t *rc, /* * Parent */ + ctx->fd = pipe_fds[0]; + if ((flags = fcntl(ctx->fd, F_GETFL, 0)) == -1 || + fcntl(ctx->fd, F_SETFL, flags | O_NONBLOCK) == -1) { + logmsg(rc, log_sys_err, "fcntl(ctx->fd, F_[GS]ETFL, O_NONBLOCK) failed: %s", + strerror(errno)); + goto lose; + } (void) close(pipe_fds[1]); - pipe_fds[1] = -1; ctx->state = rsync_state_running; ctx->problem = rsync_problem_none; if (!ctx->started) @@ -2015,8 +2008,10 @@ static void rsync_run(const rcynic_ctx_t *rc, (void) sk_rsync_ctx_t_delete_ptr(rc->rsync_queue, ctx); if (ctx && ctx->handler) ctx->handler(rc, ctx, rsync_status_failed, &ctx->uri, ctx->wsk); - if (ctx) - free(ctx); + if (ctx->pid > 0) { + (void) kill(ctx->pid, SIGKILL); + ctx->pid = 0; + } } /** |