- struct private_file_write_data *pfwd = para_calloc(
- sizeof(struct private_file_write_data));
- struct file_write_args_info *conf = wn->conf;
- char *filename;
-
- if (conf->filename_given)
- filename = conf->filename_arg;
- else
- filename = random_filename();
- wn->private_data = pfwd;
- pfwd->fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
- if (!conf->filename_given)
- free(filename);
- if (pfwd->fd >= 0)
- return 1;
- free(pfwd);
- return -E_FW_OPEN;
-}
-
-static int file_write_pre_select(struct sched *s, struct writer_node *wn)
-{
- struct private_file_write_data *pfwd = wn->private_data;
- struct writer_node_group *wng = wn->wng;
-
- pfwd->check_fd = 0;
- if (pfwd->fd <= 0)
- return -E_FW_NO_FILE;
- if (!*wng->loaded)
- return 1;
- para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
- pfwd->check_fd = 1;
+ const unsigned flags = O_WRONLY | O_CREAT, mode = S_IRUSR | S_IWUSR;
+ int ret, fd;
+ struct private_file_write_data *pfwd;
+
+
+ if (WRITE_CMD_OPT_GIVEN(FILE, FILENAME, wn->lpr)) {
+ const char *path = WRITE_CMD_OPT_STRING_VAL(FILE, FILENAME,
+ wn->lpr);
+ ret = para_open(path, flags, mode);
+ } else {
+ char *path = random_filename();
+ ret = para_open(path, flags, mode);
+ free(path);
+ }
+ if (ret < 0)
+ return ret;
+ fd = ret;
+ ret = mark_fd_blocking(fd);
+ if (ret < 0) {
+ close(fd);
+ return ret;
+ }
+ pfwd = wn->private_data = para_calloc(sizeof(*pfwd));
+ pfwd->fd = fd;