mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-05 04:41:20 +00:00
acf522e85a
Commit0c6ad476
updated gnulib, which rearranged some of the conditions in gnulib wrapper headers such that compilation started failing on BSD systems when the normal system <unistd.h> tried to include another system header but instead got a gnulib wrapper header in an incomplete state; this is because gnulib headers only work if <config.h> is included first. Commitb6f78259
papered over the symptoms of that by including <config.h> in all the examples. But this logic is backwards - if our examples are truly meant to be stand-alone, they should NOT depend on how libvirt was configured, and should NOT depend on the gnulib fixes for system quirks. In particular, if an example does not need to link against libgnulib.la, then it also does not need to use -Ignulib in its compile flags, and likewise does not need to include <config.h> since none of the gnulib wrapper headers should be interfering. So, revert (most of)b6f78259
(except for the bogus pre-patch use of "config.h" in admin/logging.c: if config.h is included, it should be via <> rather than "", and must be before any system headers); then additionally nuke all mention of <config.h>, -Ignulib, and -llibgnu.la, making all of the examples truly standalone. Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
108 lines
2.8 KiB
C
108 lines
2.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
#include <libvirt/libvirt-admin.h>
|
|
#include <libvirt/virterror.h>
|
|
|
|
static void printHelp(const char *argv0)
|
|
{
|
|
fprintf(stderr,
|
|
("Usage:\n"
|
|
" %s [options]\n"
|
|
"\n"
|
|
"Options:\n"
|
|
" -h Print this message.\n"
|
|
" -o [string] Specify new log outputs.\n"
|
|
" -f [string] Specify new log filters.\n"
|
|
"\n"),
|
|
argv0);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret, c;
|
|
virAdmConnectPtr conn = NULL;
|
|
char *get_outputs = NULL;
|
|
char *get_filters = NULL;
|
|
const char *set_outputs = NULL;
|
|
const char *set_filters = NULL;
|
|
|
|
ret = c = -1;
|
|
opterr = 0;
|
|
|
|
while ((c = getopt(argc, argv, ":hpo:f:")) > 0) {
|
|
switch (c) {
|
|
case 'h':
|
|
printHelp(argv[0]);
|
|
exit(EXIT_SUCCESS);
|
|
case 'o':
|
|
set_outputs = optarg;
|
|
break;
|
|
case 'f':
|
|
set_filters = optarg;
|
|
break;
|
|
case ':':
|
|
fprintf(stderr, "Missing argument for option -%c\n", optopt);
|
|
exit(EXIT_FAILURE);
|
|
case '?':
|
|
fprintf(stderr, "Unrecognized option '-%c'\n", optopt);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
|
|
/* first, open a connection to the daemon */
|
|
if (!(conn = virAdmConnectOpen(NULL, 0)))
|
|
goto cleanup;
|
|
|
|
/* get the currently defined log outputs and filters */
|
|
if (virAdmConnectGetLoggingOutputs(conn, &get_outputs, 0) < 0 ||
|
|
virAdmConnectGetLoggingFilters(conn, &get_filters, 0) < 0)
|
|
goto cleanup;
|
|
|
|
fprintf(stdout,
|
|
"Current settings:\n"
|
|
" outputs: %s\n"
|
|
" filters: %s\n"
|
|
"\n",
|
|
get_outputs, get_filters ? get_filters : "None");
|
|
|
|
free(get_outputs);
|
|
free(get_filters);
|
|
|
|
/* no arguments were provided */
|
|
if (argc == 1) {
|
|
ret = 0;
|
|
goto cleanup;
|
|
}
|
|
|
|
/* now, try to change the redefine the current log output and filters */
|
|
if (virAdmConnectSetLoggingOutputs(conn, set_outputs, 0) < 0)
|
|
goto cleanup;
|
|
|
|
if (virAdmConnectSetLoggingFilters(conn, set_filters, 0) < 0)
|
|
goto cleanup;
|
|
|
|
/* get the currently defined log outputs and filters */
|
|
if (virAdmConnectGetLoggingOutputs(conn, &get_outputs, 0) < 0 ||
|
|
virAdmConnectGetLoggingFilters(conn, &get_filters, 0) < 0)
|
|
goto cleanup;
|
|
|
|
fprintf(stdout,
|
|
"New settings:\n"
|
|
" outputs: %s\n"
|
|
" filters: %s\n"
|
|
"\n",
|
|
get_outputs ? get_outputs : "Default",
|
|
get_filters ? get_filters : "None");
|
|
|
|
free(get_outputs);
|
|
free(get_filters);
|
|
|
|
ret = 0;
|
|
cleanup:
|
|
virAdmConnectClose(conn);
|
|
return ret;
|
|
}
|