Debian Codegraph @

src/core/path.h

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