From: Karel Zak Date: Wed, 27 Dec 2006 22:35:56 +0000 (+0100) Subject: mount: add simple (printf-like) debug routine and --debug option X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61d9d2ff1cb0e28e2b88099bbc5b919fa5004fce;p=util-linux 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 --- diff --git a/mount/mount.c b/mount/mount.c index a51cfe20..5dc62ef6 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; diff --git a/mount/sundries.h b/mount/sundries.h index 6def95b1..00959be7 100644 --- a/mount/sundries.h +++ b/mount/sundries.h @@ -2,7 +2,10 @@ * sundries.h * Support function prototypes. Functions are in sundries.c. */ +#ifndef SUNDRIES_H +#define SUNDRIES_H +#include #include #include #include @@ -14,6 +17,7 @@ #endif extern int mount_quiet; +extern int mount_debug; extern int verbose; extern int sloppy; @@ -47,3 +51,23 @@ int nfsmount (const char *spec, const char *node, int *flags, #define EX_SOMEOK 64 /* some mount succeeded */ #define EX_BG 256 /* retry in background (internal only) */ + +static inline void +mnt_debug(int lev, const char *fmt, ...) +{ + va_list ap; + + if (lev > mount_debug) + return; + + fputs("DEBUG: ", stderr); + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + fputc('\n', stderr); +} + +#endif /* SUNDRIES_H */ +