[libvirt] [PATCH] admin: Throw a system error when 'open' fails on user-provided output

Erik Skultety posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/bd847bb382ccfe98c3be24ba8291cf57318ff267.1490948957.git.eskultet@redhat.com
src/util/virlog.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt] [PATCH] admin: Throw a system error when 'open' fails on user-provided output
Posted by Erik Skultety 7 years ago
There was an unhandled 'open' call which resulted in:

"error: Library function returned error but did not set virError"

Even if this happens during the daemon's start when we still don't have
any set of outputs defined yet, we can safely report an error, since we
automatically fallback to stderr which is fine even for both
running as a daemonized process, since this happens before the daemon
forks into the background, and running as a systemd service, since
systemd re-directs std outputs to journald by default.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1436060

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---
 src/util/virlog.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index 7b584f8e37..7933e1a7a0 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -750,8 +750,10 @@ virLogNewOutputToFile(virLogPriority priority,
     virLogOutputPtr ret = NULL;
 
     fd = open(file, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
-    if (fd < 0)
+    if (fd < 0) {
+        virReportSystemError(errno, _("failed to open %s"), file);
         return NULL;
+    }
 
     if (!(ret = virLogOutputNew(virLogOutputToFd, virLogCloseFd,
                                 (void *)(intptr_t)fd,
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] admin: Throw a system error when 'open' fails on user-provided output
Posted by Jiri Denemark 7 years ago
On Fri, Mar 31, 2017 at 10:29:25 +0200, Erik Skultety wrote:
> There was an unhandled 'open' call which resulted in:
> 
> "error: Library function returned error but did not set virError"
> 
> Even if this happens during the daemon's start when we still don't have
> any set of outputs defined yet, we can safely report an error, since we
> automatically fallback to stderr which is fine even for both
> running as a daemonized process, since this happens before the daemon
> forks into the background, and running as a systemd service, since
> systemd re-directs std outputs to journald by default.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1436060
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
>  src/util/virlog.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virlog.c b/src/util/virlog.c
> index 7b584f8e37..7933e1a7a0 100644
> --- a/src/util/virlog.c
> +++ b/src/util/virlog.c
> @@ -750,8 +750,10 @@ virLogNewOutputToFile(virLogPriority priority,
>      virLogOutputPtr ret = NULL;
>  
>      fd = open(file, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
> -    if (fd < 0)
> +    if (fd < 0) {
> +        virReportSystemError(errno, _("failed to open %s"), file);
>          return NULL;
> +    }
>  
>      if (!(ret = virLogOutputNew(virLogOutputToFd, virLogCloseFd,
>                                  (void *)(intptr_t)fd,

ACK and safe for freeze.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] admin: Throw a system error when 'open' fails on user-provided output
Posted by Erik Skultety 7 years ago
> ACK and safe for freeze.
>
> Jirka

Thanks, I pushed the patch.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list