]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/path.h
resolved: rework parsing of /etc/hosts
[thirdparty/systemd.git] / src / core / path.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 typedef struct Path Path;
5 typedef struct PathSpec PathSpec;
6
7 #include "unit.h"
8
9 typedef enum PathType {
10 PATH_EXISTS,
11 PATH_EXISTS_GLOB,
12 PATH_DIRECTORY_NOT_EMPTY,
13 PATH_CHANGED,
14 PATH_MODIFIED,
15 _PATH_TYPE_MAX,
16 _PATH_TYPE_INVALID = -1
17 } PathType;
18
19 typedef struct PathSpec {
20 Unit *unit;
21
22 char *path;
23
24 sd_event_source *event_source;
25
26 LIST_FIELDS(struct PathSpec, spec);
27
28 PathType type;
29 int inotify_fd;
30 int primary_wd;
31
32 bool previous_exists;
33 } PathSpec;
34
35 int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler);
36 void path_spec_unwatch(PathSpec *s);
37 int path_spec_fd_event(PathSpec *s, uint32_t events);
38 void path_spec_done(PathSpec *s);
39
40 static inline bool path_spec_owns_inotify_fd(PathSpec *s, int fd) {
41 return s->inotify_fd == fd;
42 }
43
44 typedef enum PathResult {
45 PATH_SUCCESS,
46 PATH_FAILURE_RESOURCES,
47 PATH_FAILURE_START_LIMIT_HIT,
48 _PATH_RESULT_MAX,
49 _PATH_RESULT_INVALID = -1
50 } PathResult;
51
52 struct Path {
53 Unit meta;
54
55 LIST_HEAD(PathSpec, specs);
56
57 PathState state, deserialized_state;
58
59 bool inotify_triggered;
60
61 bool make_directory;
62 mode_t directory_mode;
63
64 PathResult result;
65 };
66
67 void path_free_specs(Path *p);
68
69 extern const UnitVTable path_vtable;
70
71 const char* path_type_to_string(PathType i) _const_;
72 PathType path_type_from_string(const char *s) _pure_;
73
74 const char* path_result_to_string(PathResult i) _const_;
75 PathResult path_result_from_string(const char *s) _pure_;
76
77 DEFINE_CAST(PATH, Path);