]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
kill: add -q sigval to use sigqueue(2)
authorKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2011 16:15:40 +0000 (17:15 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2011 16:15:40 +0000 (17:15 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
misc-utils/Makefile.am
misc-utils/kill.1
misc-utils/kill.c

index 7b5ffff1861a39b52891a18a22bc61b049ab3a2c..93ff0699e34438f7869e3d44178f8d342fc49766 100644 (file)
@@ -195,6 +195,7 @@ AC_CHECK_FUNCS(
        getdtablesize \
        getexecname \
        getrlimit \
+       sigqueue \
        srandom \
        setresgid \
        setresuid \
index 3bae648602f72afe7ceb00be228321f81e281fb1..f58831765984b46adabaa1cef8cfb288025ea4c4 100644 (file)
@@ -120,7 +120,7 @@ endif
 
 if BUILD_KILL
 bin_PROGRAMS += kill
-kill_SOURCES = kill.c procs.c kill.h
+kill_SOURCES = kill.c procs.c kill.h $(top_srcdir)/lib/strutils.c
 dist_man_MANS += kill.1
 endif
 
index 4591f44087955005829212fa1fa305b4d9730085..fad706ab51a700926cc3f6c16641a42a63385807 100644 (file)
@@ -8,6 +8,8 @@ kill \- terminate a process
 .B kill
 .RB [ \-s
 .IR signal  | \fB\-p\fP ]
+.RB [ \-q
+.IR sigval ]
 .RN [ \-a ]
 .RB [ \-\- ]
 .IR pid ...
@@ -84,6 +86,17 @@ Specify that
 .B kill
 should only print the process id (pid)
 of the named processes, and not send any signals.
+.TP
+.BI \-q " sigval"
+Use
+.BR sigqueue (2)
+rather than
+.BR kill (2)
+and the sigval argument is used to specify an integer to be sent with the
+signal.  If the receiving process has installed a handler for this signal using
+the SA_SIGINFO flag to
+.BR sigaction (2),
+then it can obtain this data via the si_value field of the siginfo_t structure.
 .SH "SEE ALSO"
 .BR bash (1),
 .BR tcsh (1),
index f2f4e3737bc5c7d47e9dce2f17a9f0d294c2b5af..ab0fb6a98d71539f9d0e363544c450bdd09ea93d 100644 (file)
@@ -53,6 +53,7 @@
 #include "c.h"
 #include "kill.h"
 #include "nls.h"
+#include "strutils.h"
 
 struct signv {
        char *name;
@@ -152,6 +153,11 @@ extern int *get_pids (char *, int);
 
 static char *progname;
 
+#ifdef HAVE_SIGQUEUE
+static int use_sigval;
+static union sigval sigdata;
+#endif
+
 int main (int argc, char *argv[])
 {
     int errors, numsig, pid;
@@ -231,6 +237,17 @@ int main (int argc, char *argv[])
            }
            continue;
        }
+       if (! strcmp (arg, "-q")) {
+           if (argc < 2)
+               return usage (1);
+           argc--, argv++;
+           arg = *argv;
+#ifdef HAVE_SIGQUEUE
+           sigdata.sival_int = strtol_or_err(arg, _("failed to parse sigval"));
+           use_sigval = 1;
+#endif
+           continue;
+       }
        /*  `arg' begins with a dash but is not a known option.
            so it's probably something like -HUP, or -1/-n
            try to deal with it.
@@ -403,11 +420,20 @@ int usage (int status)
 
 int kill_verbose (char *procname, int pid, int sig)
 {
+    int rc;
+
     if (sig < 0) {
        printf ("%d\n", pid);
        return 0;
     }
-    if (kill (pid, sig) < 0) {
+#ifdef HAVE_SIGQUEUE
+    if (use_sigval)
+       rc = sigqueue(pid, sig, sigdata);
+    else
+#endif
+       rc = kill (pid, sig);
+
+    if (rc < 0) {
        fprintf (stderr, "%s ", progname);
        perror (procname);
        return 1;