From 61d9d2ff1cb0e28e2b88099bbc5b919fa5004fce Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 27 Dec 2006 23:35:56 +0100 Subject: mount: add simple (printf-like) debug routine and --debug option The --debug= command line option enables debug outputs. It's undocumented option, because it's really for debug/tests purpose only. Signed-off-by: Karel Zak --- mount/mount.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'mount/mount.c') diff --git a/mount/mount.c b/mount/mount.c index a51cfe204..5dc62ef62 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -44,6 +44,13 @@ #include "setproctitle.h" #endif +/* Quiet mode */ +int mount_quiet = 0; + +/* Debug mode (level) */ +int mount_debug = 0; + + /* True for fake mount (-f). */ static int fake = 0; @@ -207,7 +214,6 @@ parse_string_opt(char *s) { return 0; } -int mount_quiet=0; /* Report on a single mount. */ static void @@ -453,6 +459,10 @@ do_mount_syscall (struct mountargs *args) { if ((flags & MS_MGC_MSK) == 0) flags |= MS_MGC_VAL; + mnt_debug(1, "mount(2) syscall: source=\"%s\" target=\"%s\" " + "filesystemtype=\"%s\" mountflags=%lu data=%s", + args->spec, args->node, args->type, flags, args->data ? "YES" : "NOT"); + ret = mount (args->spec, args->node, args->type, flags, args->data); if (ret == 0) mountcount++; @@ -734,7 +744,7 @@ check_special_mountprog(const char *spec, const char *node, const char *type, res = fork(); if (res == 0) { const char *oo, *mountargs[10]; - int i = 0; + int i = 0, x; setuid(getuid()); setgid(getgid()); @@ -751,6 +761,11 @@ check_special_mountprog(const char *spec, const char *node, const char *type, mountargs[i++] = oo; } mountargs[i] = NULL; + + for(x = 0; x < 10 && mountargs[x]; x++) + mnt_debug(1, "external mount: argv[%d] = \"%s\"", + x, mountargs[x]); + execv(mountprog, (char **) mountargs); exit(1); /* exec failed */ } else if (res != -1) { @@ -795,6 +810,11 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, /* copies for freeing on exit */ const char *opts1, *spec1, *node1, *types1, *extra_opts1; + mnt_debug(1, "spec: \"%s\"", spec0); + mnt_debug(1, "node: \"%s\"", node0); + mnt_debug(1, "types: \"%s\"", types0); + mnt_debug(1, "opts: \"%s\"", opts0); + spec = spec1 = xstrdup(spec0); node = node1 = xstrdup(node0); types = types1 = xstrdup(types0); @@ -1382,6 +1402,7 @@ do_mount_all (char *types, char *options, char *test_opts) { static struct option longopts[] = { { "all", 0, 0, 'a' }, + { "debug", 1, 0, 'd' }, { "fake", 0, 0, 'f' }, { "fork", 0, 0, 'F' }, { "help", 0, 0, 'h' }, @@ -1481,12 +1502,15 @@ main(int argc, char *argv[]) { initproctitle(argc, argv); #endif - while ((c = getopt_long (argc, argv, "afFhilL:no:O:p:rsU:vVwt:", + while ((c = getopt_long (argc, argv, "ad:fFhilL:no:O:p:rsU:vVwt:", longopts, NULL)) != -1) { switch (c) { case 'a': /* mount everything in fstab */ ++mount_all; break; + case 'd': + mount_debug = atoi(optarg); + break; case 'f': /* fake: don't actually call mount(2) */ ++fake; break; @@ -1587,6 +1611,10 @@ main(int argc, char *argv[]) { } } + mnt_debug(2, "fstab path: \"%s\"", _PATH_FSTAB); + mnt_debug(2, "lock path: \"%s\"", MOUNTED_LOCK); + mnt_debug(2, "temp path: \"%s\"", MOUNTED_TEMP); + argc -= optind; argv += optind; -- cgit v1.2.3-55-g7522