Skip to content

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

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

masatake
Copy link
Member

@masatake masatake commented Jul 1, 2024

-d/--decode-mask option works 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 --decode-mask 000000004b813efb
   HUP
   INT
   ILL
   TRAP
   ABRT
   ...

If you know the pid you are interested in, you can skip running ps comman with -D/--decode-process-state option:

   $ ./kill --decode-process-state $$
   SigPnd:
   ShdPnd:
   SigBlk:
	   CHLD
   SigIgn:
	   QUIT
	   TERM
	   TSTP
	   TTIN
	   TTOU
   SigCgt:
	   HUP
	   INT
	   ILL
	   TRAP
	   ABRT
	   BUS
	   FPE
	   USR1
           ...
  • add test cases

@karelzak
Copy link
Collaborator

karelzak commented Jul 1, 2024

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 (--list 9) and also supports masks prefixed by 0x seems like a native thing; kill --list 0x000000004b813efb.

And --show-process-state rather than --decode-process-state, and report it in more human-readable way

  • non-empty items only
  • use human-readable names for the masks (SigBlk --> Blocking)
  • not separate signals by \n
$ kill --show-process-state $$`
Blocking: CHLD
Ignoring: QUIT TERM TSTP TTIN TTOU
Catching: HUP INT ILL TRAP ABRT BUS FPE USR1

I can also imagine lssig listing all about signals from /proc :-)))

@masatake masatake force-pushed the kill--decode branch 2 times, most recently from 83d3ae7 to a67a7d6 Compare July 1, 2024 16:27
@masatake
Copy link
Member Author

masatake commented Jul 1, 2024

@karelzak Thank you for the comment. I updated the change:

       $ 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
       ...
       $ ./kill --show-process-state 1
       Blocked: HUP INT USR1 USR2 TERM CHLD WINCH PWR RT0 RT1 RT2 RT3 RT4 RT5 RT6 RT7 RT13 RT14 RT15 RT16 RT17 RT18 RT20 RT21 RT22 RT23 RT24 RT25 RT26 RT27 RT28 RT29 
       Ignored: PIPE 
       Caught: QUIT ILL ABRT BUS FPE SEGV       

I can also imagine lssig listing all about signals from /proc :-)))

Eventually, we will want to implement lsps with -o and -Q options.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pid_t?

Copy link
Member Author

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.

FILE *fp;
char buf[BUFSIZ];

const struct sigfield {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't sigmasks int?

Copy link
Member Author

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?

Copy link
Member

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.

{ "ShdPnd:\t", "Pending (process)" },
{ "SigBlk:\t", "Blocked" },
{ "SigIgn:\t", "Ignored" },
{ "SigCgt:\t", "Caught" },
Copy link
Collaborator

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")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in locally.

continue;
}
if (sigmask != 0) {
printf("%s: ", sigfields[i].label);
Copy link
Collaborator

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));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in locally.

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--show-process-state

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in locally.

errx(EXIT_FAILURE, _("too many arguments"));
arg = argv[1];
if (ul_strtou64(arg, &pid, 10) < 0)
errx(EXIT_FAILURE, _("wrong pid specification: %s"), arg);
Copy link
Collaborator

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"));

Copy link
Member

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()

Copy link
Member Author

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.

Copy link
Member Author

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>
@masatake
Copy link
Member Author

masatake commented Jul 3, 2024

lsns/filter test case failed on rpm-build:fedora-rawhide-ppc64le. Mysterious. I will record the failure in #2967.

@masatake masatake changed the title [RFC] kill: add a feature decoding signal masks kill: add a feature decoding signal masks Jul 7, 2024
@masatake masatake marked this pull request as ready for review July 7, 2024 18:01
@masatake
Copy link
Member Author

masatake commented Jul 7, 2024

Added a test case.

@masatake masatake force-pushed the kill--decode branch 4 times, most recently from 23ba951 to ac801df Compare July 7, 2024 20:48
@masatake masatake marked this pull request as draft July 8, 2024 05:44
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@masatake masatake marked this pull request as ready for review July 8, 2024 11:48
@karelzak karelzak merged commit 30603d6 into util-linux:master Jul 15, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants