]> sourceware.org Git - lvm2.git/commitdiff
dumpconfig to dump active configuration
authorAlasdair Kergon <agk@redhat.com>
Wed, 15 Oct 2003 20:17:19 +0000 (20:17 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 15 Oct 2003 20:17:19 +0000 (20:17 +0000)
lib/config/config.c
tools/Makefile.in
tools/commands.h
tools/dumpconfig.c [new file with mode: 0644]

index ce33c63f01b907311712547c528aafc82f0c4ddd..8c201f7ded80fe9958c121bdd01ca096c40d7054 100644 (file)
@@ -385,17 +385,25 @@ static int _write_config(struct config_node *n, FILE *fp, int level)
 int write_config_file(struct config_tree *cf, const char *file)
 {
        int r = 1;
-       FILE *fp = fopen(file, "w");
-       if (!fp) {
+       FILE *fp;
+
+       if (!file) {
+               fp = stdout;
+               file = "stdout";
+       } else if (!(fp = fopen(file, "w"))) {
                log_sys_error("open", file);
                return 0;
        }
 
+       log_verbose("Dumping configuration to %s", file);
        if (!_write_config(cf->root, fp, 0)) {
-               stack;
+               log_error("Failure while writing configuration");
                r = 0;
        }
-       fclose(fp);
+
+       if (fp != stdout)
+               fclose(fp);
+
        return r;
 }
 
index aa8553fa8eb190a50ae05d38d0cdf9902dda7012..d198cf53dde25b9d6dd171f1a7b7f835cf4f33d7 100644 (file)
@@ -22,6 +22,7 @@ VPATH = @srcdir@
 
 SOURCES=\
        archive.c \
+       dumpconfig.c \
        lvchange.c \
        lvcreate.c \
        lvdisplay.c \
@@ -81,7 +82,7 @@ lvm: $(OBJECTS) $(top_srcdir)/lib/liblvm.a
 
 .commands: commands.h cmdnames.h Makefile
        $(CC) -E -P cmdnames.h 2> /dev/null | \
-               egrep -v '^ *(|#.*|help|pvdata|version) *$$' > .commands
+               egrep -v '^ *(|#.*|dumpconfig|help|pvdata|version) *$$' > .commands
 
 install: $(TARGETS)
        $(INSTALL) -D -o $(OWNER) -g $(GROUP) -m 555 $(STRIP) lvm \
index 93f0917bbb09c7bc29d567c3f9a3adf3b9e54780..3c03b80a403825d805e16f703522aba9721223b3 100644 (file)
@@ -33,6 +33,10 @@ xx(e2fsadm,
     extents_ARG, size_ARG, nofsck_ARG, test_ARG)
 *********/
 
+xx(dumpconfig,
+   "Dump active configuration",
+   "dumpconfig <filename>\n")
+
 xx(help,
    "Display help for commands",
    "help <command>" "\n")
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c
new file mode 100644 (file)
index 0000000..f1fa507
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2003  Sistina Software
+ *
+ * LVM is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LVM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LVM; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "tools.h"
+
+int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
+{
+       const char *file = NULL;
+
+       if (argc == 1)
+               file = argv[0];
+
+       if (argc > 1) {
+               log_error("Please specify one file for output");
+               return EINVALID_CMD_LINE;
+       }
+
+       if (!write_config_file(cmd->cft, file))
+               return ECMD_FAILED;
+
+       return ECMD_PROCESSED;
+}
This page took 0.039202 seconds and 5 git commands to generate.