#include "special.h"
#include "bus-errors.h"
#include "path-util.h"
+#include "macro.h"
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
};
bool exists = false;
- char *k, *slash;
+ char _cleanup_free_ *k = NULL;
+ char *slash;
int r;
assert(u);
path_spec_unwatch(s, u);
- if (!(k = strdup(s->path)))
+ k = strdup(s->path);
+ if (!k)
return -ENOMEM;
- if ((s->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC)) < 0) {
+ s->inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
+ if (s->inotify_fd < 0) {
r = -errno;
goto fail;
}
- if (unit_watch_fd(u, s->inotify_fd, EPOLLIN, &s->watch) < 0) {
- r = -errno;
+ r = unit_watch_fd(u, s->inotify_fd, EPOLLIN, &s->watch);
+ if (r < 0)
goto fail;
- }
s->primary_wd = inotify_add_watch(s->inotify_fd, k, flags_table[s->type]);
if (s->primary_wd >= 0)
return 0;
fail:
- free(k);
-
path_spec_unwatch(s, u);
return r;
}
}
int path_spec_fd_event(PathSpec *s, uint32_t events) {
- uint8_t *buf = NULL;
+ uint8_t _cleanup_free_ *buf = NULL;
struct inotify_event *e;
ssize_t k;
int l;
if (events != EPOLLIN) {
log_error("Got invalid poll event on inotify.");
- r = -EINVAL;
- goto out;
+ return -EINVAL;
}
if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
log_error("FIONREAD failed: %m");
- r = -errno;
- goto out;
+ return -errno;
}
assert(l > 0);
buf = malloc(l);
- if (!buf) {
- log_error("Failed to allocate buffer: %m");
- r = -errno;
- goto out;
- }
+ if (!buf)
+ return log_oom();
k = read(s->inotify_fd, buf, l);
if (k < 0) {
log_error("Failed to read inotify event: %m");
- r = -errno;
- goto out;
+ return -errno;
}
e = (struct inotify_event*) buf;
e = (struct inotify_event*) ((uint8_t*) e + step);
k -= step;
}
-out:
- free(buf);
+
return r;
}
p->directory_mode = 0755;
}
-static void path_done(Unit *u) {
- Path *p = PATH(u);
+void path_free_specs(Path *p) {
PathSpec *s;
assert(p);
- unit_ref_unset(&p->unit);
-
while ((s = p->specs)) {
- path_spec_unwatch(s, u);
+ path_spec_unwatch(s, UNIT(p));
LIST_REMOVE(PathSpec, spec, p->specs, s);
path_spec_done(s);
free(s);
}
}
+static void path_done(Unit *u) {
+ Path *p = PATH(u);
+
+ assert(p);
+
+ unit_ref_unset(&p->unit);
+ path_free_specs(p);
+}
+
int path_add_one_mount_link(Path *p, Mount *m) {
PathSpec *s;
int r;