]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - file_write.c
write: Simplify config parsers.
[paraslash.git] / file_write.c
index 2a53499abf532c05717afe5351b6ad72c3730b39..4a4dc66e52d61b2a5e632bbadd67f26a5f42ed27 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2006-2010 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -56,22 +56,29 @@ static int file_write_open(struct writer_node *wn)
                sizeof(struct private_file_write_data));
        struct file_write_args_info *conf = wn->conf;
        char *filename;
+       int ret;
 
        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);
+       ret = para_open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
        if (!conf->filename_given)
                free(filename);
-       if (pfwd->fd >= 0)
+       if (ret < 0)
+               goto out;
+       pfwd->fd = ret;
+       ret = mark_fd_blocking(pfwd->fd);
+       if (ret >= 0)
                return 1;
+       close(pfwd->fd);
+out:
        free(pfwd);
-       return -E_FW_OPEN;
+       return ret;
 }
 
-static void file_write_pre_select_btr(struct sched *s, struct task *t)
+static void file_write_pre_select(struct sched *s, struct task *t)
 {
        struct writer_node *wn = container_of(t, struct writer_node, task);
        struct private_file_write_data *pfwd = wn->private_data;
@@ -93,7 +100,7 @@ static void file_write_close(struct writer_node *wn)
        free(pfwd);
 }
 
-static void file_write_post_select_btr(__a_unused struct sched *s,
+static void file_write_post_select(__a_unused struct sched *s,
                struct task *t)
 {
        struct writer_node *wn = container_of(t, struct writer_node, task);
@@ -122,17 +129,13 @@ out:
        t->error = ret;
 }
 
-__malloc static void *file_write_parse_config(const char *options)
+__malloc static void *file_write_parse_config_or_die(const char *options)
 {
-       struct file_write_args_info *conf
-               = para_calloc(sizeof(struct file_write_args_info));
-       int ret = file_cmdline_parser_string(options, conf, "file_write");
-
-       PARA_INFO_LOG("conf->filename_given: %d\n", conf->filename_given);
-       if (!ret)
-               return conf;
-       free(conf);
-       return NULL;
+       struct file_write_args_info *conf = para_calloc(sizeof(*conf));
+
+       /* exits on errors */
+       file_cmdline_parser_string(options, conf, "file_write");
+       return conf;
 }
 
 static void file_write_free_config(void *conf)
@@ -147,9 +150,9 @@ void file_write_init(struct writer *w)
 
        file_cmdline_parser_init(&dummy);
        w->open = file_write_open;
-       w->pre_select_btr = file_write_pre_select_btr;
-       w->post_select_btr = file_write_post_select_btr;
-       w->parse_config = file_write_parse_config;
+       w->pre_select = file_write_pre_select;
+       w->post_select = file_write_post_select;
+       w->parse_config_or_die = file_write_parse_config_or_die;
        w->free_config = file_write_free_config;
        w->close = file_write_close;
        w->shutdown = NULL; /* nothing to do */