[libvirt] [PATCH] Don't exist if the libvirtd config does not exist

From: "Daniel P. Berrange" <berrange@redhat.com> It is common for the $HOME/.libvirt/libvirtd.conf file to not exist. Treat this situation as non-fatal since we can carry on with our default settings just fine. * daemon/libvirtd.c: Treat ENOENT as non-fatal when loading config --- daemon/libvirtd.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 06d2077..fe0fa27 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1028,6 +1028,10 @@ daemonConfigLoad(struct daemonConfig *data, { virConfPtr conf; + if (access(filename, R_OK) == -1 && + errno == ENOENT) + return 0; + conf = virConfReadFile (filename, 0); if (!conf) return -1; -- 1.7.6

2011/7/8 Daniel P. Berrange <berrange@redhat.com>:
From: "Daniel P. Berrange" <berrange@redhat.com>
It is common for the $HOME/.libvirt/libvirtd.conf file to not exist. Treat this situation as non-fatal since we can carry on with our default settings just fine.
* daemon/libvirtd.c: Treat ENOENT as non-fatal when loading config --- daemon/libvirtd.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 06d2077..fe0fa27 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1028,6 +1028,10 @@ daemonConfigLoad(struct daemonConfig *data, { virConfPtr conf;
+ if (access(filename, R_OK) == -1 && + errno == ENOENT) + return 0; + conf = virConfReadFile (filename, 0); if (!conf) return -1;
s/Don't exist/Don't exit/ typo in subject. ACK, qemu:///session is working again. -- Matthias Bolte http://photron.blogspot.com

On 07/08/2011 08:28 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
It is common for the $HOME/.libvirt/libvirtd.conf file to not exist. Treat this situation as non-fatal since we can carry on with our default settings just fine.
* daemon/libvirtd.c: Treat ENOENT as non-fatal when loading config --- daemon/libvirtd.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 06d2077..fe0fa27 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1028,6 +1028,10 @@ daemonConfigLoad(struct daemonConfig *data, { virConfPtr conf;
+ if (access(filename, R_OK) == -1 && + errno == ENOENT) + return 0; +
This patch breaks 'make check' - tests/libvirtd-fail is now reporting failure. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 07/08/2011 10:07 AM, Eric Blake wrote:
On 07/08/2011 08:28 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
It is common for the $HOME/.libvirt/libvirtd.conf file to not exist. Treat this situation as non-fatal since we can carry on with our default settings just fine.
+ if (access(filename, R_OK) == -1 && + errno == ENOENT) + return 0; +
This patch breaks 'make check' - tests/libvirtd-fail is now reporting failure.
That test is checking that an explicit libvirtd --config=no-such-conf reports failure. I think the solution to this is to also pass around a bool stating whether the conf file name was generated by default (ENOENT is okay) or explicitly passed in (ENOENT must fail). -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Fixes test regression introduced in commit 8e2e4780. * daemon/libvirtd.c (daemonConfigLoad): Add argument. (main): Update caller. --- Pushing under the build-breaker rule, since it is detected by 'make check'. daemon/libvirtd.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index fe0fa27..a4198d9 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1024,11 +1024,13 @@ daemonConfigFree(struct daemonConfig *data) */ static int daemonConfigLoad(struct daemonConfig *data, - const char *filename) + const char *filename, + bool allow_missing) { virConfPtr conf; - if (access(filename, R_OK) == -1 && + if (allow_missing && + access(filename, R_OK) == -1 && errno == ENOENT) return 0; @@ -1282,6 +1284,7 @@ int main(int argc, char **argv) { int ipsock = 0; struct daemonConfig *config; bool privileged = geteuid() == 0 ? true : false; + bool implicit_conf = false; struct option opts[] = { { "verbose", no_argument, &verbose, 1}, @@ -1367,14 +1370,16 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); /* No explicit config, so try and find a default one */ - if (remote_config_file == NULL && - daemonConfigFilePath(privileged, - &remote_config_file) < 0) - exit(EXIT_FAILURE); + if (remote_config_file == NULL) { + implicit_conf = true; + if (daemonConfigFilePath(privileged, + &remote_config_file) < 0) + exit(EXIT_FAILURE); + } /* Read the config file if it exists*/ if (remote_config_file && - daemonConfigLoad(config, remote_config_file) < 0) + daemonConfigLoad(config, remote_config_file, implicit_conf) < 0) exit(EXIT_FAILURE); if (config->host_uuid && -- 1.7.4.4

On Fri, Jul 08, 2011 at 11:46:11AM -0600, Eric Blake wrote:
Fixes test regression introduced in commit 8e2e4780.
* daemon/libvirtd.c (daemonConfigLoad): Add argument. (main): Update caller. ---
Pushing under the build-breaker rule, since it is detected by 'make check'.
daemon/libvirtd.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
ACK, this looks like the correct fix. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Matthias Bolte