]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/path.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / core / path.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 typedef struct Path Path;
24 typedef struct PathSpec PathSpec;
25
26 #include "unit.h"
27
28 typedef enum PathType {
29 PATH_EXISTS,
30 PATH_EXISTS_GLOB,
31 PATH_DIRECTORY_NOT_EMPTY,
32 PATH_CHANGED,
33 PATH_MODIFIED,
34 _PATH_TYPE_MAX,
35 _PATH_TYPE_INVALID = -1
36 } PathType;
37
38 typedef struct PathSpec {
39 Unit *unit;
40
41 char *path;
42
43 sd_event_source *event_source;
44
45 LIST_FIELDS(struct PathSpec, spec);
46
47 PathType type;
48 int inotify_fd;
49 int primary_wd;
50
51 bool previous_exists;
52 } PathSpec;
53
54 int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler);
55 void path_spec_unwatch(PathSpec *s);
56 int path_spec_fd_event(PathSpec *s, uint32_t events);
57 void path_spec_done(PathSpec *s);
58
59 static inline bool path_spec_owns_inotify_fd(PathSpec *s, int fd) {
60 return s->inotify_fd == fd;
61 }
62
63 typedef enum PathResult {
64 PATH_SUCCESS,
65 PATH_FAILURE_RESOURCES,
66 PATH_FAILURE_START_LIMIT_HIT,
67 _PATH_RESULT_MAX,
68 _PATH_RESULT_INVALID = -1
69 } PathResult;
70
71 struct Path {
72 Unit meta;
73
74 LIST_HEAD(PathSpec, specs);
75
76 PathState state, deserialized_state;
77
78 bool inotify_triggered;
79
80 bool make_directory;
81 mode_t directory_mode;
82
83 PathResult result;
84 };
85
86 void path_free_specs(Path *p);
87
88 extern const UnitVTable path_vtable;
89
90 const char* path_type_to_string(PathType i) _const_;
91 PathType path_type_from_string(const char *s) _pure_;
92
93 const char* path_result_to_string(PathResult i) _const_;
94 PathResult path_result_from_string(const char *s) _pure_;