]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: Add error_r parameter to the internal fs.init() method
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 25 Nov 2019 09:43:50 +0000 (11:43 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Dec 2019 10:12:30 +0000 (10:12 +0000)
This will help removing fs_set_error() calls.

src/lib-fs/fs-api-private.h
src/lib-fs/fs-api.c
src/lib-fs/fs-dict.c
src/lib-fs/fs-metawrap.c
src/lib-fs/fs-posix.c
src/lib-fs/fs-randomfail.c
src/lib-fs/fs-sis-queue.c
src/lib-fs/fs-sis.c
src/lib-fs/fs-test.c
src/plugins/fs-compress/fs-compress.c
src/plugins/mail-crypt/fs-crypt-common.c

index ac702ba8e48ab558da2d231809cd1915be499aff..6f599a3fa629aa65feb399b83eea5ac5b3c6ac27 100644 (file)
@@ -20,7 +20,7 @@ extern struct fs_api_module_register fs_api_module_register;
 struct fs_vfuncs {
        struct fs *(*alloc)(void);
        int (*init)(struct fs *fs, const char *args,
-                   const struct fs_settings *set);
+                   const struct fs_settings *set, const char **error_r);
        void (*deinit)(struct fs *fs);
 
        enum fs_properties (*get_properties)(struct fs *fs);
index 4889f70d1ba4580083cfcc9da0acba6b7abc4c14..7e5ddc7b5e8d0af6b2ba8ffff69239815ca0180c 100644 (file)
@@ -26,6 +26,8 @@ fs_alloc(const struct fs *fs_class, const char *args,
         const struct fs_settings *set, struct fs **fs_r, const char **error_r)
 {
        struct fs *fs;
+       const char *temp_error;
+       char *error = NULL;
        int ret;
 
        fs = fs_class->v.alloc();
@@ -35,14 +37,15 @@ fs_alloc(const struct fs *fs_class, const char *args,
        i_array_init(&fs->module_contexts, 5);
 
        T_BEGIN {
-               ret = fs_class->v.init(fs, args, set);
+               if ((ret = fs_class->v.init(fs, args, set, &temp_error)) < 0)
+                       error = i_strdup(temp_error);
        } T_END;
        if (ret < 0) {
                /* a bit kludgy way to allow data stack frame usage in normal
                   conditions but still be able to return error message from
                   data stack. */
-               *error_r = t_strdup_printf("%s: %s", fs_class->name,
-                                          fs_last_error(fs));
+               *error_r = t_strdup_printf("%s: %s", fs_class->name, error);
+               i_free(error);
                fs_unref(&fs);
                return -1;
        }
index 8578199c6528a9bee6582664a2d942143f4e4f6d..9e7d380a7027e64f20797ad779835669d57ae80a 100644 (file)
@@ -46,7 +46,8 @@ static struct fs *fs_dict_alloc(void)
 }
 
 static int
-fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set)
+fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set,
+            const char **error_r)
 {
        struct dict_fs *fs = (struct dict_fs *)_fs;
        struct dict_settings dict_set;
@@ -54,7 +55,7 @@ fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set)
 
        p = strchr(args, ':');
        if (p == NULL) {
-               fs_set_error(_fs, "':' missing in args");
+               *error_r = "':' missing in args";
                return -1;
        }
        encoding_str = t_strdup_until(args, p++);
@@ -65,7 +66,8 @@ fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set)
        else if (strcmp(encoding_str, "base64") == 0)
                fs->encoding = FS_DICT_VALUE_ENCODING_BASE64;
        else {
-               fs_set_error(_fs, "Unknown value encoding '%s'", encoding_str);
+               *error_r = t_strdup_printf("Unknown value encoding '%s'",
+                                          encoding_str);
                return -1;
        }
 
@@ -74,7 +76,8 @@ fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set)
        dict_set.base_dir = set->base_dir;
 
        if (dict_init(p, &dict_set, &fs->dict, &error) < 0) {
-               fs_set_error(_fs, "dict_init(%s) failed: %s", args, error);
+               *error_r = t_strdup_printf("dict_init(%s) failed: %s",
+                                          args, error);
                return -1;
        }
        return 0;
index 22f6dd83f3eeed6d622a656c87debbb4e1bbb0b5..ea73a096af3c4392aa22f69921fc1fd27e8c0a30 100644 (file)
@@ -43,14 +43,14 @@ static struct fs *fs_metawrap_alloc(void)
 }
 
 static int
-fs_metawrap_init(struct fs *_fs, const char *args, const
-                struct fs_settings *set)
+fs_metawrap_init(struct fs *_fs, const char *args,
+                const struct fs_settings *set, const char **error_r)
 {
        struct metawrap_fs *fs = (struct metawrap_fs *)_fs;
-       const char *parent_name, *parent_args, *error;
+       const char *parent_name, *parent_args;
 
        if (*args == '\0') {
-               fs_set_error(_fs, "Parent filesystem not given as parameter");
+               *error_r = "Parent filesystem not given as parameter";
                return -1;
        }
 
@@ -62,10 +62,8 @@ fs_metawrap_init(struct fs *_fs, const char *args, const
                parent_name = t_strdup_until(args, parent_args);
                parent_args++;
        }
-       if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s", error);
+       if (fs_init(parent_name, parent_args, set, &_fs->parent, error_r) < 0)
                return -1;
-       }
        if ((fs_get_properties(_fs->parent) & FS_PROPERTY_METADATA) == 0)
                fs->wrap_metadata = TRUE;
        return 0;
index 576e2d6cd3e18dc16ef29442f29b040f273801df..fb5967168f74681dc2dead8914516cfbfbaecdd2 100644 (file)
@@ -75,7 +75,8 @@ static struct fs *fs_posix_alloc(void)
 }
 
 static int
-fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
+fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set,
+             const char **error_r)
 {
        struct posix_fs *fs = container_of(_fs, struct posix_fs, fs);
        const char *const *tmp;
@@ -112,16 +113,16 @@ fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
                } else if (str_begins(arg, "mode=")) {
                        unsigned int mode;
                        if (str_to_uint_oct(arg+5, &mode) < 0) {
-                               fs_set_error(_fs, "Invalid mode value: %s", arg+5);
+                               *error_r = t_strdup_printf("Invalid mode value: %s", arg+5);
                                return -1;
                        }
                        fs->mode = mode & 0666;
                        if (fs->mode == 0) {
-                               fs_set_error(_fs, "Invalid mode: %s", arg+5);
+                               *error_r = t_strdup_printf("Invalid mode: %s", arg+5);
                                return -1;
                        }
                } else {
-                       fs_set_error(_fs, "Unknown arg '%s'", arg);
+                       *error_r = t_strdup_printf("Unknown arg '%s'", arg);
                        return -1;
                }
        }
index 879bff49d70e3e1767856725e291e06a5064af76..9ed97ed70e1b5a3ab601b21b3798cbe7ed039062 100644 (file)
@@ -159,24 +159,25 @@ static int fs_randomfail_parse_params(struct randomfail_fs *fs,
 
 static int
 fs_randomfail_init(struct fs *_fs, const char *args,
-                  const struct fs_settings *set)
+                  const struct fs_settings *set, const char **error_r)
 {
        struct randomfail_fs *fs = (struct randomfail_fs *)_fs;
        const char *p, *parent_name, *parent_args, *error;
 
        p = strchr(args, ':');
        if (p == NULL) {
-               fs_set_error(_fs, "Randomfail parameters missing");
+               *error_r = "Randomfail parameters missing";
                return -1;
        }
        if (fs_randomfail_parse_params(fs, t_strdup_until(args, p++), &error) < 0) {
-               fs_set_error(_fs, "Invalid randomfail parameters: %s", error);
+               *error_r = t_strdup_printf(
+                       "Invalid randomfail parameters: %s", error);
                return -1;
        }
        args = p;
 
        if (*args == '\0') {
-               fs_set_error(_fs, "Parent filesystem not given as parameter");
+               *error_r = "Parent filesystem not given as parameter";
                return -1;
        }
 
@@ -188,10 +189,8 @@ fs_randomfail_init(struct fs *_fs, const char *args,
                parent_name = t_strdup_until(args, parent_args);
                parent_args++;
        }
-       if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s", error);
+       if (fs_init(parent_name, parent_args, set, &_fs->parent, error_r) < 0)
                return -1;
-       }
        return 0;
 }
 
index e23e9261cfff5c7116ede2464a1de27d4820510e..86d92211c0016913e6df36e643e4c41ad0b17b4d 100644 (file)
@@ -29,16 +29,16 @@ static struct fs *fs_sis_queue_alloc(void)
 
 static int
 fs_sis_queue_init(struct fs *_fs, const char *args,
-                 const struct fs_settings *set)
+                 const struct fs_settings *set, const char **error_r)
 {
        struct sis_queue_fs *fs = (struct sis_queue_fs *)_fs;
-       const char *p, *parent_name, *parent_args, *error;
+       const char *p, *parent_name, *parent_args;
 
        /* <queue_dir>:<parent fs>[:<args>] */
 
        p = strchr(args, ':');
        if (p == NULL || p[1] == '\0') {
-               fs_set_error(_fs, "Parent filesystem not given as parameter");
+               *error_r = "Parent filesystem not given as parameter";
                return -1;
        }
 
@@ -50,10 +50,8 @@ fs_sis_queue_init(struct fs *_fs, const char *args,
                parent_args = "";
        else
                parent_name = t_strdup_until(parent_name, parent_args++);
-       if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s", error);
+       if (fs_init(parent_name, parent_args, set, &_fs->parent, error_r) < 0)
                return -1;
-       }
        return 0;
 }
 
index bc8a0b00960b848a399e1f3bbf5c7cf035cf20b2..749d65a6bf677b79053526a01459a5c1a1dfd1e2 100644 (file)
@@ -37,13 +37,14 @@ static struct fs *fs_sis_alloc(void)
 }
 
 static int
-fs_sis_init(struct fs *_fs, const char *args, const struct fs_settings *set)
+fs_sis_init(struct fs *_fs, const char *args, const struct fs_settings *set,
+           const char **error_r)
 {
        enum fs_properties props;
-       const char *parent_name, *parent_args, *error;
+       const char *parent_name, *parent_args;
 
        if (*args == '\0') {
-               fs_set_error(_fs, "Parent filesystem not given as parameter");
+               *error_r = "Parent filesystem not given as parameter";
                return -1;
        }
 
@@ -55,14 +56,12 @@ fs_sis_init(struct fs *_fs, const char *args, const struct fs_settings *set)
                parent_name = t_strdup_until(args, parent_args);
                parent_args++;
        }
-       if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s", error);
+       if (fs_init(parent_name, parent_args, set, &_fs->parent, error_r) < 0)
                return -1;
-       }
        props = fs_get_properties(_fs->parent);
        if ((props & FS_SIS_REQUIRED_PROPS) != FS_SIS_REQUIRED_PROPS) {
-               fs_set_error(_fs, "%s backend can't be used with SIS",
-                            parent_name);
+               *error_r = t_strdup_printf("%s backend can't be used with SIS",
+                                          parent_name);
                return -1;
        }
        return 0;
index fb7f7274c3300a238656348c23ce77841ce1d19c..4237fb1f8342f7be2b04d346cac1bc38c525c043 100644 (file)
@@ -18,7 +18,8 @@ static struct fs *fs_test_alloc(void)
 
 static int
 fs_test_init(struct fs *_fs ATTR_UNUSED, const char *args ATTR_UNUSED,
-            const struct fs_settings *set ATTR_UNUSED)
+            const struct fs_settings *set ATTR_UNUSED,
+            const char **error_r ATTR_UNUSED)
 {
        return 0;
 }
index ab2bbf159b984891d760fceeef11333926e8e49b..b6808f3c5e18f548f0bcfe2990f6100e6fa2187f 100644 (file)
@@ -40,8 +40,8 @@ static struct fs *fs_compress_alloc(void)
 }
 
 static int
-fs_compress_init(struct fs *_fs, const char *args, const
-                struct fs_settings *set)
+fs_compress_init(struct fs *_fs, const char *args,
+                const struct fs_settings *set, const char **error_r)
 {
        struct compress_fs *fs = (struct compress_fs *)_fs;
        const char *p, *compression_name, *level_str, *error;
@@ -55,7 +55,7 @@ fs_compress_init(struct fs *_fs, const char *args, const
 
        p = strchr(args, ':');
        if (p == NULL) {
-               fs_set_error(_fs, "Compression method not given as parameter");
+               *error_r = "Compression method not given as parameter";
                return -1;
        }
        compression_name = t_strdup_until(args, p++);
@@ -64,21 +64,23 @@ fs_compress_init(struct fs *_fs, const char *args, const
        /* get compression level */
        p = strchr(args, ':');
        if (p == NULL || p[1] == '\0') {
-               fs_set_error(_fs, "Parent filesystem not given as parameter");
+               *error_r = "Parent filesystem not given as parameter";
                return -1;
        }
 
        level_str = t_strdup_until(args, p++);
        if (str_to_uint(level_str, &fs->compress_level) < 0 ||
            fs->compress_level > 9) {
-               fs_set_error(_fs, "Invalid compression level parameter '%s'", level_str);
+               *error_r = t_strdup_printf(
+                       "Invalid compression level parameter '%s'", level_str);
                return -1;
        }
        args = p;
 
        fs->handler = compression_lookup_handler(compression_name);
        if (fs->handler == NULL) {
-               fs_set_error(_fs, "Compression method '%s' not support", compression_name);
+               *error_r = t_strdup_printf(
+                       "Compression method '%s' not supported", compression_name);
                return -1;
        }
 
@@ -91,7 +93,7 @@ fs_compress_init(struct fs *_fs, const char *args, const
                parent_args++;
        }
        if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s: %s", parent_name, error);
+               *error_r = t_strdup_printf("%s: %s", parent_name, error);
                return -1;
        }
        return 0;
index d0c1b1086e913089b2140816c7b4ae882e3e51f3..3fdf95908a4f16051d66eddfeece5f1481542ce9 100644 (file)
@@ -54,8 +54,8 @@ static struct fs *fs_crypt_alloc(void)
 }
 
 static int
-fs_crypt_init(struct fs *_fs, const char *args, const
-             struct fs_settings *set)
+fs_crypt_init(struct fs *_fs, const char *args, const struct fs_settings *set,
+             const char **error_r)
 {
        struct crypt_fs *fs = (struct crypt_fs *)_fs;
        const char *enc_algo, *set_prefix;
@@ -72,7 +72,7 @@ fs_crypt_init(struct fs *_fs, const char *args, const
        for (;;) {
                p = strchr(args, ':');
                if (p == NULL) {
-                       fs_set_error(_fs, "Missing parameters");
+                       *error_r = "Missing parameters";
                        return -1;
                }
                arg = t_strdup_until(args, p);
@@ -92,7 +92,8 @@ fs_crypt_init(struct fs *_fs, const char *args, const
                else if (strcmp(arg, "password") == 0)
                        password = value;
                else {
-                       fs_set_error(_fs, "Invalid parameter '%s'", arg);
+                       *error_r = t_strdup_printf(
+                               "Invalid parameter '%s'", arg);
                        return -1;
                }
        }
@@ -106,7 +107,7 @@ fs_crypt_init(struct fs *_fs, const char *args, const
                parent_args++;
        }
        if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
-               fs_set_error(_fs, "%s: %s", parent_name, error);
+               *error_r = t_strdup_printf("%s: %s", parent_name, error);
                return -1;
        }
        fs->enc_algo = i_strdup(enc_algo);