Import a configuration file into the configuration database. Ensure the
server is not using the configuration database! (*)
.TP
-\fBconf\-export\fP \fIfilename\fP
-Export the configuration database into a config file. (*)
+\fBconf\-export\fP [\fIfilename\fP]
+Export the configuration database into a config file or stdout. (*)
.TP
\fBconf\-list\fP [\fIitem\fP]
List the configuration database sections or section items.
Import a configuration file into the configuration database. Ensure the
server is not using the configuration database! (*)
-**conf-export** *filename*
- Export the configuration database into a config file. (*)
+**conf-export** [*filename*]
+ Export the configuration database into a config file or stdout. (*)
**conf-list** [*item*]
List the configuration database sections or section items.
-/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
const char *file_name,
yp_style_t style)
{
- if (conf == NULL || file_name == NULL) {
+ if (conf == NULL) {
return KNOT_EINVAL;
}
return KNOT_ENOMEM;
}
- FILE *fp = fopen(file_name, "w");
+ FILE *fp = (file_name != NULL) ? fopen(file_name, "w") : stdout;
if (fp == NULL) {
free(buff);
return knot_map_errno();
ret = KNOT_EOK;
export_error:
- fclose(fp);
+ if (file_name != NULL) {
+ fclose(fp);
+ }
free(buff);
return ret;
-/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
* Exports configuration to textual file.
*
* \param[in] conf Configuration.
- * \param[in] file_name Output filename.
+ * \param[in] file_name Output filename (stdout is used if NULL).
* \param[in] style Formatting style.
*
* \return Error code, KNOT_EOK if success.
-/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static int cmd_conf_export(cmd_args_t *args)
{
- int ret = check_args(args, 1, 1);
+ int ret = check_args(args, 0, 1);
if (ret != KNOT_EOK) {
return ret;
}
- log_debug("exporting confdb into file '%s'", args->argv[0]);
+ // Stdout is the default output file.
+ const char *file_name = NULL;
+ if (args->argc > 0) {
+ file_name = args->argv[0];
+ log_debug("exporting confdb into file '%s'", file_name);
+ }
- ret = conf_export(conf(), args->argv[0], YP_SNONE);
+ ret = conf_export(conf(), file_name, YP_SNONE);
if (ret == KNOT_EOK) {
- log_info("OK");
+ if (args->argc > 0) {
+ log_info("OK");
+ }
} else {
log_error("export (%s)", knot_strerror(ret));
}
{ CMD_CONF_INIT, "", "Initialize the confdb. (*)" },
{ CMD_CONF_CHECK, "", "Check the server configuration. (*)" },
{ CMD_CONF_IMPORT, "<filename>", "Import a config file into the confdb. (*)" },
- { CMD_CONF_EXPORT, "<filename>", "Export the confdb into a config file. (*)" },
+ { CMD_CONF_EXPORT, "[<filename>]", "Export the confdb into a config file or stdout. (*)" },
{ CMD_CONF_LIST, "[<item>...]", "List the confdb sections or section items." },
{ CMD_CONF_READ, "[<item>...]", "Get the item from the active confdb." },
{ CMD_CONF_BEGIN, "", "Begin a writing confdb transaction." },