Add parser and printer for coredump filter mask
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "coredump-util.h"
|
||||
#include "extract-word.h"
|
||||
#include "string-table.h"
|
||||
|
||||
static const char *const coredump_filter_table[_COREDUMP_FILTER_MAX] = {
|
||||
[COREDUMP_FILTER_PRIVATE_ANONYMOUS] = "private-anonymous",
|
||||
[COREDUMP_FILTER_SHARED_ANONYMOUS] = "shared-anonymous",
|
||||
[COREDUMP_FILTER_PRIVATE_FILE_BACKED] = "private-file-backed",
|
||||
[COREDUMP_FILTER_SHARED_FILE_BACKED] = "shared-file-backed",
|
||||
[COREDUMP_FILTER_ELF_HEADERS] = "elf-headers",
|
||||
[COREDUMP_FILTER_PRIVATE_HUGE] = "private-huge",
|
||||
[COREDUMP_FILTER_SHARED_HUGE] = "shared-huge",
|
||||
[COREDUMP_FILTER_PRIVATE_DAX] = "private-dax",
|
||||
[COREDUMP_FILTER_SHARED_DAX] = "shared-dax",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(coredump_filter, CoredumpFilter);
|
||||
|
||||
int coredump_filter_mask_from_string(const char *s, uint64_t *ret) {
|
||||
uint64_t m = 0;
|
||||
|
||||
assert(s);
|
||||
assert(ret);
|
||||
|
||||
for (;;) {
|
||||
_cleanup_free_ char *n = NULL;
|
||||
CoredumpFilter v;
|
||||
int r;
|
||||
|
||||
r = extract_first_word(&s, &n, NULL, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
if (streq(n, "default")) {
|
||||
m |= COREDUMP_FILTER_MASK_DEFAULT;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (streq(n, "all")) {
|
||||
m = UINT64_MAX;
|
||||
continue;
|
||||
}
|
||||
|
||||
v = coredump_filter_from_string(n);
|
||||
if (v >= 0) {
|
||||
m |= 1u << v;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint64_t x;
|
||||
r = safe_atoux64(n, &x);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
m |= x;
|
||||
}
|
||||
|
||||
*ret = m;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum CoredumpFilter {
|
||||
COREDUMP_FILTER_PRIVATE_ANONYMOUS = 0,
|
||||
COREDUMP_FILTER_SHARED_ANONYMOUS,
|
||||
COREDUMP_FILTER_PRIVATE_FILE_BACKED,
|
||||
COREDUMP_FILTER_SHARED_FILE_BACKED,
|
||||
COREDUMP_FILTER_ELF_HEADERS,
|
||||
COREDUMP_FILTER_PRIVATE_HUGE,
|
||||
COREDUMP_FILTER_SHARED_HUGE,
|
||||
COREDUMP_FILTER_PRIVATE_DAX,
|
||||
COREDUMP_FILTER_SHARED_DAX,
|
||||
_COREDUMP_FILTER_MAX,
|
||||
_COREDUMP_FILTER_INVALID = -1,
|
||||
} CoredumpFilter;
|
||||
|
||||
#define COREDUMP_FILTER_MASK_DEFAULT (1u << COREDUMP_FILTER_PRIVATE_ANONYMOUS | \
|
||||
1u << COREDUMP_FILTER_SHARED_ANONYMOUS | \
|
||||
1u << COREDUMP_FILTER_ELF_HEADERS | \
|
||||
1u << COREDUMP_FILTER_PRIVATE_HUGE)
|
||||
|
||||
const char* coredump_filter_to_string(CoredumpFilter i) _const_;
|
||||
CoredumpFilter coredump_filter_from_string(const char *s) _pure_;
|
||||
int coredump_filter_mask_from_string(const char *s, uint64_t *ret);
|
||||
@@ -51,6 +51,8 @@ shared_sources = files('''
|
||||
condition.h
|
||||
conf-parser.c
|
||||
conf-parser.h
|
||||
coredump-util.c
|
||||
coredump-util.h
|
||||
cpu-set-util.c
|
||||
cpu-set-util.h
|
||||
crypt-util.c
|
||||
|
||||
Reference in New Issue
Block a user