Skip to contentSkip to conversation

curses: don't initialize curses when qemu is daemonized

PATCH Superseded Hitoshi Mitake 2 participants 7 messages Sep 12, 2012 – Sep 14, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 curses: don't initialize curses when qemu is daemonized

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

BTW, I didn't build and test on windows environment because I don't have it which is capable of qemu build. Could someone build and test it on windows?

Cc Andrzej Zaborowski <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Michael Roth <[email protected]>
---
 os-posix.c      |    5 +++++
 qemu-os-posix.h |    2 ++
 qemu-os-win32.h |    5 +++++
 ui/curses.c     |    4 ++++
 4 files changed, 16 insertions(+), 0 deletions(-)
os-posix.c +5 -0
index 79fa228..99c5343 100644
@@ -360,3 +360,8 @@ int qemu_create_pidfile(const char *filename)
     /* keep pidfile open & locked forever */
     return 0;
 }
+
+int is_daemonized(void)
+{
+    return daemonize;
+}
qemu-os-posix.h +2 -0
index 8e1149d..0b2b60a 100644
@@ -46,4 +46,6 @@ typedef struct timeval qemu_timeval;
 typedef struct timespec qemu_timespec;
 int qemu_utimens(const char *path, const qemu_timespec *times);
 
+int is_daemonized(void);
+
 #endif
qemu-os-win32.h +5 -0
index 753679b..08a6fa8 100644
@@ -86,4 +86,9 @@ typedef struct {
 } qemu_timeval;
 int qemu_gettimeofday(qemu_timeval *tp);
 
+static inline int is_daemonized(void)
+{
+    return 0;
+}
+
 #endif
ui/curses.c +4 -0
index c2be2c6..fc6ae8c 100644
@@ -335,6 +335,10 @@ static void curses_keyboard_setup(void)
 void curses_display_init(DisplayState *ds, int full_screen)
 {
     DisplayChangeListener *dcl;
+
+    if (is_daemonized())
+        return;
+
 #ifndef _WIN32
     if (!isatty(1)) {
         fprintf(stderr, "We need a terminal output\n");
Signature · 1 line
1.7.5.1
#1 lore raw
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

Stefan

#2 lore raw
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 8 lines
Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Yes. But -curses doesn't make sense when it is passed with -daemonize.

Quoted 4 lines

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

What is the same issue with SDL?

Thanks,
Hitoshi

#3 lore raw
Quoted 20 lines · Hitoshi Mitake
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 8 lines
Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Quoted 8 lines

Yes. But -curses doesn't make sense when it is passed with -daemonize.

Quoted 4 lines

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

What is the same issue with SDL?

You are right, it's fine to have an SDL display when QEMU is daemonized.

What bugged me about the patch is that ui/curses.c shouldn't know about daemonize. It would be cleaner to check this before initializing the curses display. An error could be printed instead of silently skipping curses initialization.

Can you move the check to vl.c:main() so it calls is_daemonized() and exits with an error message?

Stefan

#4 lore raw
Quoted 32 lines · Stefan Hajnoczi
Quoted 20 lines · Hitoshi Mitake
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 8 lines
Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Quoted 8 lines

Yes. But -curses doesn't make sense when it is passed with -daemonize.

Quoted 4 lines

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

What is the same issue with SDL?

You are right, it's fine to have an SDL display when QEMU is daemonized.

Quoted 8 lines

What bugged me about the patch is that ui/curses.c shouldn't know about daemonize. It would be cleaner to check this before initializing the curses display. An error could be printed instead of silently skipping curses initialization.

Can you move the check to vl.c:main() so it calls is_daemonized() and exits with an error message?

I agree with moving is_daemonized() to main(). I'll include this change in the next version.

But I'm worrying about the way of printing error message and exiting. This may break scripts which execute qemu with -daemonize && -curses.

So I like the way of skipping initialization of curses silently. It doesn't change the semantics of command line option of qemu.

I'd like to hear your comments.

Thanks,
Hitoshi

#5 lore raw
Quoted 45 lines · Hitoshi Mitake
Quoted 32 lines · Stefan Hajnoczi
Quoted 20 lines · Hitoshi Mitake
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 8 lines
Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Quoted 8 lines

Yes. But -curses doesn't make sense when it is passed with -daemonize.

Quoted 4 lines

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

What is the same issue with SDL?

You are right, it's fine to have an SDL display when QEMU is daemonized.

Quoted 8 lines

What bugged me about the patch is that ui/curses.c shouldn't know about daemonize. It would be cleaner to check this before initializing the curses display. An error could be printed instead of silently skipping curses initialization.

Can you move the check to vl.c:main() so it calls is_daemonized() and exits with an error message?

I agree with moving is_daemonized() to main(). I'll include this change in the next version.

Quoted 7 lines

But I'm worrying about the way of printing error message and exiting. This may break scripts which execute qemu with -daemonize && -curses.

So I like the way of skipping initialization of curses silently. It doesn't change the semantics of command line option of qemu.

I'd like to hear your comments.

It's a trade-off. Silently skipping curses initialization allows users with broken command-lines to continue, but it may confuse new users who try out this combination (they will not get a clear error message explaining what is going on).

I think it's better to be explicit because the risk of breaking existing user's setups is low. If you prefer the other way, that's fine by me too.

Stefan

#6 lore raw
Quoted 54 lines · Stefan Hajnoczi
Quoted 45 lines · Hitoshi Mitake
Quoted 32 lines · Stefan Hajnoczi
Quoted 20 lines · Hitoshi Mitake
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Hitoshi Mitake

Current qemu initializes curses even if -daemonize option is passed. This cause problem because shell prompt appears without calling endwin().

This patch adds new function, is_daemonized(), to OS dependent code. With this function, curses_display_init() can check that qemu is daemonized or not. If daemonized, curses_display_init() returns immediately.

Quoted 8 lines
Quoted 5 lines

Of course, -daemonize && -curses doesn't make sense. Users shouldn't pass the arguments at the same time. But the problem is very painful because Ctrl-C cannot be delivered to the terminal. So if this approach isn't acceptable, -daemonize && -curses combination should be treated as error.

I think it makes sense to explicitly check that -daemonize is used with -nographic | -vnc | -spice.

Quoted 8 lines

Yes. But -curses doesn't make sense when it is passed with -daemonize.

Quoted 4 lines

Making curses aware of daemonize seems strange and doesn't stop the same issue with SDL.

What is the same issue with SDL?

You are right, it's fine to have an SDL display when QEMU is daemonized.

Quoted 8 lines

What bugged me about the patch is that ui/curses.c shouldn't know about daemonize. It would be cleaner to check this before initializing the curses display. An error could be printed instead of silently skipping curses initialization.

Can you move the check to vl.c:main() so it calls is_daemonized() and exits with an error message?

I agree with moving is_daemonized() to main(). I'll include this change in the next version.

Quoted 7 lines

But I'm worrying about the way of printing error message and exiting. This may break scripts which execute qemu with -daemonize && -curses.

So I like the way of skipping initialization of curses silently. It doesn't change the semantics of command line option of qemu.

I'd like to hear your comments.

Quoted 9 lines

It's a trade-off. Silently skipping curses initialization allows users with broken command-lines to continue, but it may confuse new users who try out this combination (they will not get a clear error message explaining what is going on).

I think it's better to be explicit because the risk of breaking existing user's setups is low. If you prefer the other way, that's fine by me too.

I considered about the combination of -daemonize and -curses, and concluded that it is odd but not an invalid thing.
So I decided not to treat it as an error.

I'll send the v2 later.

Thanks,
Hitoshi