All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN
@ 2017-07-04  9:27 Paolo Bonzini
  2017-07-04  9:33 ` Daniel P. Berrange
  2017-07-04  9:40 ` Richard W.M. Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2017-07-04  9:27 UTC (permalink / raw)
  To: qemu-devel

Using signal to establish a signal handler is not portable; on
SysV systems, the signal handler would be reset to SIG_DFL after
delivery, while BSD preserves the signal handler.  Daniel Berrange
reported that (to complicate matters further) the signal system call
has SysV behavior, but glibc signal() actually calls the sigaction
system call to provide BSD behavior.

However, using signal() to set a signal's disposition to SIG_DFL
or SIG_IGN is portable and is a relatively common occurrence in
QEMU source code, so allow that.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/checkpatch.pl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 45027b9281..73efc927a9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2473,6 +2473,10 @@ sub process {
 		if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
 			ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);
 		}
+# recommend sigaction over signal for portability, when establishing a handler
+		if ($line =~ /\bsignal\s*\(/ && !($line =~ /SIG_(?:IGN|DFL)/)) {
+			ERROR("use sigaction to establish signal handlers; signal is not portable\n" . $herecurr);
+		}
 # check for module_init(), use category-specific init macros explicitly please
 		if ($line =~ /^module_init\s*\(/) {
 			ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN
  2017-07-04  9:27 [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN Paolo Bonzini
@ 2017-07-04  9:33 ` Daniel P. Berrange
  2017-07-04  9:40 ` Richard W.M. Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel P. Berrange @ 2017-07-04  9:33 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, Jul 04, 2017 at 11:27:04AM +0200, Paolo Bonzini wrote:
> Using signal to establish a signal handler is not portable; on
> SysV systems, the signal handler would be reset to SIG_DFL after
> delivery, while BSD preserves the signal handler.  Daniel Berrange
> reported that (to complicate matters further) the signal system call
> has SysV behavior, but glibc signal() actually calls the sigaction
> system call to provide BSD behavior.
> 
> However, using signal() to set a signal's disposition to SIG_DFL
> or SIG_IGN is portable and is a relatively common occurrence in
> QEMU source code, so allow that.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/checkpatch.pl | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>

We currently only have 1 violation of this rule, and that
is in the TCG test suite, so pretty harmless.

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 45027b9281..73efc927a9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2473,6 +2473,10 @@ sub process {
>  		if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
>  			ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);
>  		}
> +# recommend sigaction over signal for portability, when establishing a handler
> +		if ($line =~ /\bsignal\s*\(/ && !($line =~ /SIG_(?:IGN|DFL)/)) {
> +			ERROR("use sigaction to establish signal handlers; signal is not portable\n" . $herecurr);
> +		}
>  # check for module_init(), use category-specific init macros explicitly please
>  		if ($line =~ /^module_init\s*\(/) {
>  			ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
> -- 
> 2.13.0
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN
  2017-07-04  9:27 [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN Paolo Bonzini
  2017-07-04  9:33 ` Daniel P. Berrange
@ 2017-07-04  9:40 ` Richard W.M. Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Richard W.M. Jones @ 2017-07-04  9:40 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On Tue, Jul 04, 2017 at 11:27:04AM +0200, Paolo Bonzini wrote:
> Using signal to establish a signal handler is not portable; on
> SysV systems, the signal handler would be reset to SIG_DFL after
> delivery, while BSD preserves the signal handler.  Daniel Berrange
> reported that (to complicate matters further) the signal system call
> has SysV behavior, but glibc signal() actually calls the sigaction
> system call to provide BSD behavior.
> 
> However, using signal() to set a signal's disposition to SIG_DFL
> or SIG_IGN is portable and is a relatively common occurrence in
> QEMU source code, so allow that.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

This looks good.  Ignore the parallel version which I just sent :-(

  Reviewed-by: Richard W.M. Jones <rjones@redhat.com>

Rich.

>  scripts/checkpatch.pl | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 45027b9281..73efc927a9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2473,6 +2473,10 @@ sub process {
>  		if ($line =~ /\b(strto[^kd].*?)\s*\(/) {
>  			ERROR("consider using qemu_$1 in preference to $1\n" . $herecurr);
>  		}
> +# recommend sigaction over signal for portability, when establishing a handler
> +		if ($line =~ /\bsignal\s*\(/ && !($line =~ /SIG_(?:IGN|DFL)/)) {
> +			ERROR("use sigaction to establish signal handlers; signal is not portable\n" . $herecurr);
> +		}
>  # check for module_init(), use category-specific init macros explicitly please
>  		if ($line =~ /^module_init\s*\(/) {
>  			ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
> -- 
> 2.13.0
> 

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-04  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04  9:27 [Qemu-devel] [PATCH] checkpatch: should not use signal except for SIG_DFL or SIG_IGN Paolo Bonzini
2017-07-04  9:33 ` Daniel P. Berrange
2017-07-04  9:40 ` Richard W.M. Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.