Skip to contentSkip to conversation

qsd: Do not use error_report() before monitor_init

PATCH In review Hanna Reitz 3 participants 3 messages Jun 9, 2022 – Jun 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qsd: Do not use error_report() before monitor_init

error_report() only works once monitor_init_globals_core() has been called, which is not the case when parsing the --daemonize option. Use fprintf(stderr, ...) instead.

Fixes 2525edd85fec53e23fda98974a15e3b3c8957596 ("qsd: Add --daemonize")
---
 storage-daemon/qemu-storage-daemon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
storage-daemon/qemu-storage-daemon.c +5 -1
index c104817cdd..0890495c40 100644
@@ -286,7 +286,11 @@ static void process_options(int argc, char *argv[], bool pre_init_pass)
             }
         case OPTION_DAEMONIZE:
             if (os_set_daemonize(true) < 0) {
-                error_report("--daemonize not supported in this build");
+                /*
+                 * --daemonize is parsed before monitor_init_globals_core(), so
+                 * error_report() does not work yet
+                 */
+                fprintf(stderr, "--daemonize not supported in this build\n");
                 exit(EXIT_FAILURE);
             }
             break;
Signature · 1 line
2.35.3
Reviewed-by Philippe Mathieu-Daudé on v1 1/1
#1 lore raw
Quoted 9 lines · Hanna Reitz

error_report() only works once monitor_init_globals_core() has been called, which is not the case when parsing the --daemonize option. Use fprintf(stderr, ...) instead.

Fixes 2525edd85fec53e23fda98974a15e3b3c8957596 ("qsd: Add --daemonize")
---
  storage-daemon/qemu-storage-daemon.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
#2 lore raw
In reply to Hanna Reitz
Quoted 18 lines · Hanna Reitz

error_report() only works once monitor_init_globals_core() has been called, which is not the case when parsing the --daemonize option. Use fprintf(stderr, ...) instead.

Fixes 2525edd85fec53e23fda98974a15e3b3c8957596 ("qsd: Add --daemonize")
---
 storage-daemon/qemu-storage-daemon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
storage-daemon/qemu-storage-daemon.c +0 -0
index c104817cdd..0890495c40 100644
@@ -286,7 +286,11 @@ static void process_options(int argc, char *argv[], bool pre_init_pass)
             }
         case OPTION_DAEMONIZE:

storage-daemon/qemu-storage-daemon.c static void process_options(int argc, char *argv[], bool pre_init_pass) · line 296

Quoted 10 lines
storage-daemon/qemu-storage-daemon.c +5 -1
             if (os_set_daemonize(true) < 0) {
-                error_report("--daemonize not supported in this build");
+                /*
+                 * --daemonize is parsed before monitor_init_globals_core(), so
+                 * error_report() does not work yet
+                 */
+                fprintf(stderr, "--daemonize not supported in this build\n");
                 exit(EXIT_FAILURE);
             }
             break;

Is it worth making error_report() have code for "called in early startup before monitor was initialized" that falls back to "just print to stderr"? Having our standard error reporting function not be usable everywhere is kind of surprising...

-- PMM