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