2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file file_writer.c simple output plugin for testing purposes */
27 #include "file_write.cmdline.h"
30 /** data specific to the file writer */
31 struct private_file_writer_data {
32 /** the file descriptor of the output file */
34 /** non-zero if \a fd was added to the write fd set */
38 static int file_writer_open(struct writer_node *wn)
40 struct private_file_writer_data *pfwd = para_calloc(
41 sizeof(struct private_file_writer_data));
42 struct file_write_args_info *conf = wn->conf;
44 if (conf->filename_given)
45 filename = conf->filename_arg;
47 char *tmp = para_tmpname(), *home = para_homedir();
48 filename = make_message("%s/.paraslash/%s", home, tmp);
52 wn->private_data = pfwd;
53 pfwd->fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
54 if (!conf->filename_given)
62 static int file_writer_pre_select(struct sched *s, struct writer_node *wn)
64 struct private_file_writer_data *pfwd = wn->private_data;
65 struct writer_node_group *wng = wn->wng;
72 para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
77 static int file_writer_post_select(struct sched *s, struct writer_node *wn)
79 struct private_file_writer_data *pfwd = wn->private_data;
80 struct writer_node_group *wng = wn->wng;
85 if (*wng->loaded <= wn->written)
87 if (!FD_ISSET(pfwd->fd, &s->wfds))
89 // PARA_INFO_LOG("writing %zd\n", *wng->loaded);
90 ret = write(pfwd->fd, wng->buf + wn->written,
91 *wng->loaded - wn->written);
98 static void file_writer_close(struct writer_node *wn)
100 struct private_file_writer_data *pfwd = wn->private_data;
105 __malloc void *file_writer_parse_config(char *options)
107 PARA_INFO_LOG("options: %s\n", options);
108 struct file_write_args_info *conf
109 = para_calloc(sizeof(struct file_write_args_info));
110 int ret = file_cmdline_parser_string(options, conf, "file_write");
111 PARA_INFO_LOG("conf->filename_given: %d\n", conf->filename_given);
118 /** the init function of the file writer */
119 void file_writer_init(struct writer *w)
121 w->open = file_writer_open;
122 w->pre_select = file_writer_pre_select;
123 w->post_select = file_writer_post_select;
124 w->parse_config = file_writer_parse_config;
125 w->close = file_writer_close;
126 w->shutdown = NULL; /* nothing to do */