Create src/shared/unit-file.[ch] for unit-file related ops

So far we put such functinos in install.[ch], but that is tied too closely
to enable/disable. Let's start moving things to a place with a better name.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-07-04 15:46:16 +02:00
parent 47a0011186
commit 5cfa33e0bc
17 changed files with 76 additions and 54 deletions

View File

@ -23,6 +23,7 @@
#include "memory-util.h"
#include "missing_syscall.h"
#include "unit.h"
#include "strv.h"
#include "virt.h"
enum {

View File

@ -10,6 +10,7 @@
#include "log.h"
#include "selinux-access.h"
#include "string-util.h"
#include "strv.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, job_type, JobType);
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_state, job_state, JobState);

View File

@ -12,6 +12,7 @@
#include "dbus-util.h"
#include "dbus.h"
#include "fd-util.h"
#include "install.h"
#include "locale-util.h"
#include "log.h"
#include "path-util.h"

View File

@ -20,6 +20,7 @@
#include "socket-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
/* Takes a value generated randomly or by hashing and turns it into a UID in the right range */

View File

@ -46,6 +46,7 @@
#include "fs-util.h"
#include "hashmap.h"
#include "io-util.h"
#include "install.h"
#include "label.h"
#include "locale-setup.h"
#include "log.h"

View File

@ -6,9 +6,10 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "dbus-unit.h"
#include "strv.h"
#include "terminal-util.h"
#include "transaction.h"
#include "dbus-unit.h"
static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);

View File

@ -28,6 +28,7 @@
#include "fs-util.h"
#include "id128-util.h"
#include "io-util.h"
#include "install.h"
#include "load-dropin.h"
#include "load-fragment.h"
#include "log.h"

View File

@ -8,10 +8,9 @@
#include "bpf-program.h"
#include "condition.h"
#include "emergency-action.h"
#include "install.h"
#include "list.h"
#include "set.h"
#include "unit-name.h"
#include "unit-file.h"
#include "cgroup.h"
typedef struct UnitRef UnitRef;

View File

@ -8,6 +8,7 @@
#include "escape.h"
#include "log.h"
#include "path-lookup.h"
#include "strv.h"
static int environment_dirs(char ***ret) {
_cleanup_strv_free_ char **dirs = NULL;

View File

@ -10,6 +10,7 @@
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "install.h"
#include "io-util.h"
#include "locale-util.h"
#include "loop-util.h"

View File

@ -37,7 +37,7 @@
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "unit-name.h"
#include "unit-file.h"
#define UNIT_FILE_FOLLOW_SYMLINK_MAX 64
@ -98,25 +98,6 @@ static void presets_freep(Presets *p) {
p->n_rules = 0;
}
bool unit_type_may_alias(UnitType type) {
return IN_SET(type,
UNIT_SERVICE,
UNIT_SOCKET,
UNIT_TARGET,
UNIT_DEVICE,
UNIT_TIMER,
UNIT_PATH);
}
bool unit_type_may_template(UnitType type) {
return IN_SET(type,
UNIT_SERVICE,
UNIT_SOCKET,
UNIT_TARGET,
UNIT_TIMER,
UNIT_PATH);
}
static const char *const unit_file_type_table[_UNIT_FILE_TYPE_MAX] = {
[UNIT_FILE_TYPE_REGULAR] = "regular",
[UNIT_FILE_TYPE_SYMLINK] = "symlink",

View File

@ -1,8 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
typedef enum UnitFileScope UnitFileScope;
typedef enum UnitFileState UnitFileState;
typedef enum UnitFilePresetMode UnitFilePresetMode;
typedef enum UnitFileChangeType UnitFileChangeType;
typedef enum UnitFileFlags UnitFileFlags;
@ -19,31 +17,6 @@ typedef struct UnitFileInstallInfo UnitFileInstallInfo;
#include "strv.h"
#include "unit-name.h"
enum UnitFileScope {
UNIT_FILE_SYSTEM,
UNIT_FILE_GLOBAL,
UNIT_FILE_USER,
_UNIT_FILE_SCOPE_MAX,
_UNIT_FILE_SCOPE_INVALID = -1
};
enum UnitFileState {
UNIT_FILE_ENABLED,
UNIT_FILE_ENABLED_RUNTIME,
UNIT_FILE_LINKED,
UNIT_FILE_LINKED_RUNTIME,
UNIT_FILE_MASKED,
UNIT_FILE_MASKED_RUNTIME,
UNIT_FILE_STATIC,
UNIT_FILE_DISABLED,
UNIT_FILE_INDIRECT,
UNIT_FILE_GENERATED,
UNIT_FILE_TRANSIENT,
UNIT_FILE_BAD,
_UNIT_FILE_STATE_MAX,
_UNIT_FILE_STATE_INVALID = -1
};
enum UnitFilePresetMode {
UNIT_FILE_PRESET_FULL,
UNIT_FILE_PRESET_ENABLE_ONLY,
@ -114,9 +87,6 @@ struct UnitFileInstallInfo {
bool auxiliary;
};
bool unit_type_may_alias(UnitType type) _const_;
bool unit_type_may_template(UnitType type) _const_;
int unit_file_enable(
UnitFileScope scope,
UnitFileFlags flags,

View File

@ -170,6 +170,8 @@ shared_sources = files('''
udev-util.h
uid-range.c
uid-range.h
unit-file.h
unit-file.c
utmp-wtmp.h
varlink.c
varlink.h

View File

@ -5,7 +5,7 @@
typedef struct LookupPaths LookupPaths;
#include "install.h"
#include "unit-file.h"
#include "macro.h"
typedef enum LookupPathsFlags {

23
src/shared/unit-file.c Normal file
View File

@ -0,0 +1,23 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "macro.h"
#include "unit-file.h"
bool unit_type_may_alias(UnitType type) {
return IN_SET(type,
UNIT_SERVICE,
UNIT_SOCKET,
UNIT_TARGET,
UNIT_DEVICE,
UNIT_TIMER,
UNIT_PATH);
}
bool unit_type_may_template(UnitType type) {
return IN_SET(type,
UNIT_SERVICE,
UNIT_SOCKET,
UNIT_TARGET,
UNIT_TIMER,
UNIT_PATH);
}

37
src/shared/unit-file.h Normal file
View File

@ -0,0 +1,37 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdbool.h>
#include "unit-name.h"
typedef enum UnitFileState UnitFileState;
typedef enum UnitFileScope UnitFileScope;
enum UnitFileState {
UNIT_FILE_ENABLED,
UNIT_FILE_ENABLED_RUNTIME,
UNIT_FILE_LINKED,
UNIT_FILE_LINKED_RUNTIME,
UNIT_FILE_MASKED,
UNIT_FILE_MASKED_RUNTIME,
UNIT_FILE_STATIC,
UNIT_FILE_DISABLED,
UNIT_FILE_INDIRECT,
UNIT_FILE_GENERATED,
UNIT_FILE_TRANSIENT,
UNIT_FILE_BAD,
_UNIT_FILE_STATE_MAX,
_UNIT_FILE_STATE_INVALID = -1
};
enum UnitFileScope {
UNIT_FILE_SYSTEM,
UNIT_FILE_GLOBAL,
UNIT_FILE_USER,
_UNIT_FILE_SCOPE_MAX,
_UNIT_FILE_SCOPE_INVALID = -1
};
bool unit_type_may_alias(UnitType type) _const_;
bool unit_type_may_template(UnitType type) _const_;

View File

@ -7,6 +7,7 @@
#include "bus-util.h"
#include "manager.h"
#include "rm-rf.h"
#include "strv.h"
#include "test-helper.h"
#include "tests.h"
#include "service.h"