mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 11:17:34 +00:00
LibC: Move getsignalbyname() helper from Userland/kill into LibC
This commit is contained in:
parent
a6b2598fba
commit
ad0295d033
3 changed files with 51 additions and 49 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -186,4 +187,53 @@ int sigsuspend(const sigset_t*)
|
||||||
dbgprintf("FIXME: Implement sigsuspend()\n");
|
dbgprintf("FIXME: Implement sigsuspend()\n");
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* signal_names[] = {
|
||||||
|
"INVAL",
|
||||||
|
"HUP",
|
||||||
|
"INT",
|
||||||
|
"QUIT",
|
||||||
|
"ILL",
|
||||||
|
"TRAP",
|
||||||
|
"ABRT",
|
||||||
|
"BUS",
|
||||||
|
"FPE",
|
||||||
|
"KILL",
|
||||||
|
"USR1",
|
||||||
|
"SEGV",
|
||||||
|
"USR2",
|
||||||
|
"PIPE",
|
||||||
|
"ALRM",
|
||||||
|
"TERM",
|
||||||
|
"STKFLT",
|
||||||
|
"CHLD",
|
||||||
|
"CONT",
|
||||||
|
"STOP",
|
||||||
|
"TSTP",
|
||||||
|
"TTIN",
|
||||||
|
"TTOU",
|
||||||
|
"URG",
|
||||||
|
"XCPU",
|
||||||
|
"XFSZ",
|
||||||
|
"VTALRM",
|
||||||
|
"PROF",
|
||||||
|
"WINCH",
|
||||||
|
"IO",
|
||||||
|
"INFO",
|
||||||
|
"SYS",
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(signal_names) == sizeof(const char*) * 32);
|
||||||
|
|
||||||
|
int getsignalbyname(const char* name)
|
||||||
|
{
|
||||||
|
ASSERT(name);
|
||||||
|
for (size_t i = 0; i < NSIG; ++i) {
|
||||||
|
auto* signal_name = signal_names[i];
|
||||||
|
if (!strcmp(signal_name, name))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
|
||||||
int sigpending(sigset_t*);
|
int sigpending(sigset_t*);
|
||||||
int sigsuspend(const sigset_t*);
|
int sigsuspend(const sigset_t*);
|
||||||
int raise(int sig);
|
int raise(int sig);
|
||||||
|
int getsignalbyname(const char*);
|
||||||
|
|
||||||
extern const char* sys_siglist[NSIG];
|
extern const char* sys_siglist[NSIG];
|
||||||
|
|
||||||
|
|
|
@ -39,55 +39,6 @@ static void print_usage_and_exit()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* signal_names[] = {
|
|
||||||
"INVAL",
|
|
||||||
"HUP",
|
|
||||||
"INT",
|
|
||||||
"QUIT",
|
|
||||||
"ILL",
|
|
||||||
"TRAP",
|
|
||||||
"ABRT",
|
|
||||||
"BUS",
|
|
||||||
"FPE",
|
|
||||||
"KILL",
|
|
||||||
"USR1",
|
|
||||||
"SEGV",
|
|
||||||
"USR2",
|
|
||||||
"PIPE",
|
|
||||||
"ALRM",
|
|
||||||
"TERM",
|
|
||||||
"STKFLT",
|
|
||||||
"CHLD",
|
|
||||||
"CONT",
|
|
||||||
"STOP",
|
|
||||||
"TSTP",
|
|
||||||
"TTIN",
|
|
||||||
"TTOU",
|
|
||||||
"URG",
|
|
||||||
"XCPU",
|
|
||||||
"XFSZ",
|
|
||||||
"VTALRM",
|
|
||||||
"PROF",
|
|
||||||
"WINCH",
|
|
||||||
"IO",
|
|
||||||
"INFO",
|
|
||||||
"SYS"
|
|
||||||
};
|
|
||||||
|
|
||||||
static_assert(sizeof(signal_names) == sizeof(const char*) * 32);
|
|
||||||
|
|
||||||
int getsignalbyname(const char* name)
|
|
||||||
{
|
|
||||||
ASSERT(name);
|
|
||||||
for (size_t i = 0; i < NSIG; ++i) {
|
|
||||||
auto* signal_name = signal_names[i];
|
|
||||||
if (!strcmp(signal_name, name))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (pledge("stdio proc", nullptr) < 0) {
|
if (pledge("stdio proc", nullptr) < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue