* [Qemu-devel] [PATCH] checkpatch: Error if signal(2) is used non-portably.
@ 2017-07-04 9:38 Richard W.M. Jones
2017-07-04 9:41 ` Richard W.M. Jones
0 siblings, 1 reply; 2+ messages in thread
From: Richard W.M. Jones @ 2017-07-04 9:38 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, armbru, eblake, berrange
The only portable use for signal(2) is setting a signal to SIG_IGN or
SIG_DFL. Everything else is a portability minefield. This change
adds such a check to checkpatch. It gives an error like this:
ERROR: Use sigaction instead of signal, except when setting the handler to SIG_IGN or SIG_DFL
#39: FILE: qemu-nbd.c:585:
+ signal(SIGPIPE, foobar);
total: 1 errors, 0 warnings, 10 lines checked
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
scripts/checkpatch.pl | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 45027b9281..76a2a87b25 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2593,6 +2593,15 @@ sub process {
$line =~ /\b(?:$non_exit_glib_asserts)\(/) {
ERROR("Use g_assert or g_assert_not_reached\n". $herecurr);
}
+
+# signal(2) can only portably be used for SIG_IGN or SIG_DFL. For
+# everything else, sigaction should be used instead.
+ if ($line =~ /\bsignal\([^,]+, ([^,\)]+)/ &&
+ $1 !~ /^SIG_(IGN|DFL)$/) {
+ ERROR("Use sigaction instead of signal, ".
+ "except when setting the handler to ".
+ "SIG_IGN or SIG_DFL\n" . $herecurr);
+ }
}
# If we have no input at all, then there is nothing to report on
--
2.13.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] checkpatch: Error if signal(2) is used non-portably.
2017-07-04 9:38 [Qemu-devel] [PATCH] checkpatch: Error if signal(2) is used non-portably Richard W.M. Jones
@ 2017-07-04 9:41 ` Richard W.M. Jones
0 siblings, 0 replies; 2+ messages in thread
From: Richard W.M. Jones @ 2017-07-04 9:41 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, armbru
Ignore this, Paolo also sent a similar patch after we were discussing
this on IRC.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-04 9:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-04 9:38 [Qemu-devel] [PATCH] checkpatch: Error if signal(2) is used non-portably Richard W.M. Jones
2017-07-04 9:41 ` Richard W.M. Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).