initctl signal command parsing: done

This commit is contained in:
Jörgen Sigvardsson committed 2022-02-15 12:29:40 +01:00
1 parent 3c9053b055
commit 62da379472
6 files changed
+135 -37

No files matched your search

+28
View File
@@ -275,6 +275,34 @@ char *sig2str(int sig)
return signame;
}
/**
* str2sig - Translate signal name to the corresponding signal number.
* @sig: The name of the signal
*
* A signal can be a complete signal name such as "SIGHUP", or
* it can be the shortest unique name, such as "HUP" (no SIG prefix).
*/
int str2sig(char *sig)
{
int name_offset = 0;
size_t i;
/* if sig name starts with "SIG", then skip the first
* three characters. signames holds the names without
* the "SIG" prefix.
*/
if (strncasecmp(sig, "SIG", 3) == 0) {
name_offset = 3;
}
for (i = 1; i < NELEMS(signames); ++i) {
if (strcasecmp(&sig[name_offset], signames[i]) == 0)
return i;
}
return -1;
}
char *code2str(int code)
{
static char codename[20];