From: Andre Noll Date: Fri, 5 Nov 2010 18:28:24 +0000 (+0100) Subject: file_writer: Make file_write_open() a no-op. X-Git-Tag: v0.4.5~4^2~3 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=00837775857a5c40c8c8da8ac509c3e751312ea3 file_writer: Make file_write_open() a no-op. Move the allocation of the private_file_write_data struct to ->post_select() and adjust the the check whether the output file has already been opened accordingly. If the output file has just been opened, pfwd->fd will never be set in the write fd set of the scheduler, so we can skip this test. --- diff --git a/file_write.c b/file_write.c index e6a3229e..149b48ef 100644 --- a/file_write.c +++ b/file_write.c @@ -50,20 +50,16 @@ __must_check __malloc static char *random_filename(void) return result; } -static void file_write_open(struct writer_node *wn) +static void file_write_open(__a_unused struct writer_node *wn) { - struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd)); - - wn->private_data = pfwd; - pfwd->fd = -1; } static int prepare_output_file(struct writer_node *wn) { struct file_write_args_info *conf = wn->conf; - struct private_file_write_data *pfwd = wn->private_data; char *filename; int ret; + struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd)); if (conf->filename_given) filename = conf->filename_arg; @@ -76,8 +72,11 @@ static int prepare_output_file(struct writer_node *wn) goto out; pfwd->fd = ret; ret = mark_fd_blocking(pfwd->fd); - if (ret >= 0) - return 1; + if (ret < 0) + goto out_close; + wn->private_data = pfwd; + return 1; +out_close: close(pfwd->fd); out: free(pfwd); @@ -92,7 +91,7 @@ static void file_write_pre_select(struct sched *s, struct task *t) if (ret == 0) return; - if (ret < 0 || pfwd->fd < 0) + if (ret < 0 || !pfwd) return sched_min_delay(s); para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno); } @@ -101,8 +100,9 @@ static void file_write_close(struct writer_node *wn) { struct private_file_write_data *pfwd = wn->private_data; - if (pfwd->fd >= 0) - close(pfwd->fd); + if (!pfwd) + return; + close(pfwd->fd); free(pfwd); } @@ -120,10 +120,9 @@ static void file_write_post_select(__a_unused struct sched *s, ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF); if (ret <= 0) goto out; - if (pfwd->fd < 0) { + if (!pfwd) { ret = prepare_output_file(wn); - if (ret < 0) - goto out; + goto out; } if (!FD_ISSET(pfwd->fd, &s->wfds)) return;