static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
-int path_spec_watch(PathSpec *s, Unit *u) {
+static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
+
+int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
static const int flags_table[_PATH_TYPE_MAX] = {
[PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB,
static const int flags_table[_PATH_TYPE_MAX] = {
[PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB,
- r = unit_watch_fd(u, s->inotify_fd, EPOLLIN, &s->watch);
+ r = sd_event_add_io(s->unit->manager->event, &s->event_source, s->inotify_fd, EPOLLIN, handler, s);
- log_warning("Failed to add watch on %s: %m", s->path);
+ log_warning("Failed to add watch on %s: %s", s->path,
+ errno == ENOSPC ? "too many watches" : strerror(-r));
-int path_spec_fd_event(PathSpec *s, uint32_t events) {
- _cleanup_free_ uint8_t *buf = NULL;
+int path_spec_fd_event(PathSpec *s, uint32_t revents) {
+ union inotify_event_buffer buffer;
- if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
- log_error("FIONREAD failed: %m");
- return -errno;
- }
-
- assert(l > 0);
-
- buf = malloc(l);
- if (!buf)
- return log_oom();
+ l = read(s->inotify_fd, &buffer, sizeof(buffer));
+ if (l < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ return 0;
- k = read(s->inotify_fd, buf, l);
- if (k < 0) {
- log_error("Failed to read inotify event: %m");
- return -errno;
+ return log_error_errno(errno, "Failed to read inotify event: %m");
- path_spec_unwatch(s, UNIT(p));
- LIST_REMOVE(PathSpec, spec, p->specs, s);
+ path_spec_unwatch(s);
+ LIST_REMOVE(spec, p->specs, s);
- log_warning("%s failed to enter waiting state: %s",
- UNIT(p)->id, strerror(-r));
+ log_warning_errno(r, "%s failed to enter waiting state: %m", UNIT(p)->id);
p->result = PATH_SUCCESS;
path_enter_waiting(p, true, true);
p->result = PATH_SUCCESS;
path_enter_waiting(p, true, true);
assert(p->state == PATH_WAITING || p->state == PATH_RUNNING);
path_enter_dead(p, PATH_SUCCESS);
assert(p->state == PATH_WAITING || p->state == PATH_RUNNING);
path_enter_dead(p, PATH_SUCCESS);
-static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
- Path *p = PATH(u);
- PathSpec *s;
+static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
+ PathSpec *s = userdata;
+ Path *p;
static const char* const path_type_table[_PATH_TYPE_MAX] = {
[PATH_EXISTS] = "PathExists",
[PATH_EXISTS_GLOB] = "PathExistsGlob",
static const char* const path_type_table[_PATH_TYPE_MAX] = {
[PATH_EXISTS] = "PathExists",
[PATH_EXISTS_GLOB] = "PathExistsGlob",
[PATH_CHANGED] = "PathChanged",
[PATH_MODIFIED] = "PathModified",
[PATH_CHANGED] = "PathChanged",
[PATH_MODIFIED] = "PathModified",
};
DEFINE_STRING_TABLE_LOOKUP(path_type, PathType);
static const char* const path_result_table[_PATH_RESULT_MAX] = {
[PATH_SUCCESS] = "success",
};
DEFINE_STRING_TABLE_LOOKUP(path_type, PathType);
static const char* const path_result_table[_PATH_RESULT_MAX] = {
[PATH_SUCCESS] = "success",
};
DEFINE_STRING_TABLE_LOOKUP(path_result, PathResult);
const UnitVTable path_vtable = {
.object_size = sizeof(Path),
};
DEFINE_STRING_TABLE_LOOKUP(path_result, PathResult);
const UnitVTable path_vtable = {
.object_size = sizeof(Path),
.active_state = path_active_state,
.sub_state_to_string = path_sub_state_to_string,
.active_state = path_active_state,
.sub_state_to_string = path_sub_state_to_string,
.trigger_notify = path_trigger_notify,
.reset_failed = path_reset_failed,
.bus_interface = "org.freedesktop.systemd1.Path",
.trigger_notify = path_trigger_notify,
.reset_failed = path_reset_failed,
.bus_interface = "org.freedesktop.systemd1.Path",