diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2015-04-30 13:59:00 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2015-04-30 14:06:55 +0200 |
commit | 4388ab477c644c3d58b81acf2de969d49fb984ca (patch) | |
tree | 72424b597afad53fb22f1fa04cd8aeb83fb0c722 | |
parent | 3706abde5e7703562bad3072cca13faf31b6b8b6 (diff) | |
download | lvm2-4388ab477c644c3d58b81acf2de969d49fb984ca.tar.gz |
lvmconfig: comment out settings with proper space/tab prefix
We're commenting out settings with undefined default values.
The comment character '#' was printed at the very beginning of
the line, it should be placed just at the beginning of the setting,
after the space/tab prefix is printed.
Before this patch:
$ lvmconfig --type default activation
activation {
...
# volume_list=[]
...
}
With this patch applied:
$ lvmconfig --type default activation
activation {
...
# volume_list=[]
...
}
-rw-r--r-- | lib/config/config.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/config/config.c b/lib/config/config.c index 167cfffd5..385bf9ea0 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -1609,6 +1609,8 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void char summary[MAX_COMMENT_LINE+1]; char version[9]; int pos = 0; + size_t len; + char *space_prefix; if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) && (!(out->tree_spec->check_status[cn->id] & CFG_DIFF))) @@ -1639,9 +1641,15 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void } /* Usual tree view with nodes and their values. */ - fprintf(out->fp, "%s%s\n", (out->tree_spec->type != CFG_DEF_TREE_CURRENT) && - (out->tree_spec->type != CFG_DEF_TREE_DIFF) && - (cfg_def->flags & CFG_DEFAULT_UNDEFINED) ? "#" : "", line); + if ((out->tree_spec->type != CFG_DEF_TREE_CURRENT) && + (out->tree_spec->type != CFG_DEF_TREE_DIFF) && + (cfg_def->flags & CFG_DEFAULT_UNDEFINED)) { + space_prefix = ((len = strspn(line, "\t "))) ? dm_pool_strndup(out->mem, line, len) : NULL; + fprintf(out->fp, "%s%s%s\n", space_prefix ? : "", "# ", line + len); + if (space_prefix) + dm_pool_free(out->mem, space_prefix); + } else + fprintf(out->fp, "%s\n", line); return 1; } |