]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add error_r to t_readlink and its callers
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Sun, 4 Dec 2016 10:47:22 +0000 (12:47 +0200)
committerGitLab <gitlab@git.dovecot.net>
Mon, 30 Jan 2017 16:48:15 +0000 (18:48 +0200)
src/config/doveconf.c
src/lib-master/master-instance.c
src/lib-master/master-service.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/mailbox-list.c
src/lib/path-util.c
src/lib/path-util.h

index 0cc72e423927281bd5f50e28ab6be98f676714f7..439faccb0357bb3cd6e4f52c6abd729dacd9b3c4 100644 (file)
@@ -684,12 +684,14 @@ static void hostname_verify_format(const char *arg)
 
 static void check_wrong_config(const char *config_path)
 {
-       const char *base_dir, *symlink_path, *prev_path;
+       const char *base_dir, *symlink_path, *prev_path, *error;
 
        base_dir = get_setting("master", "base_dir");
        symlink_path = t_strconcat(base_dir, "/"PACKAGE".conf", NULL);
-       if (t_readlink(symlink_path, &prev_path) < 0)
+       if (t_readlink(symlink_path, &prev_path, &error) < 0) {
+               i_error("t_readlink(%s) failed: %s", symlink_path, error);
                return;
+       }
 
        if (strcmp(prev_path, config_path) != 0) {
                i_warning("Dovecot was last started using %s, "
index 5baf04f543408d818ae84258e1e974ac90bda708..92073d45f61257253df055173dba763e1bc3485b 100644 (file)
@@ -58,15 +58,17 @@ static void
 master_instance_update_config_path(struct master_instance_list *list,
                                   struct master_instance *inst)
 {
-       const char *path, *config_path;
+       const char *path, *config_path, *error;
 
        /* update instance's config path if it has changed */
        path = t_strconcat(inst->base_dir, "/"PACKAGE".conf", NULL);
-       if (t_readlink(path, &config_path) == 0) {
-               if (null_strcmp(inst->config_path, config_path) != 0) {
-                       inst->config_path = p_strdup(list->pool, config_path);
-                       list->config_paths_changed = TRUE;
-               }
+       if (t_readlink(path, &config_path, &error) < 0) {
+               i_error("t_readlink(%s) failed: %s", path, error);
+               return;
+       }
+       if (null_strcmp(inst->config_path, config_path) != 0) {
+               inst->config_path = p_strdup(list->pool, config_path);
+               list->config_paths_changed = TRUE;
        }
 }
 
index 6e53db7d019543027dd21fe8d2097d6ba399e394..78eb2da2a5d8f6e0b0e319729b5ad79ae00f37c7 100644 (file)
@@ -424,8 +424,9 @@ static bool get_instance_config(const char *name, const char **config_path_r)
        inst = master_instance_list_find_by_name(list, name);
        if (inst != NULL) {
                path = t_strdup_printf("%s/dovecot.conf", inst->base_dir);
-               if (t_readlink(path, config_path_r) < 0)
-                       i_fatal("readlink(%s) failed: %m", path);
+               const char *error;
+               if (t_readlink(path, config_path_r, &error) < 0)
+                       i_fatal("t_readlink(%s) failed: %s", path, error);
        }
        master_instance_list_deinit(&list);
        return inst != NULL;
index 3a8ad5265ab544f839e2b0440e143f42b2c07cb2..0045cebbafaf63c439ea171b7fa751a2f2cdd766 100644 (file)
@@ -32,12 +32,12 @@ static bool
 dbox_alt_path_has_changed(const char *root_dir, const char *alt_path,
                          const char *alt_path2, const char *alt_symlink_path)
 {
-       const char *linkpath;
+       const char *linkpath, *error;
 
-       if (t_readlink(alt_symlink_path, &linkpath) < 0) {
+       if (t_readlink(alt_symlink_path, &linkpath, &error) < 0) {
                if (errno == ENOENT)
                        return alt_path != NULL;
-               i_error("readlink(%s) failed: %m", alt_symlink_path);
+               i_error("t_readlink(%s) failed: %s", alt_symlink_path, error);
                return FALSE;
        }
 
index 9761e6bcac427307def4ae94d7dbb0f45b5b602d..f4011b6dc74072b0f72423e275e9798b546d6a59 100644 (file)
@@ -1691,7 +1691,7 @@ int mailbox_list_dirent_is_alias_symlink(struct mailbox_list *list,
                return 1;
 
        T_BEGIN {
-               const char *path, *linkpath;
+               const char *path, *linkpath, *error;
 
                path = t_strconcat(dir_path, "/", d->d_name, NULL);
                if (lstat(path, &st) < 0) {
@@ -1700,8 +1700,8 @@ int mailbox_list_dirent_is_alias_symlink(struct mailbox_list *list,
                        ret = -1;
                } else if (!S_ISLNK(st.st_mode)) {
                        ret = 0;
-               } else if (t_readlink(path, &linkpath) < 0) {
-                       i_error("readlink(%s) failed: %m", path);
+               } else if (t_readlink(path, &linkpath, &error) < 0) {
+                       i_error("t_readlink(%s) failed: %s", path, error);
                        ret = -1;
                } else {
                        /* it's an alias only if it points to the same
index b9e5f7c361948fb8b8f80ed96a762a2f6d03cbbb..b2eba3b5a0aa9d373f6d3df314fe830ad333b3e0 100644 (file)
@@ -48,8 +48,10 @@ int t_get_current_dir(const char **dir_r)
        return 0;
 }
 
-int t_readlink(const char *path, const char **dest_r)
+int t_readlink(const char *path, const char **dest_r, const char **error_r)
 {
+       i_assert(error_r != NULL);
+
        /* @UNSAFE */
        ssize_t ret;
        char *dest;
@@ -60,8 +62,10 @@ int t_readlink(const char *path, const char **dest_r)
                size = nearest_power(size+1);
                dest = t_buffer_get(size);
        }
-       if (ret < 0)
+       if (ret < 0) {
+               *error_r = t_strdup_printf("readlink() failed: %m");
                return -1;
+       }
 
        dest[ret] = '\0';
        t_buffer_alloc(ret + 1);
index fc7b72a7b23bfb0e8e52e35356aa982930ab568a..af30e23e00aa300b3c5476215316b686ff64fb9e 100644 (file)
@@ -2,15 +2,22 @@
 #define PATH_UTIL_H
 
 /* Returns path as absolute path. If it's not already absolute path,
-   it's assumed to be relative to current working directory. */
+ * it's assumed to be relative to current working directory.
+ *
+ * In the t_abspath functions, the returned paths are not normalized. This
+ * means that './' and '../' are not resolved, but they left in the returned
+ * path as given in the parameters. Symbolic links are not resolved either.
+ */
 const char *t_abspath(const char *path);
 /* Like t_abspath(), but path is relative to given root. */
 const char *t_abspath_to(const char *path, const char *root);
 
 /* Returns current directory, allocated from data stack. */
 int t_get_current_dir(const char **dir_r);
-/* Returns symlink destination, allocated from data stack. */
-int t_readlink(const char *path, const char **dest_r);
+
+/* Get symlink destination allocated from data stack. Returns 0 on success and
+ * -1 on failure. error_r is set on failure and cannot be NULL. */
+int t_readlink(const char *path, const char **dest_r, const char **error_r);
 
 /* Update binpath to be absolute:
    a) begins with '/' -> no change