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.
-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;
}
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;
+ struct private_file_write_data *pfwd = para_calloc(sizeof(*pfwd));
if (conf->filename_given)
filename = conf->filename_arg;
if (conf->filename_given)
filename = conf->filename_arg;
goto out;
pfwd->fd = ret;
ret = mark_fd_blocking(pfwd->fd);
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);
close(pfwd->fd);
out:
free(pfwd);
- if (ret < 0 || pfwd->fd < 0)
return sched_min_delay(s);
para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
}
return sched_min_delay(s);
para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
}
{
struct private_file_write_data *pfwd = wn->private_data;
{
struct private_file_write_data *pfwd = wn->private_data;
- if (pfwd->fd >= 0)
- close(pfwd->fd);
+ if (!pfwd)
+ return;
+ close(pfwd->fd);
ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret <= 0)
goto out;
ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret <= 0)
goto out;
ret = prepare_output_file(wn);
ret = prepare_output_file(wn);
- if (ret < 0)
- goto out;
}
if (!FD_ISSET(pfwd->fd, &s->wfds))
return;
}
if (!FD_ISSET(pfwd->fd, &s->wfds))
return;