File: global.c

package info (click to toggle)
erofs-utils 1.9-2
  • links: PTS
  • area: main
  • in suites:
  • size: 1,392 kB
  • sloc: ansic: 28,406; makefile: 203; sh: 33
file content (59 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0
/*
 * Copyright (C) 2025 Alibaba Cloud
 */
#include "erofs/lock.h"
#ifdef HAVE_CURL_CURL_H
#include <curl/curl.h>
#endif
#ifdef HAVE_LIBXML_PARSER_H
#include <libxml/parser.h>
#endif
#include "erofs/err.h"
#include "erofs/config.h"
#include "liberofs_compress.h"

static EROFS_DEFINE_MUTEX(erofs_global_mutex);
#ifdef HAVE_LIBCURL
static bool erofs_global_curl_initialized;
#endif

int liberofs_global_init(void)
{
	int err = 0;

	erofs_mutex_lock(&erofs_global_mutex);
	erofs_init_configure();
#ifdef S3EROFS_ENABLED
	xmlInitParser();
#endif
#ifdef HAVE_LIBCURL
	if (!erofs_global_curl_initialized) {
		if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
			err = -EFAULT;
			goto out_unlock;
		}
		erofs_global_curl_initialized = true;
	}
out_unlock:
#endif
	erofs_mutex_unlock(&erofs_global_mutex);
	return err;
}

void liberofs_global_exit(void)
{
	erofs_mutex_lock(&erofs_global_mutex);
	z_erofs_mt_global_exit();
#ifdef HAVE_LIBCURL
	if (erofs_global_curl_initialized) {
		curl_global_cleanup();
		erofs_global_curl_initialized = false;
	}
#endif
#ifdef S3EROFS_ENABLED
	xmlCleanupParser();
#endif
	erofs_exit_configure();
	erofs_mutex_unlock(&erofs_global_mutex);
}