]> git.ipfire.org Git - thirdparty/util-linux.git/blob - libmount/src/init.c
misc: Fix various typos
[thirdparty/util-linux.git] / libmount / src / init.c
1 /*
2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7
8 /**
9 * SECTION: init
10 * @title: Library initialization
11 * @short_description: initialize debugging
12 */
13
14 #include <stdarg.h>
15
16 #include "mountP.h"
17
18 UL_DEBUG_DEFINE_MASK(libmount);
19 UL_DEBUG_DEFINE_MASKNAMES(libmount) =
20 {
21 { "all", MNT_DEBUG_ALL, "info about all subsystems" },
22 { "cache", MNT_DEBUG_CACHE, "paths and tags cache" },
23 { "cxt", MNT_DEBUG_CXT, "library context (handler)" },
24 { "diff", MNT_DEBUG_DIFF, "mountinfo changes tracking" },
25 { "fs", MNT_DEBUG_FS, "FS abstraction" },
26 { "help", MNT_DEBUG_HELP, "this help" },
27 { "locks", MNT_DEBUG_LOCKS, "mtab and utab locking" },
28 { "loop", MNT_DEBUG_LOOP, "loop devices routines" },
29 { "options", MNT_DEBUG_OPTIONS, "mount options parsing" },
30 { "tab", MNT_DEBUG_TAB, "fstab, mtab, mountinfo routines" },
31 { "update", MNT_DEBUG_UPDATE, "mtab, utab updates" },
32 { "utils", MNT_DEBUG_UTILS, "misc library utils" },
33 { "monitor", MNT_DEBUG_MONITOR, "mount tables monitor" },
34 { "btrfs", MNT_DEBUG_BTRFS, "btrfs specific routines" },
35
36 { NULL, 0 }
37 };
38
39 /**
40 * mnt_init_debug:
41 * @mask: debug mask (0xffff to enable full debugging)
42 *
43 * If the @mask is not specified, then this function reads
44 * the LIBMOUNT_DEBUG environment variable to get the mask.
45 *
46 * Already initialized debugging stuff cannot be changed. Calling
47 * this function twice has no effect.
48 */
49 void mnt_init_debug(int mask)
50 {
51 if (libmount_debug_mask)
52 return;
53
54 __UL_INIT_DEBUG(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG);
55
56 if (libmount_debug_mask != MNT_DEBUG_INIT
57 && libmount_debug_mask != (MNT_DEBUG_HELP|MNT_DEBUG_INIT)) {
58 const char *ver = NULL;
59 const char **features = NULL, **p;
60
61 mnt_get_library_version(&ver);
62 mnt_get_library_features(&features);
63
64 DBG(INIT, ul_debug("library debug mask: 0x%04x", libmount_debug_mask));
65 DBG(INIT, ul_debug("library version: %s", ver));
66 p = features;
67 while (p && *p)
68 DBG(INIT, ul_debug(" feature: %s", *p++));
69 }
70
71 ON_DBG(HELP, ul_debug_print_masks("LIBMOUNT_DEBUG",
72 UL_DEBUG_MASKNAMES(libmount)));
73 }
74
75 #ifdef TEST_PROGRAM
76
77 #include <errno.h>
78 #include <stdlib.h>
79 int main(int argc, char *argv[])
80 {
81 if (argc == 2) {
82 int mask;
83
84 errno = 0;
85 mask = strtoul(argv[1], 0, 0);
86
87 if (errno)
88 return 1;
89
90 mnt_init_debug(mask);
91 }
92 else if (argc == 1) {
93 mnt_init_debug(0);
94 } else
95 return 1;
96
97 return 0;
98 }
99 #endif /* TEST_PROGRAM */
100