]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
checkpatch: should not use signal except for SIG_DFL or SIG_IGN
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 4 Jul 2017 09:26:37 +0000 (11:26 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 4 Jul 2017 12:39:28 +0000 (14:39 +0200)
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.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
scripts/checkpatch.pl

index 45027b92816a557e3e3b76842f5a420a73b23494..73efc927a905cec4f060f5ba292a32f5152dbe37 100755 (executable)
@@ -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);