]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/install.h
Merge pull request #2092 from poettering/dnssec2
[thirdparty/systemd.git] / src / shared / install.h
CommitLineData
83096483
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
c2f1db8f 3#pragma once
83096483
LP
4
5/***
6 This file is part of systemd.
7
8 Copyright 2011 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
83096483
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
83096483 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
83096483
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
cab6235f
LP
24typedef enum UnitFileScope UnitFileScope;
25typedef enum UnitFileState UnitFileState;
26typedef enum UnitFilePresetMode UnitFilePresetMode;
27typedef enum UnitFileChangeType UnitFileChangeType;
0ec0deaa 28typedef enum UnitFileType UnitFileType;
cab6235f
LP
29typedef struct UnitFileChange UnitFileChange;
30typedef struct UnitFileList UnitFileList;
31typedef struct UnitFileInstallInfo UnitFileInstallInfo;
32
83096483 33#include "hashmap.h"
a8ffe6fb 34#include "path-lookup.h"
0ec0deaa
LP
35#include "strv.h"
36#include "unit-name.h"
83096483 37
cab6235f 38enum UnitFileScope {
83096483
LP
39 UNIT_FILE_SYSTEM,
40 UNIT_FILE_GLOBAL,
41 UNIT_FILE_USER,
42 _UNIT_FILE_SCOPE_MAX,
43 _UNIT_FILE_SCOPE_INVALID = -1
cab6235f 44};
83096483 45
cab6235f 46enum UnitFileState {
83096483
LP
47 UNIT_FILE_ENABLED,
48 UNIT_FILE_ENABLED_RUNTIME,
49 UNIT_FILE_LINKED,
50 UNIT_FILE_LINKED_RUNTIME,
51 UNIT_FILE_MASKED,
52 UNIT_FILE_MASKED_RUNTIME,
53 UNIT_FILE_STATIC,
54 UNIT_FILE_DISABLED,
aedd4012 55 UNIT_FILE_INDIRECT,
0ec0deaa 56 UNIT_FILE_BAD,
83096483
LP
57 _UNIT_FILE_STATE_MAX,
58 _UNIT_FILE_STATE_INVALID = -1
cab6235f 59};
83096483 60
cab6235f 61enum UnitFilePresetMode {
d309c1c3
LP
62 UNIT_FILE_PRESET_FULL,
63 UNIT_FILE_PRESET_ENABLE_ONLY,
64 UNIT_FILE_PRESET_DISABLE_ONLY,
86bbe5bf 65 _UNIT_FILE_PRESET_MAX,
d309c1c3 66 _UNIT_FILE_PRESET_INVALID = -1
cab6235f 67};
d309c1c3 68
cab6235f 69enum UnitFileChangeType {
83096483
LP
70 UNIT_FILE_SYMLINK,
71 UNIT_FILE_UNLINK,
72 _UNIT_FILE_CHANGE_TYPE_MAX,
73 _UNIT_FILE_CHANGE_TYPE_INVALID = -1
cab6235f 74};
83096483 75
cab6235f 76struct UnitFileChange {
83096483
LP
77 UnitFileChangeType type;
78 char *path;
79 char *source;
cab6235f 80};
83096483 81
cab6235f 82struct UnitFileList {
83096483
LP
83 char *path;
84 UnitFileState state;
cab6235f 85};
83096483 86
0ec0deaa
LP
87enum UnitFileType {
88 UNIT_FILE_TYPE_REGULAR,
89 UNIT_FILE_TYPE_SYMLINK,
90 UNIT_FILE_TYPE_MASKED,
91 _UNIT_FILE_TYPE_MAX,
92 _UNIT_FILE_TYPE_INVALID = -1,
93};
94
cab6235f 95struct UnitFileInstallInfo {
7584d236
ZJS
96 char *name;
97 char *path;
98
99 char **aliases;
100 char **wanted_by;
101 char **required_by;
aedd4012 102 char **also;
d54c4993
LP
103
104 char *default_instance;
0ec0deaa
LP
105
106 UnitFileType type;
107
108 char *symlink_target;
cab6235f 109};
7584d236 110
0ec0deaa
LP
111static inline bool UNIT_FILE_INSTALL_INFO_HAS_RULES(UnitFileInstallInfo *i) {
112 assert(i);
113
114 return !strv_isempty(i->aliases) ||
115 !strv_isempty(i->wanted_by) ||
116 !strv_isempty(i->required_by);
117}
118
119static inline bool UNIT_FILE_INSTALL_INFO_HAS_ALSO(UnitFileInstallInfo *i) {
120 assert(i);
121
122 return !strv_isempty(i->also);
123}
124
7195aa42
ZJS
125int unit_file_enable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes);
126int unit_file_disable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes);
127int unit_file_reenable(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes);
128int unit_file_link(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes);
d309c1c3
LP
129int unit_file_preset(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes);
130int unit_file_preset_all(UnitFileScope scope, bool runtime, const char *root_dir, UnitFilePresetMode mode, bool force, UnitFileChange **changes, unsigned *n_changes);
7195aa42
ZJS
131int unit_file_mask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, bool force, UnitFileChange **changes, unsigned *n_changes);
132int unit_file_unmask(UnitFileScope scope, bool runtime, const char *root_dir, char **files, UnitFileChange **changes, unsigned *n_changes);
718db961 133int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char *file, bool force, UnitFileChange **changes, unsigned *n_changes);
99504dd4 134int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name);
0ec0deaa 135int unit_file_add_dependency(UnitFileScope scope, bool runtime, const char *root_dir, char **files, const char *target, UnitDependency dep, bool force, UnitFileChange **changes, unsigned *n_changes);
83096483 136
0ec0deaa
LP
137int unit_file_lookup_state(UnitFileScope scope, const char *root_dir,const LookupPaths *paths, const char *name, UnitFileState *ret);
138int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
83096483
LP
139
140int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
0ec0deaa 141Hashmap* unit_file_list_free(Hashmap *h);
83096483 142
57ab2eab 143int unit_file_changes_add(UnitFileChange **changes, unsigned *n_changes, UnitFileChangeType type, const char *path, const char *source);
83096483
LP
144void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes);
145
c2a8d7b0 146int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name);
83096483 147
44a6b1b6
ZJS
148const char *unit_file_state_to_string(UnitFileState s) _const_;
149UnitFileState unit_file_state_from_string(const char *s) _pure_;
83096483 150
44a6b1b6
ZJS
151const char *unit_file_change_type_to_string(UnitFileChangeType s) _const_;
152UnitFileChangeType unit_file_change_type_from_string(const char *s) _pure_;
d309c1c3
LP
153
154const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
155UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;