1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dumpconfig to dump active configuration

This commit is contained in:
Alasdair Kergon 2003-10-15 20:17:19 +00:00
parent c7ee8edc33
commit dcc31da516
4 changed files with 57 additions and 5 deletions

View 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;
}

View 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 \

View 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")

39
tools/dumpconfig.c Normal file
View File

@ -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;
}