2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2007-12-06 05:40:15 +08:00
|
|
|
|
2006-08-30 06:27:07 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2007-11-13 06:16:25 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2012-12-13 00:35:35 +08:00
|
|
|
#include "virconf.h"
|
2012-12-13 02:06:53 +08:00
|
|
|
#include "viralloc.h"
|
2006-08-30 06:27:07 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret, exit_code = EXIT_FAILURE;
|
2014-09-01 20:08:04 +08:00
|
|
|
virConfPtr conf = NULL;
|
2006-08-30 06:27:07 +08:00
|
|
|
int len = 10000;
|
2011-04-25 06:25:10 +08:00
|
|
|
char *buffer = NULL;
|
2006-08-30 06:27:07 +08:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
|
2011-04-25 06:25:10 +08:00
|
|
|
goto cleanup;
|
2006-08-30 06:27:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 16:37:25 +08:00
|
|
|
if (VIR_ALLOC_N_QUIET(buffer, len) < 0) {
|
2011-04-25 06:25:10 +08:00
|
|
|
fprintf(stderr, "out of memory\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-06-19 20:34:30 +08:00
|
|
|
conf = virConfReadFile(argv[1], 0);
|
2006-08-30 06:27:07 +08:00
|
|
|
if (conf == NULL) {
|
|
|
|
fprintf(stderr, "Failed to process %s\n", argv[1]);
|
2011-04-25 06:25:10 +08:00
|
|
|
goto cleanup;
|
2006-08-30 06:27:07 +08:00
|
|
|
}
|
2011-04-25 06:25:10 +08:00
|
|
|
ret = virConfWriteMem(buffer, &len, conf);
|
2006-08-30 06:27:07 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
|
2011-04-25 06:25:10 +08:00
|
|
|
goto cleanup;
|
2006-08-30 06:27:07 +08:00
|
|
|
}
|
2007-11-13 06:16:25 +08:00
|
|
|
if (fwrite(buffer, 1, len, stdout) != len) {
|
2012-10-17 17:23:12 +08:00
|
|
|
fprintf(stderr, "Write failed: %s\n", strerror(errno));
|
2011-04-25 06:25:10 +08:00
|
|
|
goto cleanup;
|
2007-10-19 16:29:13 +08:00
|
|
|
}
|
2011-04-25 06:25:10 +08:00
|
|
|
|
|
|
|
exit_code = EXIT_SUCCESS;
|
|
|
|
|
2014-03-25 14:53:44 +08:00
|
|
|
cleanup:
|
2011-04-25 06:25:10 +08:00
|
|
|
VIR_FREE(buffer);
|
2014-09-01 20:08:04 +08:00
|
|
|
virConfFree(conf);
|
2011-04-25 06:25:10 +08:00
|
|
|
return exit_code;
|
2006-08-30 06:27:07 +08:00
|
|
|
}
|