summaryrefslogtreecommitdiff
path: root/name.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-24 00:39:29 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-24 00:39:29 +0100
commit9152c765065184d0c1267ed2499e3fe4cac53755 (patch)
tree70047967e77e502779d1febc6209a4f7b67a1bbf /name.c
parent476fe607ecbabc5beffafc8efb0778e3d9e1030a (diff)
add simple event loop
Diffstat (limited to 'name.c')
-rw-r--r--name.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/name.c b/name.c
index b6e62e9bee..e92242845b 100644
--- a/name.c
+++ b/name.c
@@ -3,6 +3,7 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
+#include <sys/epoll.h>
#include "set.h"
#include "name.h"
@@ -11,7 +12,7 @@
#include "load-fragment.h"
#include "load-dropin.h"
-static const NameVTable * const name_vtable[_NAME_TYPE_MAX] = {
+const NameVTable * const name_vtable[_NAME_TYPE_MAX] = {
[NAME_SERVICE] = &service_vtable,
[NAME_TIMER] = &timer_vtable,
[NAME_SOCKET] = &socket_vtable,
@@ -22,8 +23,6 @@ static const NameVTable * const name_vtable[_NAME_TYPE_MAX] = {
[NAME_SNAPSHOT] = &snapshot_vtable
};
-#define NAME_VTABLE(n) name_vtable[(n)->meta.type]
-
NameType name_type_from_string(const char *n) {
NameType t;
@@ -700,3 +699,41 @@ void name_notify(Name *n, NameActiveState os, NameActiveState ns) {
else if (NAME_IS_ACTIVE_OR_ACTIVATING(os) && NAME_IS_INACTIVE_OR_DEACTIVATING(ns))
retroactively_stop_dependencies(n);
}
+
+int name_watch_fd(Name *n, int fd, uint32_t events) {
+ struct epoll_event ev;
+
+ assert(n);
+ assert(fd >= 0);
+
+ zero(ev);
+ ev.data.fd = fd;
+ ev.data.ptr = n;
+ ev.events = events;
+
+ if (epoll_ctl(n->meta.manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
+ return -errno;
+
+ return 0;
+}
+
+void name_unwatch_fd(Name *n, int fd) {
+ assert(n);
+ assert(fd >= 0);
+
+ assert_se(epoll_ctl(n->meta.manager->epoll_fd, EPOLL_CTL_DEL, fd, NULL) >= 0 || errno == ENOENT);
+}
+
+int name_watch_pid(Name *n, pid_t pid) {
+ assert(n);
+ assert(pid >= 1);
+
+ return hashmap_put(n->meta.manager->watch_pids, UINT32_TO_PTR(pid), n);
+}
+
+void name_unwatch_pid(Name *n, pid_t pid) {
+ assert(n);
+ assert(pid >= 1);
+
+ hashmap_remove(n->meta.manager->watch_pids, UINT32_TO_PTR(pid));
+}