Use sigwait instead og sigwaitinfo.
PATCH 1/1 Use sigwait instead og sigwaitinfo.
Fix compilation failure on Darwin.
--- compatfd.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
compatfd.c +2 -2
@@ -33,9 +33,9 @@ static void *sigwait_compat(void *opaque)sigprocmask (SIG_BLOCK , &all,NULL ); do { - siginfo_t siginfo; + int sig; - err = sigwaitinfo(&info->mask, &siginfo); + err = sigwait(&info->mask, &sig); if (err == -1 && errno == EINTR) { err = 0; continue;
Signature · 1 line
1.7.3.GIT
compatfd.c static void *sigwait_compat(void *opaque)
Quoted 5 lines · Tristan Gingold
compatfd.c +2
-2-siginfo_t siginfo; +int sig; - err =sigwaitinfo (&info->mask,&siginfo); + err =sigwait (&info->mask,&sig);
This is doable but the patch is wrong, after sigwaitinfo "err" is the signal number, so you should replace
memcpy(buffer, &err, sizeof(err));
further down with
memcpy(buffer, &sig, sizeof(sig));
Paolo
PATCH 1/1 Use sigwait instead of sigwaitinfo.
In reply to Tristan GingoldFix compilation failure on Darwin.
--- compatfd.c | 36 ++++++++++++++++++------------------ 1 files changed, 18 insertions(+), 18 deletions(-)
compatfd.c +18 -18
@@ -26,45 +26,45 @@ struct sigfd_compat_infostatic void *sigwait_compat (void *opaque) {struct sigfd_compat_info *info = opaque; -int err;sigset_t all;sigfillset (&all);sigprocmask (SIG_BLOCK , &all,NULL ); -do { -siginfo_t siginfo; +while (1 ) { +int sig; +int err; - err =sigwaitinfo (&info->mask, &siginfo); -if (err ==-1 && errno ==EINTR ) { - err =0 ; -continue ; - } - -if (err >0 ) { -char buffer[128 ]; + err =sigwait (&info->mask, &sig); +if (err !=0 ) { +if (errno ==EINTR ) { +continue ; + }else { +return NULL ; + } + }else { +struct qemu_signalfd_siginfo buffer;size_t offset =0 ; -memcpy (buffer, &err,sizeof (err)); +memset (&buffer,0 ,sizeof (buffer)); + buffer.ssi_signo = sig; +while (offset <sizeof (buffer)) {ssize_t len; - len =write (info->fd, buffer + offset, + len =write (info->fd, (char *)&buffer + offset,sizeof (buffer) - offset);if (len ==-1 && errno ==EINTR )continue ;if (len <=0 ) { - err =-1 ; -break ; +return NULL ; } offset += len; } } - }while (err >=0 ); - -return NULL ; + } }static int qemu_signalfd_compat (const sigset_t *mask)
Signature · 1 line
1.7.3.GIT
[Qemu-devel] Re: [PATCH] Use sigwait instead of sigwaitinfo.
Quoted 65 lines · Tristan Gingold
Fix compilation failure on Darwin.
Signed-off-by Tristan Gingold<[email protected]>--- compatfd.c | 36 ++++++++++++++++++------------------ 1 files changed, 18 insertions(+), 18 deletions(-)compatfd.c +17
-15@@ -26,45 +26,45 @@ struct sigfd_compat_infostatic void *sigwait_compat (void *opaque) {struct sigfd_compat_info *info = opaque; -int err;sigset_t all;sigfillset (&all);sigprocmask (SIG_BLOCK ,&all,NULL ); - do { - siginfo_t siginfo; +while (1 ) { +int sig; +int err; - err = sigwaitinfo(&info->mask,&siginfo); - if (err == -1&& errno == EINTR) { - err = 0; - continue; - } - - if (err> 0) { - char buffer[128]; + err =sigwait (&info->mask,&sig); +if (err !=0 ) { +if (errno ==EINTR ) { +continue ; + }else { +return NULL ; + } + }else { +struct qemu_signalfd_siginfo buffer;size_t offset =0 ; - memcpy(buffer,&err, sizeof(err)); +memset (&buffer,0 ,sizeof (buffer)); + buffer.ssi_signo = sig; +while (offset<sizeof (buffer)) {ssize_t len; - len = write(info->fd, buffer + offset, + len =write (info->fd, (char *)&buffer + offset,sizeof (buffer) - offset);if (len ==-1 && errno ==EINTR )continue ;if (len<=0 ) { - err = -1; - break; +return NULL ; }
compatfd.c struct sigfd_compat_info · line 70
Quoted 10 lines
compatfd.c +1
-3offset += len; } } - }while (err>=0 ); - -return NULL ; + } }static int qemu_signalfd_compat (const sigset_t *mask)
Looks good.
Paolo
[Qemu-devel] Re: [PATCH] Use sigwait instead of sigwaitinfo.
In reply to Tristan GingoldQuoted 53 lines · Tristan Gingold
Fix compilation failure on Darwin.
Signed-off-by Tristan Gingold <[email protected]>--- compatfd.c | 36 ++++++++++++++++++------------------ 1 files changed, 18 insertions(+), 18 deletions(-)compatfd.c +15
-12@@ -26,45 +26,45 @@ struct sigfd_compat_infostatic void *sigwait_compat (void *opaque) {struct sigfd_compat_info *info = opaque; -int err;sigset_t all;sigfillset (&all);sigprocmask (SIG_BLOCK , &all,NULL ); - do { - siginfo_t siginfo; +while (1 ) { +int sig; +int err; - err = sigwaitinfo(&info->mask, &siginfo); - if (err == -1 && errno == EINTR) { - err = 0; - continue; - } - - if (err > 0) { - char buffer[128]; + err =sigwait (&info->mask, &sig); +if (err !=0 ) { +if (errno ==EINTR ) { +continue ; + }else { +return NULL ; + } + }else { +struct qemu_signalfd_siginfo buffer;size_t offset =0 ; - memcpy(buffer, &err, sizeof(err)); +memset (&buffer,0 ,sizeof (buffer)); + buffer.ssi_signo = sig; +while (offset <sizeof (buffer)) {ssize_t len;
compatfd.c struct sigfd_compat_info · line 61
Quoted 10 lines
compatfd.c +2
-3- len =write (info->fd, buffer + offset, + len =write (info->fd, (char *)&buffer + offset,sizeof (buffer) - offset);if (len ==-1 && errno ==EINTR )continue ;if (len <=0 ) { - err =-1 ; -break ; +return NULL ;
This and the above handling of sigwait return codes changes the error handling strategy. So far we silently skipped errors, now we silently terminate the compatfd thread. I think none of both approaches is good.
Failing sigwait is likely a reason to bail out, but loudly, writing some error message to the console and triggering a shutdown of qemu.
An overflow of the compatfd pipe to the main thread may be due to some very unfortunate overload scenario. Not sure if that qualifies for a thread termination (definitely not for a silent one).
Error handling should probably be adjusted independently of this darwin build fix.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
[Qemu-devel] Re: [PATCH] Use sigwait instead of sigwaitinfo.
Quoted 3 lines · Jan Kiszka
This and the above handling of sigwait return codes changes the error handling strategy.
Did it ? I don't think so.
Quoted 2 lines
So far we silently skipped errors, now we silently
terminate the compatfd thread. I think none of both approaches is good.
I think that both silently terminate the compatfd. The previous code is:
do {
siginfo_t siginfo; err = sigwaitinfo(&info->mask, &siginfo);
if (err == -1 && errno == EINTR) {
err = 0;
continue;
}
if (err > 0) {
char buffer[128];
size_t offset = 0;
memcpy(buffer, &err, sizeof(err));
while (offset < sizeof(buffer)) {
ssize_t len;
len = write(info->fd, buffer + offset,
sizeof(buffer) - offset);
if (len == -1 && errno == EINTR)
continue;
if (len <= 0) {
err = -1;
break;
}
offset += len;
}
}
} while (err >= 0);So in case of any error, err is set to a negative value which exits the thread.
Quoted 2 lines
Failing sigwait is likely a reason to bail out, but loudly, writing some error message to the console and triggering a shutdown of qemu.
I agree with that.
Quoted 3 lines
An overflow of the compatfd pipe to the main thread may be due to some very unfortunate overload scenario. Not sure if that qualifies for a thread termination (definitely not for a silent one).
What do you mean by overflow ? Unless I am wrong, the fd is not non-blocking, write will block.
Quoted 2 lines
Error handling should probably be adjusted independently of this darwin build fix.
I agree too.
Tristan.
[Qemu-devel] Re: [PATCH] Use sigwait instead of sigwaitinfo.
Quoted 45 lines · Tristan Gingold
Quoted 3 lines · Jan Kiszka
This and the above handling of sigwait return codes changes the error handling strategy.
Did it ? I don't think so.
Quoted 2 lines
So far we silently skipped errors, now we silently
terminate the compatfd thread. I think none of both approaches is good.I think that both silently terminate the compatfd. The previous code is:
do { siginfo_t siginfo;err = sigwaitinfo(&info->mask, &siginfo); if (err == -1 && errno == EINTR) { err = 0; continue; } if (err > 0) { char buffer[128]; size_t offset = 0; memcpy(buffer, &err, sizeof(err)); while (offset < sizeof(buffer)) { ssize_t len; len = write(info->fd, buffer + offset, sizeof(buffer) - offset); if (len == -1 && errno == EINTR) continue; if (len <= 0) { err = -1; break; } offset += len; } } } while (err >= 0);
Quoted 1 line
So in case of any error, err is set to a negative value which exits the thread.
Ah, sorry, oversaw that. In that case the patch is fine as it does not change the existing behavior.
Quoted 11 lines
Quoted 3 lines
Failing sigwait is likely a reason to bail out, but loudly, writing some error message to the console and triggering a shutdown of qemu.
I agree with that.
Quoted 3 lines
An overflow of the compatfd pipe to the main thread may be due to some very unfortunate overload scenario. Not sure if that qualifies for a thread termination (definitely not for a silent one).
What do you mean by overflow ? Unless I am wrong, the fd is not non-blocking, write will block.
True. So any error returned here is a real one.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH] Use sigwait instead of sigwaitinfo.
In reply to Tristan GingoldQuoted 1 line · Tristan Gingold
Fix compilation failure on Darwin.
Also OpenBSD needs this patch.
Blue Swirl
AppliedRe: [Qemu-devel] [PATCH] Use sigwait instead of sigwaitinfo.
In reply to Tristan GingoldThanks, applied.
Quoted 80 lines · Tristan Gingold
Fix compilation failure on Darwin.
Signed-off-by Tristan Gingold <[email protected]>---
compatfd.c | 36 ++++++++++++++++++------------------1 files changed, 18 insertions(+), 18 deletions(-)compatfd.c +18
-19@@ -26,45 +26,45 @@ struct sigfd_compat_info static void *sigwait_compat(void *opaque) { struct sigfd_compat_info *info = opaque; - int err; sigset_t all; sigfillset(&all); sigprocmask(SIG_BLOCK, &all, NULL); - do { - siginfo_t siginfo; + while (1) { + int sig; + int err; - err = sigwaitinfo(&info->mask, &siginfo); - if (err == -1 && errno == EINTR) { - err = 0; - continue; - } - - if (err > 0) { - char buffer[128]; + err = sigwait(&info->mask, &sig); + if (err != 0) { + if (errno == EINTR) { + continue; + } else { + return NULL; + } + } else { + struct qemu_signalfd_siginfo buffer; size_t offset = 0; - memcpy(buffer, &err, sizeof(err)); + memset(&buffer, 0, sizeof(buffer)); + buffer.ssi_signo = sig; + while (offset < sizeof(buffer)) { ssize_t len; - len = write(info->fd, buffer + offset, + len = write(info->fd, (char *)&buffer + offset, sizeof(buffer) - offset); if (len == -1 && errno == EINTR) continue; if (len <= 0) { - err = -1; - break; + return NULL; } offset += len; } } - } while (err >= 0); - - return NULL; + } } static int qemu_signalfd_compat(const sigset_t *mask) --1.7.3.GIT