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;
}
SOURCES=\
archive.c \
+ dumpconfig.c \
lvchange.c \
lvcreate.c \
lvdisplay.c \
.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 \
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")
--- /dev/null
+/*
+ * 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;
+}