]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/path.h
Merge pull request #17732 from yuwata/core-use-synthetic_errno
[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
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_FAILURE_UNIT_START_LIMIT_HIT,
49 _PATH_RESULT_MAX,
50 _PATH_RESULT_INVALID = -1
51 } PathResult;
52
53 struct Path {
54 Unit meta;
55
56 LIST_HEAD(PathSpec, specs);
57
58 PathState state, deserialized_state;
59
60 bool make_directory;
61 mode_t directory_mode;
62
63 PathResult result;
64 };
65
66 void path_free_specs(Path *p);
67
68 extern const UnitVTable path_vtable;
69
70 const char* path_type_to_string(PathType i) _const_;
71 PathType path_type_from_string(const char *s) _pure_;
72
73 const char* path_result_to_string(PathResult i) _const_;
74 PathResult path_result_from_string(const char *s) _pure_;
75
76 DEFINE_CAST(PATH, Path);