-
Notifications
You must be signed in to change notification settings - Fork 1.2k
kill: add a feature decoding signal masks #3105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ah, I like this idea :-) What do you think about adding support for decoding the masks to the --list? It already supports conversion from signal number to signal name ( And
I can also imagine |
83d3ae7
to
a67a7d6
Compare
@karelzak Thank you for the comment. I updated the change:
Eventually, we will want to implement |
misc-utils/kill.c
Outdated
exit(EXIT_SUCCESS); | ||
} | ||
if (!strcmp(arg, "-L") || !strcmp(arg, "--table")) { | ||
print_all_signals(stdout, 1); | ||
exit(EXIT_SUCCESS); | ||
} | ||
if (!strcmp(arg, "-d") || !strcmp(arg, "--show-process-state")) { | ||
uint64_t pid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not pid_t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Fixed in locally.
misc-utils/kill.c
Outdated
FILE *fp; | ||
char buf[BUFSIZ]; | ||
|
||
const struct sigfield { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Fixed in locally.
|
||
if (strncmp(buf, key, keylen) == 0) { | ||
char *val = buf + keylen; | ||
uint64_t sigmask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't sigmasks int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least on x86_64, int looks too small.
[yamato@dev64]~/var/util-linux/util-linux% cat /tmp/foo.c
int main(void) {return sizeof(int);}
[yamato@dev64]~/var/util-linux/util-linux% gcc /tmp/foo.c
[yamato@dev64]~/var/util-linux/util-linux% ./a.out; echo $?
4
[yamato@dev64]~/var/util-linux/util-linux% ./kill -l 0xffffffffffffffff | cat -n | tail
55 RT21
56 RT22
57 RT23
58 RT24
59 RT25
60 RT26
61 RT27
62 RT28
63 RT29
64 RT30
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I looked at sigmask(3)
which is deprecated.
pthread_sigmask(3) proposes sigset_t
. But those are 128 bytes big on amd64 glibc and a structure to boot.
So a uint64_t
is probably the best to work with.
misc-utils/kill.c
Outdated
{ "ShdPnd:\t", "Pending (process)" }, | ||
{ "SigBlk:\t", "Blocked" }, | ||
{ "SigIgn:\t", "Ignored" }, | ||
{ "SigCgt:\t", "Caught" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's translate the strings:
N_("Caught")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in locally.
misc-utils/kill.c
Outdated
continue; | ||
} | ||
if (sigmask != 0) { | ||
printf("%s: ", sigfields[i].label); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf("%s: ", _(sigfields[i].label));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in locally.
misc-utils/kill.c
Outdated
fputs(_(" -L, --table list signal names and numbers\n"), out); | ||
fputs(_(" -r, --require-handler do not send signal if signal handler is not present\n"), out); | ||
fputs(_(" -d, --decode-process-state <pid>\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--show-process-state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in locally.
misc-utils/kill.c
Outdated
errx(EXIT_FAILURE, _("too many arguments")); | ||
arg = argv[1]; | ||
if (ul_strtou64(arg, &pid, 10) < 0) | ||
errx(EXIT_FAILURE, _("wrong pid specification: %s"), arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pid = strtou64_or_err(argv[1], _("invalid pid argument"));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change to pid_t
: strtopid_or_err()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know strtopid_or_err. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in locally.
-l/--list option is extended to work well with the output of ps command: $ ps s $$ UID PID PENDING BLOCKED IGNORED CAUGHT STAT TTY TIME COMMAND 1000 1588189 0000000000000000 0000000000010000 0000000000384004 000000004b813efb S pts/56 0:00 bash $ ./kill --list 0x000000004b813efb HUP INT ILL TRAP ABRT ... If you know the pid you are interested in, you can skip running ps comman with -d/--show-process-state option: $ ./kill --show-process-state $$ Blocked: INT Ignored: TERM TSTP TTIN TTOU Caught: HUP INT PIPE ALRM CHLD WINCH Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsns/filter test case failed on rpm-build:fedora-rawhide-ppc64le. Mysterious. I will record the failure in #2967. |
Added a test case. |
23ba951
to
ac801df
Compare
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
-d/--decode-mask option works well with the output of ps command:
If you know the pid you are interested in, you can skip running ps comman with -D/--decode-process-state option: