mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
Merge Make signal.cc:signal_map an unordered map
This also includes renaming SIGTSTP "stp" to "tstp" while preserving backwards compatibility. Analogous to !1420. Signed-off-by: Ryan Lee <ryan.lee@canonical.com> MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1425 Approved-by: Georgia Garcia <georgia.garcia@canonical.com> Merged-by: John Johansen <john@jjmx.net>
This commit is contained in:
commit
74a67394ac
1 changed files with 14 additions and 13 deletions
|
@ -23,7 +23,7 @@
|
|||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "parser.h"
|
||||
#include "profile.h"
|
||||
|
@ -35,7 +35,7 @@
|
|||
#define MAXRT_SIG 32 /* Max RT above MINRT_SIG */
|
||||
|
||||
/* Signal names mapped to and internal ordering */
|
||||
static struct signal_map { const char *name; int num; } signal_map[] = {
|
||||
static unordered_map<string, int> signal_map = {
|
||||
{"hup", 1},
|
||||
{"int", 2},
|
||||
{"quit", 3},
|
||||
|
@ -55,7 +55,8 @@ static struct signal_map { const char *name; int num; } signal_map[] = {
|
|||
{"chld", 17},
|
||||
{"cont", 18},
|
||||
{"stop", 19},
|
||||
{"stp", 20},
|
||||
{"stp", 20}, // parser's previous name for SIGTSTP
|
||||
{"tstp", 20},
|
||||
{"ttin", 21},
|
||||
{"ttou", 22},
|
||||
{"urg", 23},
|
||||
|
@ -64,14 +65,12 @@ static struct signal_map { const char *name; int num; } signal_map[] = {
|
|||
{"vtalrm", 26},
|
||||
{"prof", 27},
|
||||
{"winch", 28},
|
||||
{"io", 29},
|
||||
{"io", 29}, // SIGIO == SIGPOLL
|
||||
{"poll", 29},
|
||||
{"pwr", 30},
|
||||
{"sys", 31},
|
||||
{"emt", 32},
|
||||
{"exists", 35},
|
||||
|
||||
/* terminate */
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
/* this table is ordered post sig_map[sig] mapping */
|
||||
|
@ -96,7 +95,7 @@ static const char *const sig_names[MAXMAPPED_SIG + 1] = {
|
|||
"chld",
|
||||
"cont",
|
||||
"stop",
|
||||
"stp",
|
||||
"tstp",
|
||||
"ttin",
|
||||
"ttou",
|
||||
"urg",
|
||||
|
@ -105,7 +104,7 @@ static const char *const sig_names[MAXMAPPED_SIG + 1] = {
|
|||
"vtalrm",
|
||||
"prof",
|
||||
"winch",
|
||||
"io",
|
||||
"io", // SIGIO == SIGPOLL
|
||||
"pwr",
|
||||
"sys",
|
||||
"emt",
|
||||
|
@ -130,12 +129,14 @@ int find_signal_mapping(const char *sig)
|
|||
return -1;
|
||||
return MINRT_SIG + n;
|
||||
} else {
|
||||
for (int i = 0; signal_map[i].name; i++) {
|
||||
if (strcmp(sig, signal_map[i].name) == 0)
|
||||
return signal_map[i].num;
|
||||
}
|
||||
}
|
||||
// Can't use string_view because that requires C++17
|
||||
auto sigmap = signal_map.find(string(sig));
|
||||
if (sigmap != signal_map.end()) {
|
||||
return sigmap->second;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void signal_rule::extract_sigs(struct value_list **list)
|
||||
|
|
Loading…
Add table
Reference in a new issue