Commit d5de4546 authored by Arun Chandrasekaran's avatar Arun Chandrasekaran

pgrep: use sigqueue to pass value with the signal.

Based on the command line option, use 'sigqueue'
instead of 'kill' to pass the integer value with
the signal.
parent 5043d395
Pipeline #5059870 (#) failed with stage
in 2 minutes and 53 seconds
......@@ -158,6 +158,18 @@ which namespaces to match.
Match only the provided namespaces. Available namespaces:
ipc, mnt, net, pid, user,uts.
.TP
\fB\-q\fR, \fB\-\-queue \fIvalue\fP
Use
.BR sigqueue(2)
rather than
.BR kill(2)
and the value 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.
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.TP
......
......@@ -35,6 +35,7 @@
#include <regex.h>
#include <errno.h>
#include <getopt.h>
#include <stdbool.h>
/* EXIT_SUCCESS is 0 */
/* EXIT_FAILURE is 1 */
......@@ -92,6 +93,8 @@ static int opt_case = 0;
static int opt_echo = 0;
static int opt_threads = 0;
static pid_t opt_ns_pid = 0;
static bool use_sigqueue = false;
static union sigval sigval = {0};
static const char *opt_delim = "\n";
static struct el *opt_pgrp = NULL;
......@@ -148,6 +151,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
fputs(_(" --nslist <ns,...> list which namespaces will be considered for\n"
" the --ns option.\n"
" Available namespaces: ipc, mnt, net, pid, user, uts\n"), fp);
fputs(_(" -q, --queue <value> integer value to be sent with the signal\n"), fp);
fputs(USAGE_SEPARATOR, fp);
fputs(USAGE_HELP, fp);
fputs(USAGE_VERSION, fp);
......@@ -652,6 +656,7 @@ static void parse_opts (int argc, char **argv)
{"echo", no_argument, NULL, 'e'},
{"ns", required_argument, NULL, NS_OPTION},
{"nslist", required_argument, NULL, NSLIST_OPTION},
{"queue", required_argument, NULL, 'q'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
......@@ -670,7 +675,7 @@ static void parse_opts (int argc, char **argv)
strcat (opts, "lad:vw");
}
strcat (opts, "LF:cfinoxP:g:s:u:U:G:t:?Vh");
strcat (opts, "LF:cfinoxP:g:s:u:U:G:t:?Vhq:");
while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != -1) {
switch (opt) {
......@@ -809,6 +814,10 @@ static void parse_opts (int argc, char **argv)
if (opt_nslist == NULL)
usage ('?');
break;
case 'q':
sigval.sival_int = atoi(optarg);
use_sigqueue = true;
break;
case 'h':
case '?':
usage (opt);
......@@ -848,6 +857,13 @@ static void parse_opts (int argc, char **argv)
program_invocation_short_name);
}
inline static int execute_kill(pid_t pid, int sig_num)
{
if (use_sigqueue)
return sigqueue(pid, sig_num, sigval);
else
return kill(pid, sig_num);
}
int main (int argc, char **argv)
{
......@@ -868,7 +884,7 @@ int main (int argc, char **argv)
if (i_am_pkill) {
int i;
for (i = 0; i < num; i++) {
if (kill (procs[i].num, opt_signal) != -1) {
if (execute_kill (procs[i].num, opt_signal) != -1) {
if (opt_echo)
printf(_("%s killed (pid %lu)\n"), procs[i].str, procs[i].num);
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment