]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: load and unload libicu properly
authorDarrick J. Wong <djwong@kernel.org>
Fri, 12 Feb 2021 22:23:06 +0000 (17:23 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 12 Feb 2021 22:23:06 +0000 (17:23 -0500)
Make sure we actually load and unload libicu properly.  This isn't
strictly required since the library can bootstrap itself, but unloading
means fewer things for valgrind to complain about.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
scrub/unicrash.c
scrub/unicrash.h
scrub/xfs_scrub.c

index d5d2cf201e34802b96f4ffa73090394a2b774801..de3217c2932df29cad2ff799e663d4ec7f94c0f1 100644 (file)
@@ -722,3 +722,20 @@ unicrash_check_fs_label(
        return __unicrash_check_name(uc, dsc, _("filesystem label"),
                        label, 0);
 }
+
+/* Load libicu and initialize it. */
+bool
+unicrash_load(void)
+{
+       UErrorCode              uerr = U_ZERO_ERROR;
+
+       u_init(&uerr);
+       return U_FAILURE(uerr);
+}
+
+/* Unload libicu once we're done with it. */
+void
+unicrash_unload(void)
+{
+       u_cleanup();
+}
index c3a7f385c528777986dfacd34707426bed7cf93f..755afaef18c974a12e2da18262ae75672614cf58 100644 (file)
@@ -25,6 +25,8 @@ int unicrash_check_xattr_name(struct unicrash *uc, struct descr *dsc,
                const char *attrname);
 int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
                const char *label);
+bool unicrash_load(void);
+void unicrash_unload(void);
 #else
 # define unicrash_dir_init(u, c, b)            (0)
 # define unicrash_xattr_init(u, c, b)          (0)
@@ -33,6 +35,8 @@ int unicrash_check_fs_label(struct unicrash *uc, struct descr *dsc,
 # define unicrash_check_dir_name(u, d, n)      (0)
 # define unicrash_check_xattr_name(u, d, n)    (0)
 # define unicrash_check_fs_label(u, d, n)      (0)
+# define unicrash_load()                       (0)
+# define unicrash_unload()                     do { } while (0)
 #endif /* HAVE_LIBICU */
 
 #endif /* XFS_SCRUB_UNICRASH_H_ */
index 1edeb15063fe1f1382da1854e7c6b50bdcc5b002..bc2e84a73aa07c8ff82e70ee9c5991ca231687cc 100644 (file)
@@ -603,6 +603,12 @@ main(
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       if (unicrash_load()) {
+               fprintf(stderr,
+       _("%s: couldn't initialize Unicode library.\n"),
+                               progname);
+               goto out;
+       }
 
        pthread_mutex_init(&ctx.lock, NULL);
        ctx.mode = SCRUB_MODE_REPAIR;
@@ -788,6 +794,7 @@ out:
        phase_end(&all_pi, 0);
        if (progress_fp)
                fclose(progress_fp);
+       unicrash_unload();
 
        /*
         * If we're being run as a service, the return code must fit the LSB