Skip to content

Commit

Permalink
Userland: Make killall accept signal names as well
Browse files Browse the repository at this point in the history
Use getsignalbyname() to support killall -HUP foo, and such things.
  • Loading branch information
awesomekling committed Oct 29, 2020
1 parent ad0295d commit ffd1e48
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Userland/killall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <AK/String.h>
#include <LibCore/ProcessStatisticsReader.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -66,9 +67,19 @@ int main(int argc, char** argv)
if (argv[1][0] != '-')
print_usage_and_exit();

auto number = String(&argv[1][1]).to_uint();
Optional<unsigned> number;

if (isalpha(argv[1][1])) {
int value = getsignalbyname(&argv[1][1]);
if (value >= 0 && value < NSIG)
number = value;
}

if (!number.has_value())
number = String(&argv[1][1]).to_uint();

if (!number.has_value()) {
printf("'%s' is not a valid signal number\n", &argv[1][1]);
printf("'%s' is not a valid signal name or number\n", &argv[1][1]);
return 2;
}
signum = number.value();
Expand Down

0 comments on commit ffd1e48

Please sign in to comment.