]>
Commit | Line | Data |
---|---|---|
2c37ca7c | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c12cec75 | 2 | /* |
2c37ca7c | 3 | * This file is part of libmount from util-linux project. |
c12cec75 | 4 | * |
2c37ca7c KZ |
5 | * Copyright (C) 2008-2018 Karel Zak <kzak@redhat.com> |
6 | * | |
7 | * libmount is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU Lesser General Public License as published by | |
9 | * the Free Software Foundation; either version 2.1 of the License, or | |
10 | * (at your option) any later version. | |
c12cec75 KZ |
11 | */ |
12 | ||
192c6aad KZ |
13 | /** |
14 | * SECTION: init | |
15 | * @title: Library initialization | |
d58b3157 | 16 | * @short_description: initialize debugging |
192c6aad KZ |
17 | */ |
18 | ||
3f31a959 | 19 | #include <stdarg.h> |
c12cec75 KZ |
20 | |
21 | #include "mountP.h" | |
22 | ||
d7365821 | 23 | UL_DEBUG_DEFINE_MASK(libmount); |
819d9a29 | 24 | UL_DEBUG_DEFINE_MASKNAMES(libmount) = |
03e4220d | 25 | { |
35333416 KZ |
26 | { "all", MNT_DEBUG_ALL, "info about all subsystems" }, |
27 | { "cache", MNT_DEBUG_CACHE, "paths and tags cache" }, | |
28 | { "cxt", MNT_DEBUG_CXT, "library context (handler)" }, | |
29 | { "diff", MNT_DEBUG_DIFF, "mountinfo changes tracking" }, | |
30 | { "fs", MNT_DEBUG_FS, "FS abstraction" }, | |
31 | { "help", MNT_DEBUG_HELP, "this help" }, | |
8241fb00 | 32 | { "hook", MNT_DEBUG_HOOK, "hooks functionality" }, |
35333416 | 33 | { "locks", MNT_DEBUG_LOCKS, "mtab and utab locking" }, |
7bbde59c | 34 | { "loop", MNT_DEBUG_LOOP, "loop devices routines" }, |
35333416 | 35 | { "options", MNT_DEBUG_OPTIONS, "mount options parsing" }, |
45c1fe0c | 36 | { "optlist", MNT_DEBUG_OPTLIST, "mount options container" }, |
9e930041 | 37 | { "tab", MNT_DEBUG_TAB, "fstab, mtab, mountinfo routines" }, |
35333416 KZ |
38 | { "update", MNT_DEBUG_UPDATE, "mtab, utab updates" }, |
39 | { "utils", MNT_DEBUG_UTILS, "misc library utils" }, | |
372112e9 | 40 | { "monitor", MNT_DEBUG_MONITOR, "mount tables monitor" }, |
2cd28fc8 | 41 | { "btrfs", MNT_DEBUG_BTRFS, "btrfs specific routines" }, |
e6a49887 | 42 | { "verity", MNT_DEBUG_VERITY, "verity specific routines" }, |
372112e9 | 43 | |
14ad2353 OO |
44 | { NULL, 0 } |
45 | }; | |
03e4220d | 46 | |
192c6aad KZ |
47 | /** |
48 | * mnt_init_debug: | |
d58b3157 | 49 | * @mask: debug mask (0xffff to enable full debugging) |
192c6aad | 50 | * |
d58b3157 OO |
51 | * If the @mask is not specified, then this function reads |
52 | * the LIBMOUNT_DEBUG environment variable to get the mask. | |
192c6aad | 53 | * |
d58b3157 OO |
54 | * Already initialized debugging stuff cannot be changed. Calling |
55 | * this function twice has no effect. | |
192c6aad | 56 | */ |
c12cec75 KZ |
57 | void mnt_init_debug(int mask) |
58 | { | |
35333416 KZ |
59 | if (libmount_debug_mask) |
60 | return; | |
61 | ||
a15dca2f | 62 | __UL_INIT_DEBUG_FROM_ENV(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG); |
39de73f5 | 63 | |
35333416 KZ |
64 | if (libmount_debug_mask != MNT_DEBUG_INIT |
65 | && libmount_debug_mask != (MNT_DEBUG_HELP|MNT_DEBUG_INIT)) { | |
39de73f5 KZ |
66 | const char *ver = NULL; |
67 | const char **features = NULL, **p; | |
68 | ||
39de73f5 KZ |
69 | mnt_get_library_version(&ver); |
70 | mnt_get_library_features(&features); | |
71 | ||
45c1fe0c | 72 | DBG(INIT, ul_debug("library debug mask: 0x%06x", libmount_debug_mask)); |
83a78332 | 73 | DBG(INIT, ul_debug("library version: %s", ver)); |
39de73f5 KZ |
74 | p = features; |
75 | while (p && *p) | |
83a78332 | 76 | DBG(INIT, ul_debug(" feature: %s", *p++)); |
39de73f5 | 77 | } |
35333416 KZ |
78 | |
79 | ON_DBG(HELP, ul_debug_print_masks("LIBMOUNT_DEBUG", | |
80 | UL_DEBUG_MASKNAMES(libmount))); | |
c12cec75 | 81 | } |
14ad2353 OO |
82 | |
83 | #ifdef TEST_PROGRAM | |
84 | ||
85 | #include <errno.h> | |
86 | #include <stdlib.h> | |
87 | int main(int argc, char *argv[]) | |
88 | { | |
89 | if (argc == 2) { | |
90 | int mask; | |
91 | ||
92 | errno = 0; | |
93 | mask = strtoul(argv[1], 0, 0); | |
94 | ||
95 | if (errno) | |
96 | return 1; | |
97 | ||
74d70957 | 98 | mnt_init_debug(mask); |
14ad2353 OO |
99 | } |
100 | else if (argc == 1) { | |
74d70957 KZ |
101 | mnt_init_debug(0); |
102 | } else | |
14ad2353 OO |
103 | return 1; |
104 | ||
105 | return 0; | |
106 | } | |
107 | #endif /* TEST_PROGRAM */ | |
108 |