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

cleanup: use simplier structure initialization

And also use static struct for _out_spec.
This commit is contained in:
Zdenek Kabelac 2013-06-14 22:00:44 +02:00
parent 636c51ae3f
commit 5e19410d93
3 changed files with 22 additions and 16 deletions

View File

@ -1830,8 +1830,8 @@ static void _daemonize(void)
static void restart(void) static void restart(void)
{ {
struct dm_event_fifos fifos; struct dm_event_fifos fifos = { 0 };
struct dm_event_daemon_message msg = { 0, 0, NULL }; struct dm_event_daemon_message msg = { 0 };
int i, count = 0; int i, count = 0;
char *message; char *message;
int length; int length;

View File

@ -879,16 +879,18 @@ int config_write(struct dm_config_tree *cft,
int withcomment, int withversion, int withcomment, int withversion,
const char *file, int argc, char **argv) const char *file, int argc, char **argv)
{ {
struct out_baton baton = {0, 0, 0}; static const struct dm_config_node_out_spec _out_spec = {
const struct dm_config_node *cn; .prefix_fn = _out_prefix_fn,
const struct dm_config_node_out_spec out_spec = {.prefix_fn = _out_prefix_fn,
.line_fn = _out_line_fn, .line_fn = _out_line_fn,
.suffix_fn = _out_suffix_fn}; .suffix_fn = _out_suffix_fn
};
const struct dm_config_node *cn;
struct out_baton baton = {
.withcomment = withcomment,
.withversion = withversion
};
int r = 1; int r = 1;
baton.withcomment = withcomment;
baton.withversion = withversion;
if (!file) { if (!file) {
baton.fp = stdout; baton.fp = stdout;
file = "stdout"; file = "stdout";
@ -899,13 +901,13 @@ int config_write(struct dm_config_tree *cft,
log_verbose("Dumping configuration to %s", file); log_verbose("Dumping configuration to %s", file);
if (!argc) { if (!argc) {
if (!dm_config_write_node_out(cft->root, &out_spec, &baton)) { if (!dm_config_write_node_out(cft->root, &_out_spec, &baton)) {
log_error("Failure while writing to %s", file); log_error("Failure while writing to %s", file);
r = 0; r = 0;
} }
} else while (argc--) { } else while (argc--) {
if ((cn = dm_config_find_node(cft->root, *argv))) { if ((cn = dm_config_find_node(cft->root, *argv))) {
if (!dm_config_write_one_node_out(cn, &out_spec, &baton)) { if (!dm_config_write_one_node_out(cn, &_out_spec, &baton)) {
log_error("Failure while writing to %s", file); log_error("Failure while writing to %s", file);
r = 0; r = 0;
} }

View File

@ -346,12 +346,16 @@ static int _write_node(const struct dm_config_node *cn, int only_one,
const struct dm_config_node_out_spec *out_spec, const struct dm_config_node_out_spec *out_spec,
void *baton) void *baton)
{ {
struct config_output out; struct config_output out = {
if (!(out.mem = dm_pool_create("config_output", 1024))) .mem = dm_pool_create("config_output", 1024),
.putline = putline,
.spec = out_spec,
.baton = baton
};
if (!out.mem)
return_0; return_0;
out.putline = putline;
out.spec = out_spec;
out.baton = baton;
if (!_write_config(cn, only_one, &out, 0)) { if (!_write_config(cn, only_one, &out, 0)) {
dm_pool_destroy(out.mem); dm_pool_destroy(out.mem);
return_0; return_0;