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