[PATCH] event-test: Properly terminate strings printed from callbacks

Kristina Hanicova posted 1 patch 3 years, 2 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20210219130753.15266-1-khanicov@redhat.com
examples/c/misc/event-test.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] event-test: Properly terminate strings printed from callbacks
Posted by Kristina Hanicova 3 years, 2 months ago
Stdio was buffering strings in functions:
myDomainEventBlockJobCallback,
myDomainEventBlockThresholdCallback,
myDomainEventMemoryFailureCallback. It caused flushing the
printed strings from callbacks at the end of a run, not
gradually. The solution is to add \n at the end of each string.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
---
 examples/c/misc/event-test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c
index f164e825e1..76d4f3f6e8 100644
--- a/examples/c/misc/event-test.c
+++ b/examples/c/misc/event-test.c
@@ -938,7 +938,7 @@ myDomainEventBlockJobCallback(virConnectPtr conn G_GNUC_UNUSED,
     const char *eventName = opaque;
 
     printf("%s EVENT: Domain %s(%d) block job callback '%s' disk '%s', "
-           "type '%s' status '%s'",
+           "type '%s' status '%s'\n",
            __func__, virDomainGetName(dom), virDomainGetID(dom), eventName,
            disk, blockJobTypeToStr(type), blockJobStatusToStr(status));
     return 0;
@@ -956,7 +956,7 @@ myDomainEventBlockThresholdCallback(virConnectPtr conn G_GNUC_UNUSED,
 {
     /* Casts to uint64_t to work around mingw not knowing %lld */
     printf("%s EVENT: Domain %s(%d) block threshold callback dev '%s'(%s), "
-           "threshold: '%" PRIu64 "', excess: '%" PRIu64 "'",
+           "threshold: '%" PRIu64 "', excess: '%" PRIu64 "'\n",
            __func__, virDomainGetName(dom), virDomainGetID(dom),
            dev, NULLSTR(path), (uint64_t)threshold, (uint64_t)excess);
     return 0;
@@ -972,7 +972,7 @@ myDomainEventMemoryFailureCallback(virConnectPtr conn G_GNUC_UNUSED,
                                    void *opaque G_GNUC_UNUSED)
 {
     printf("%s EVENT: Domain %s(%d) memory failure: recipient '%d', "
-           "aciont '%d', flags '%d'", __func__, virDomainGetName(dom),
+           "aciont '%d', flags '%d'\n", __func__, virDomainGetName(dom),
            virDomainGetID(dom), recipient, action, flags);
     return 0;
 }
-- 
2.29.2

Re: [PATCH] event-test: Properly terminate strings printed from callbacks
Posted by Ján Tomko 3 years, 2 months ago
On a Friday in 2021, Kristina Hanicova wrote:
>Stdio was buffering strings in functions:
>myDomainEventBlockJobCallback,
>myDomainEventBlockThresholdCallback,
>myDomainEventMemoryFailureCallback. It caused flushing the
>printed strings from callbacks at the end of a run, not
>gradually. The solution is to add \n at the end of each string.
>
>Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
>---
> examples/c/misc/event-test.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>
and pushed.

Jano