checkpatch: should not use signal except for SIG_DFL or SIG_IGN
PATCH 1/1 checkpatch: should not use signal except for SIG_DFL or SIG_IGN
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.
--- scripts/checkpatch.pl | 4 ++++ 1 file changed, 4 insertions(+)
scripts/checkpatch.pl +4 -0
@@ -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);
Signature · 1 line
2.13.0
Quoted 7 lines · Paolo Bonzini
Using signal to establish a signal handler is not portable; on SysV systems, the signal handler would be reset to
SIG_DFLafter delivery, while BSD preserves the signal handler. Daniel Berrange reported that (to complicate matters further) the signal system call has SysV behavior, but glibcsignal()actually calls the sigaction system call to provide BSD behavior.
Quoted 8 lines
However, using
signal()to set a signal's disposition toSIG_DFLorSIG_IGNis portable and is a relatively common occurrence in QEMU source code, so allow that.Signed-off-by Paolo Bonzini <[email protected]>--- scripts/checkpatch.pl | 4 ++++ 1 file changed, 4 insertions(+)
We currently only have 1 violation of this rule, and that is in the TCG test suite, so pretty harmless.
Quoted 18 lines
scripts/checkpatch.pl +4
-0@@ -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);Signature · 1 line
2.13.0
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Quoted 7 lines · Paolo Bonzini
Using signal to establish a signal handler is not portable; on SysV systems, the signal handler would be reset to
SIG_DFLafter delivery, while BSD preserves the signal handler. Daniel Berrange reported that (to complicate matters further) the signal system call has SysV behavior, but glibcsignal()actually calls the sigaction system call to provide BSD behavior.
Quoted 5 lines
However, using
signal()to set a signal's disposition toSIG_DFLorSIG_IGNis portable and is a relatively common occurrence in QEMU source code, so allow that.Signed-off-by Paolo Bonzini <[email protected]>
This looks good. Ignore the parallel version which I just sent :-(
Rich.
Quoted 21 lines
scripts/checkpatch.pl | 4 ++++ 1 file changed, 4 insertions(+)scripts/checkpatch.pl +4
-0@@ -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);Signature · 1 line
2.13.0
Signature · 5 lines
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