/src/util-linux/libmount/src/init.c
Line | Count | Source |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | /* |
3 | | * This file is part of libmount from util-linux project. |
4 | | * |
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. |
11 | | */ |
12 | | |
13 | | /** |
14 | | * SECTION: init |
15 | | * @title: Library initialization |
16 | | * @short_description: initialize debugging |
17 | | */ |
18 | | |
19 | | #include <stdarg.h> |
20 | | |
21 | | #include "mountP.h" |
22 | | |
23 | | UL_DEBUG_DEFINE_MASK(libmount); |
24 | | UL_DEBUG_DEFINE_MASKNAMES(libmount) = |
25 | | { |
26 | | { "all", UL_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" }, |
32 | | { "hook", MNT_DEBUG_HOOK, "hooks functionality" }, |
33 | | { "locks", MNT_DEBUG_LOCKS, "mtab and utab locking" }, |
34 | | { "loop", MNT_DEBUG_LOOP, "loop devices routines" }, |
35 | | { "options", MNT_DEBUG_OPTIONS, "mount options parsing" }, |
36 | | { "optlist", MNT_DEBUG_OPTLIST, "mount options container" }, |
37 | | { "tab", MNT_DEBUG_TAB, "fstab, mtab, mountinfo routines" }, |
38 | | { "update", MNT_DEBUG_UPDATE, "mtab, utab updates" }, |
39 | | { "utils", MNT_DEBUG_UTILS, "misc library utils" }, |
40 | | { "monitor", MNT_DEBUG_MONITOR, "mount tables monitor" }, |
41 | | { "btrfs", MNT_DEBUG_BTRFS, "btrfs specific routines" }, |
42 | | { "verity", MNT_DEBUG_VERITY, "verity specific routines" }, |
43 | | |
44 | | { NULL, 0 } |
45 | | }; |
46 | | |
47 | | /** |
48 | | * mnt_init_debug: |
49 | | * @mask: debug mask (UL_DEBUG_ALL to enable full debugging) |
50 | | * |
51 | | * If the @mask is not specified, then this function reads |
52 | | * the LIBMOUNT_DEBUG environment variable to get the mask. |
53 | | * |
54 | | * Already initialized debugging stuff cannot be changed. Calling |
55 | | * this function twice has no effect. |
56 | | */ |
57 | | void mnt_init_debug(int mask) |
58 | 0 | { |
59 | 0 | if (libmount_debug_mask) |
60 | 0 | return; |
61 | | |
62 | 0 | __UL_INIT_DEBUG_FROM_ENV(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG); |
63 | |
|
64 | 0 | if (libmount_debug_mask != MNT_DEBUG_INIT |
65 | 0 | && libmount_debug_mask != (MNT_DEBUG_HELP|MNT_DEBUG_INIT)) { |
66 | 0 | const char *ver = NULL; |
67 | 0 | const char **features = NULL, **p; |
68 | |
|
69 | 0 | mnt_get_library_version(&ver); |
70 | 0 | mnt_get_library_features(&features); |
71 | |
|
72 | 0 | DBG(INIT, ul_debug("library debug mask: 0x%08x", libmount_debug_mask)); |
73 | 0 | DBG(INIT, ul_debug("library version: %s", ver)); |
74 | 0 | p = features; |
75 | 0 | while (p && *p) |
76 | 0 | DBG(INIT, ul_debug(" feature: %s", *p++)); |
77 | 0 | } |
78 | |
|
79 | 0 | ON_DBG(HELP, ul_debug_print_masks("LIBMOUNT_DEBUG", |
80 | 0 | UL_DEBUG_MASKNAMES(libmount))); |
81 | 0 | } |
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 | | |
98 | | mnt_init_debug(mask); |
99 | | } |
100 | | else if (argc == 1) { |
101 | | mnt_init_debug(0); |
102 | | } else |
103 | | return 1; |
104 | | |
105 | | return 0; |
106 | | } |
107 | | #endif /* TEST_PROGRAM */ |
108 | | |