chiark / gitweb /
util: add a bit of syntactic sugar to run short code fragments with a different umask
[elogind.git] / src / core / path.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct Path Path;
25
26 #include "unit.h"
27 #include "mount.h"
28
29 typedef enum PathState {
30         PATH_DEAD,
31         PATH_WAITING,
32         PATH_RUNNING,
33         PATH_FAILED,
34         _PATH_STATE_MAX,
35         _PATH_STATE_INVALID = -1
36 } PathState;
37
38 typedef enum PathType {
39         PATH_EXISTS,
40         PATH_EXISTS_GLOB,
41         PATH_DIRECTORY_NOT_EMPTY,
42         PATH_CHANGED,
43         PATH_MODIFIED,
44         _PATH_TYPE_MAX,
45         _PATH_TYPE_INVALID = -1
46 } PathType;
47
48 typedef struct PathSpec {
49         char *path;
50
51         Watch watch;
52
53         LIST_FIELDS(struct PathSpec, spec);
54
55         PathType type;
56         int inotify_fd;
57         int primary_wd;
58
59         bool previous_exists;
60 } PathSpec;
61
62 int path_spec_watch(PathSpec *s, Unit *u);
63 void path_spec_unwatch(PathSpec *s, Unit *u);
64 int path_spec_fd_event(PathSpec *s, uint32_t events);
65 void path_spec_done(PathSpec *s);
66
67 static inline bool path_spec_owns_inotify_fd(PathSpec *s, int fd) {
68         return s->inotify_fd == fd;
69 }
70
71 typedef enum PathResult {
72         PATH_SUCCESS,
73         PATH_FAILURE_RESOURCES,
74         _PATH_RESULT_MAX,
75         _PATH_RESULT_INVALID = -1
76 } PathResult;
77
78 struct Path {
79         Unit meta;
80
81         LIST_HEAD(PathSpec, specs);
82
83         UnitRef unit;
84
85         PathState state, deserialized_state;
86
87         bool inotify_triggered;
88
89         bool make_directory;
90         mode_t directory_mode;
91
92         PathResult result;
93 };
94
95 void path_unit_notify(Unit *u, UnitActiveState new_state);
96
97 /* Called from the mount code figure out if a mount is a dependency of
98  * any of the paths of this path object */
99 int path_add_one_mount_link(Path *p, Mount *m);
100
101 void path_free_specs(Path *p);
102
103 extern const UnitVTable path_vtable;
104
105 const char* path_state_to_string(PathState i);
106 PathState path_state_from_string(const char *s);
107
108 const char* path_type_to_string(PathType i);
109 PathType path_type_from_string(const char *s);
110
111 const char* path_result_to_string(PathResult i);
112 PathResult path_result_from_string(const char *s);