disable sigcld handling before calling pclose()
PATCH 1/1 disable sigcld handling before calling pclose()
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.
I debug the qemu by adding some printf(), and find the function pclose() returns -1.
I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)
======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in pclose().
We should disable sigcld handling before calling pclose().
--- os-posix.c | 19 +++++++++++++++++++ qemu-os-posix.h | 2 ++ savevm.c | 2 ++ 3 files changed, 23 insertions(+), 0 deletions(-)
os-posix.c +19 -0
@@ -86,6 +86,25 @@ void os_setup_signal_handling(void)sigaction (SIGCHLD , &act,NULL ); } +void os_stop_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler =SIG_DFL ; +sigaction (SIGCHLD , &act,NULL ); +} + +void os_resume_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler = sigchld_handler; + act.sa_flags =SA_NOCLDSTOP ; +sigaction (SIGCHLD , &act,NULL ); +} +/* Find a likely location for support files using the location of the binary. For installed binaries this will be "$bindir/../share/qemu". When running from the build tree this will be "$bindir/../pc-bios". */
qemu-os-posix.h +2 -0
@@ -33,6 +33,8 @@ static inline void os_host_main_loop_wait(int *timeout)void os_set_line_buffering (void );void os_set_proc_name (const char *s);void os_setup_signal_handling (void ); +void os_stop_sigchld_handling (void ); +void os_resume_sigchld_handling (void );void os_daemonize (void );void os_setup_post (void );
savevm.c +2 -0
@@ -234,7 +234,9 @@ static int stdio_pclose(void *opaque) {QEMUFileStdio *s = opaque;int ret; +os_stop_sigchld_handling (); ret =pclose (s->stdio_file); +os_resume_sigchld_handling ();qemu_free (s);return ret; }
Signature · 1 line
1.7.1
At 2010-12-09 11:41, Wen Congyang Write:
Quoted 14 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)
Quoted 9 lines
======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().We should disable sigcld handling before calling
pclose().Signed-off-by Wen Congyang <[email protected]>
Ping :)
At 12/14/2010 05:23 PM, Wen Congyang Write:
Quoted 17 lines
At 2010-12-09 11:41, Wen Congyang Write:
Quoted 16 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)======
Quoted 10 lines
Quoted 7 lines
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().We should disable sigcld handling before calling
pclose().Signed-off-by Wen Congyang <[email protected]>Ping :)
Ping Again... :)
Am 20.12.2010 um 02:25 schrieb Wen Congyang:
Quoted 23 lines
At 12/14/2010 05:23 PM, Wen Congyang Write:
Quoted 22 lines
At 2010-12-09 11:41, Wen Congyang Write:
Quoted 21 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().We should disable sigcld handling before calling
pclose().
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Signed-off-by Wen Congyang <[email protected]>Ping :)
Ping Again... :)
os-posix.c part looks sane to me, but what about Win32? Wouldn't it need stub functions?
Andreas
At 12/20/2010 02:33 PM, Andreas Färber Write:
Quoted 29 lines
Am 20.12.2010 um 02:25 schrieb Wen Congyang:
Quoted 27 lines
At 12/14/2010 05:23 PM, Wen Congyang Write:
Quoted 26 lines
At 2010-12-09 11:41, Wen Congyang Write:
Quoted 25 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No childprocesses)
======We wait the child twice: one is in signal SIGCHLD handling and the other
one is inpclose().We should disable sigcld handling before calling
pclose().Signed-off-by Wen Congyang <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Ping :)
Ping Again... :)
os-posix.cpart looks sane to me, but what about Win32? Wouldn't it need stub functions?
I do not know whether there is same BUG on Windows.
I will add stub functions for Win32.
Quoted 3 lines
Andreas
PATCH v2 1/1 disable sigcld handling before calling pclose()
In reply to Andreas FärberWhen I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.
I debug the qemu by adding some printf(), and find the function pclose() returns -1.
I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)
======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in pclose().
We should disable sigcld handling before calling pclose().
v2:
- Add stub functions for Win32
--- os-posix.c | 19 +++++++++++++++++++ qemu-os-posix.h | 2 ++ qemu-os-win32.h | 2 ++ savevm.c | 2 ++ 4 files changed, 25 insertions(+), 0 deletions(-)
os-posix.c +19 -0
@@ -86,6 +86,25 @@ void os_setup_signal_handling(void)sigaction (SIGCHLD , &act,NULL ); } +void os_stop_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler =SIG_DFL ; +sigaction (SIGCHLD , &act,NULL ); +} + +void os_resume_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler = sigchld_handler; + act.sa_flags =SA_NOCLDSTOP ; +sigaction (SIGCHLD , &act,NULL ); +} +/* Find a likely location for support files using the location of the binary. For installed binaries this will be "$bindir/../share/qemu". When running from the build tree this will be "$bindir/../pc-bios". */
qemu-os-posix.h +2 -0
@@ -33,6 +33,8 @@ static inline void os_host_main_loop_wait(int *timeout)void os_set_line_buffering (void );void os_set_proc_name (const char *s);void os_setup_signal_handling (void ); +void os_stop_sigchld_handling (void ); +void os_resume_sigchld_handling (void );void os_daemonize (void );void os_setup_post (void );
qemu-os-win32.h +2 -0
@@ -43,6 +43,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);void os_host_main_loop_wait (int *timeout);static inline void os_setup_signal_handling (void ) {} +static inline void os_stop_sigchld_handling (void ) {} +static inline void os_resume_sigchld_handling (void ) {}static inline void os_daemonize (void ) {}static inline void os_setup_post (void ) {}void os_set_line_buffering (void );
savevm.c +2 -0
@@ -234,7 +234,9 @@ static int stdio_pclose(void *opaque) {QEMUFileStdio *s = opaque;int ret; +os_stop_sigchld_handling (); ret =pclose (s->stdio_file); +os_resume_sigchld_handling ();qemu_free (s);return ret; }
Signature · 1 line
1.7.1
At 12/21/2010 12:05 PM, Wen Congyang Write:
Quoted 19 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().
Quoted 7 lines
We should disable sigcld handling before calling
pclose().v2:
- Add stub functions for Win32Signed-off-by Wen Congyang <[email protected]>
Ping Again... :)
This is a bug fix.
Quoted 14 lines · Wen Congyang
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)
Quoted 6 lines
======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().We should disable sigcld handling before calling
pclose().
I wondered whether we need SIGCHLD handling at all. fork is called only from:
- xen_domain_watcher in hw/xen_domainbuild.c
- launch_script in net/tap.c
- SLIRP's fork_exec ("mini inetd")
For the first, the child will always "outlive" the parent. For the second, we do waitpid in the function. So SLIRP is the only real user of the SIGCHLD handler and in fact this:
suggests that the handler came from there (search for do_wait). Would anybody object to removing the support for Samba under SLIRP and all the resulting cruft?
Paolo
At 12/21/2010 12:05 PM, Wen Congyang Write:
Quoted 94 lines
When I use the command 'virsh save' to save the domain state, I receive the following error message:
operation failed: Migration unexpectedly failed.I debug the qemu by adding some
printf(), and find the functionpclose()returns -1.I use strace to trace qemu, the log is as the following:
======
close(17) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---wait4(-1, NULL, WNOHANG, NULL) = 22016 rt_sigreturn(0) = 0 wait4(22016, 0x7fff7f1034fc, 0, NULL) = -1 ECHILD (No child processes)======
We wait the child twice: one is in signal SIGCHLD handling and the other one is in
pclose().We should disable sigcld handling before calling
pclose().v2:
- Add stub functions for Win32Signed-off-by Wen Congyang <[email protected]>--- os-posix.c | 19 +++++++++++++++++++ qemu-os-posix.h | 2 ++ qemu-os-win32.h | 2 ++ savevm.c | 2 ++ 4 files changed, 25 insertions(+), 0 deletions(-)os-posix.c +19
-0@@ -86,6 +86,25 @@ void os_setup_signal_handling(void)sigaction (SIGCHLD , &act,NULL ); } +void os_stop_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler =SIG_DFL ; +sigaction (SIGCHLD , &act,NULL ); +} + +void os_resume_sigchld_handling (void ) +{ +struct sigaction act; + +memset (&act,0 ,sizeof (act)); + act.sa_handler = sigchld_handler; + act.sa_flags =SA_NOCLDSTOP ; +sigaction (SIGCHLD , &act,NULL ); +} +/* Find a likely location for support files using the location of the binary. For installed binaries this will be "$bindir/../share/qemu". When running from the build tree this will be "$bindir/../pc-bios". */ qemu-os-posix.h +2
-0@@ -33,6 +33,8 @@ static inline void os_host_main_loop_wait(int *timeout)void os_set_line_buffering (void );void os_set_proc_name (const char *s);void os_setup_signal_handling (void ); +void os_stop_sigchld_handling (void ); +void os_resume_sigchld_handling (void );void os_daemonize (void );void os_setup_post (void );qemu-os-win32.h +2
-0@@ -43,6 +43,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);void os_host_main_loop_wait (int *timeout);static inline void os_setup_signal_handling (void ) {} +static inline void os_stop_sigchld_handling (void ) {} +static inline void os_resume_sigchld_handling (void ) {}static inline void os_daemonize (void ) {}static inline void os_setup_post (void ) {}void os_set_line_buffering (void );savevm.c +0
-0
savevm.c static int stdio_pclose(void *opaque) · line 242
Quoted 9 lines
savevm.c +2
-0@@ -234,7 +234,9 @@ static int stdio_pclose(void *opaque) {QEMUFileStdio *s = opaque;int ret; +os_stop_sigchld_handling (); ret =pclose (s->stdio_file); +os_resume_sigchld_handling ();qemu_free (s);return ret; }
Ping Again... :)
This is a bug fix.
2 months has gone, but I do not receive any comment. Should we remove SIGCHLD handling as Paolo said?