mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
shared: add exec-directory-util.ch
This commit is contained in:
@@ -3000,17 +3000,6 @@ static const char* const exec_preserve_mode_table[_EXEC_PRESERVE_MODE_MAX] = {
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(exec_preserve_mode, ExecPreserveMode, EXEC_PRESERVE_YES);
|
||||
|
||||
/* This table maps ExecDirectoryType to the setting it is configured with in the unit */
|
||||
static const char* const exec_directory_type_table[_EXEC_DIRECTORY_TYPE_MAX] = {
|
||||
[EXEC_DIRECTORY_RUNTIME] = "RuntimeDirectory",
|
||||
[EXEC_DIRECTORY_STATE] = "StateDirectory",
|
||||
[EXEC_DIRECTORY_CACHE] = "CacheDirectory",
|
||||
[EXEC_DIRECTORY_LOGS] = "LogsDirectory",
|
||||
[EXEC_DIRECTORY_CONFIGURATION] = "ConfigurationDirectory",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(exec_directory_type, ExecDirectoryType);
|
||||
|
||||
/* This table maps ExecDirectoryType to the symlink setting it is configured with in the unit */
|
||||
static const char* const exec_directory_type_symlink_table[_EXEC_DIRECTORY_TYPE_MAX] = {
|
||||
[EXEC_DIRECTORY_RUNTIME] = "RuntimeDirectorySymlink",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "cgroup-util.h"
|
||||
#include "core-forward.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "exec-directory-util.h"
|
||||
#include "exec-util.h"
|
||||
#include "list.h"
|
||||
#include "log-context.h"
|
||||
@@ -126,22 +127,19 @@ typedef struct ExecRuntime {
|
||||
int ephemeral_storage_socket[2];
|
||||
} ExecRuntime;
|
||||
|
||||
typedef enum ExecDirectoryType {
|
||||
EXEC_DIRECTORY_RUNTIME,
|
||||
EXEC_DIRECTORY_STATE,
|
||||
EXEC_DIRECTORY_CACHE,
|
||||
EXEC_DIRECTORY_LOGS,
|
||||
EXEC_DIRECTORY_CONFIGURATION,
|
||||
_EXEC_DIRECTORY_TYPE_MAX,
|
||||
_EXEC_DIRECTORY_TYPE_INVALID = -EINVAL,
|
||||
} ExecDirectoryType;
|
||||
|
||||
static inline bool EXEC_DIRECTORY_TYPE_SHALL_CHOWN(ExecDirectoryType t) {
|
||||
/* Returns true for the ExecDirectoryTypes that we shall chown()ing for the user to. We do this for
|
||||
* all of them, except for configuration */
|
||||
return t >= 0 && t < _EXEC_DIRECTORY_TYPE_MAX && t != EXEC_DIRECTORY_CONFIGURATION;
|
||||
}
|
||||
|
||||
typedef struct QuotaLimit {
|
||||
uint64_t quota_absolute; /* absolute quota in bytes; if UINT64_MAX relative quota configured, see below */
|
||||
uint32_t quota_scale; /* relative quota to backend size, scaled to 0…UINT32_MAX */
|
||||
bool quota_enforce;
|
||||
bool quota_accounting;
|
||||
} QuotaLimit;
|
||||
|
||||
typedef struct ExecDirectoryItem {
|
||||
char *path;
|
||||
char **symlinks;
|
||||
@@ -153,6 +151,7 @@ typedef struct ExecDirectory {
|
||||
mode_t mode;
|
||||
size_t n_items;
|
||||
ExecDirectoryItem *items;
|
||||
QuotaLimit exec_quota;
|
||||
} ExecDirectory;
|
||||
|
||||
typedef enum ExecCleanMask {
|
||||
@@ -581,9 +580,6 @@ ExecPreserveMode exec_preserve_mode_from_string(const char *s) _pure_;
|
||||
const char* exec_keyring_mode_to_string(ExecKeyringMode i) _const_;
|
||||
ExecKeyringMode exec_keyring_mode_from_string(const char *s) _pure_;
|
||||
|
||||
const char* exec_directory_type_to_string(ExecDirectoryType i) _const_;
|
||||
ExecDirectoryType exec_directory_type_from_string(const char *s) _pure_;
|
||||
|
||||
const char* exec_directory_type_symlink_to_string(ExecDirectoryType i) _const_;
|
||||
ExecDirectoryType exec_directory_type_symlink_from_string(const char *s) _pure_;
|
||||
|
||||
|
||||
15
src/shared/exec-directory-util.c
Normal file
15
src/shared/exec-directory-util.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "exec-directory-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
/* This table maps ExecDirectoryType to the setting it is configured with in the unit */
|
||||
static const char* const exec_directory_type_table[_EXEC_DIRECTORY_TYPE_MAX] = {
|
||||
[EXEC_DIRECTORY_RUNTIME] = "RuntimeDirectory",
|
||||
[EXEC_DIRECTORY_STATE] = "StateDirectory",
|
||||
[EXEC_DIRECTORY_CACHE] = "CacheDirectory",
|
||||
[EXEC_DIRECTORY_LOGS] = "LogsDirectory",
|
||||
[EXEC_DIRECTORY_CONFIGURATION] = "ConfigurationDirectory",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(exec_directory_type, ExecDirectoryType);
|
||||
19
src/shared/exec-directory-util.h
Normal file
19
src/shared/exec-directory-util.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "macro-fundamental.h"
|
||||
|
||||
typedef enum ExecDirectoryType {
|
||||
EXEC_DIRECTORY_RUNTIME,
|
||||
EXEC_DIRECTORY_STATE,
|
||||
EXEC_DIRECTORY_CACHE,
|
||||
EXEC_DIRECTORY_LOGS,
|
||||
EXEC_DIRECTORY_CONFIGURATION,
|
||||
_EXEC_DIRECTORY_TYPE_MAX,
|
||||
_EXEC_DIRECTORY_TYPE_INVALID = -EINVAL,
|
||||
} ExecDirectoryType;
|
||||
|
||||
const char* exec_directory_type_to_string(ExecDirectoryType i) _const_;
|
||||
ExecDirectoryType exec_directory_type_from_string(const char *s) _pure_;
|
||||
@@ -69,6 +69,7 @@ shared_sources = files(
|
||||
'elf-util.c',
|
||||
'enable-mempool.c',
|
||||
'ethtool-util.c',
|
||||
'exec-directory-util.c',
|
||||
'exec-util.c',
|
||||
'exit-status.c',
|
||||
'extension-util.c',
|
||||
|
||||
Reference in New Issue
Block a user