core: move CrashAction enum def to crash-handler.[ch]

This commit is contained in:
Mike Yuan
2025-03-08 19:27:55 +01:00
parent 568bafca50
commit fafb05451f
4 changed files with 22 additions and 21 deletions

View File

@@ -13,6 +13,7 @@
#include "raw-clone.h"
#include "rlimit-util.h"
#include "signal-util.h"
#include "string-table.h"
#include "terminal-util.h"
#include "virt.h"
@@ -188,3 +189,11 @@ void install_crash_handler(void) {
if (r < 0)
log_debug_errno(r, "I had trouble setting up the crash handler, ignoring: %m");
}
static const char* const crash_action_table[_CRASH_ACTION_MAX] = {
[CRASH_FREEZE] = "freeze",
[CRASH_REBOOT] = "reboot",
[CRASH_POWEROFF] = "poweroff",
};
DEFINE_STRING_TABLE_LOOKUP(crash_action, CrashAction);

View File

@@ -1,7 +1,20 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include "macro.h"
typedef enum CrashAction {
CRASH_FREEZE,
CRASH_REBOOT,
CRASH_POWEROFF,
_CRASH_ACTION_MAX,
_CRASH_ACTION_INVALID = -EINVAL,
} CrashAction;
const char* crash_action_to_string(CrashAction action);
CrashAction crash_action_from_string(const char *action);
_noreturn_ void freeze_or_exit_or_reboot(void);
void install_crash_handler(void);

View File

@@ -93,7 +93,6 @@
#include "special.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "strv.h"
#include "switch-root.h"
#include "sysctl-util.h"
@@ -168,14 +167,6 @@ static char **saved_env = NULL;
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
const struct rlimit *saved_rlimit_memlock);
static const char* const crash_action_table[_CRASH_ACTION_MAX] = {
[CRASH_FREEZE] = "freeze",
[CRASH_REBOOT] = "reboot",
[CRASH_POWEROFF] = "poweroff",
};
DEFINE_STRING_TABLE_LOOKUP(crash_action, CrashAction);
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_crash_action, crash_action, CrashAction, CRASH_FREEZE);
static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {

View File

@@ -1,20 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <stdbool.h>
typedef enum CrashAction {
CRASH_FREEZE,
CRASH_REBOOT,
CRASH_POWEROFF,
_CRASH_ACTION_MAX,
_CRASH_ACTION_INVALID = -EINVAL,
} CrashAction;
const char* crash_action_to_string(CrashAction action);
CrashAction crash_action_from_string(const char *action);
extern bool arg_dump_core;
extern int arg_crash_chvt;
extern bool arg_crash_shell;