@@ -8,6 +8,7 @@
|
||||
#include "cgroup-setup.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "condition.h"
|
||||
#include "coredump-util.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "escape.h"
|
||||
#include "exec-util.h"
|
||||
@@ -119,6 +120,7 @@ DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, safe_atou64);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, mode_t, parse_mode);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, unsigned, safe_atou);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("x", int64_t, int64_t, safe_atoi64);
|
||||
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, coredump_filter_mask_from_string);
|
||||
|
||||
static int bus_append_string(sd_bus_message *m, const char *field, const char *eq) {
|
||||
int r;
|
||||
@@ -898,6 +900,9 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
|
||||
"OOMScoreAdjust"))
|
||||
return bus_append_safe_atoi(m, field, eq);
|
||||
|
||||
if (streq(field, "CoredumpFilter"))
|
||||
return bus_append_coredump_filter_mask_from_string(m, field, eq);
|
||||
|
||||
if (streq(field, "Nice"))
|
||||
return bus_append_parse_nice(m, field, eq);
|
||||
|
||||
|
||||
@@ -374,6 +374,12 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
|
||||
(void) format_timespan(timespan, sizeof(timespan), u, 0);
|
||||
bus_print_property_value(name, expected_value, value, timespan);
|
||||
|
||||
} else if (streq(name, "CoredumpFilter")) {
|
||||
char buf[STRLEN("0xFFFFFFFF")];
|
||||
|
||||
xsprintf(buf, "0x%"PRIx64, u);
|
||||
bus_print_property_value(name, expected_value, value, buf);
|
||||
|
||||
} else if (streq(name, "RestrictNamespaces")) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
const char *result;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "coredump-util.h"
|
||||
#include "extract-word.h"
|
||||
#include "fileio.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;
|
||||
}
|
||||
|
||||
int set_coredump_filter(uint64_t value) {
|
||||
char t[STRLEN("0xFFFFFFFF")];
|
||||
|
||||
sprintf(t, "0x%"PRIx64, value);
|
||||
|
||||
return write_string_file("/proc/self/coredump_filter", t,
|
||||
WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/* 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);
|
||||
|
||||
int set_coredump_filter(uint64_t value);
|
||||
@@ -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