From ed8b18dbe85d4d1915101d2ee5a0e9c0263f1971 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 5 Jan 2017 16:45:01 +0100 Subject: use systemd service manager notification --- Makefile | 4 ++++ README.md | 1 + netlink-notify.c | 4 ++++ netlink-notify.h | 5 +++++ systemd/netlink-notify.service | 2 +- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 37c1e85..9f4e38d 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ RM := rm # flags CFLAGS += -std=c11 -O2 -fPIC -Wall -Werror CFLAGS += $(shell pkg-config --cflags --libs libnotify) +CFLAGS_SYSTEMD := $(shell pkg-config --cflags --libs libsystemd 2>/dev/null) +ifneq ($(CFLAGS_SYSTEMD),) +CFLAGS += -DHAVE_SYSTEMD $(CFLAGS_SYSTEMD) +endif LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie # this is just a fallback in case you do not use git but downloaded diff --git a/README.md b/README.md index de6dd4f..41615b8 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Requirements To compile and run `netlink-notify` you need: +* [systemd](https://www.github.com/systemd/systemd) * [libnotify](http://library.gnome.org/devel/notification-spec/) * [linux](http://www.kernel.org/) * [markdown](http://daringfireball.net/projects/markdown/) (HTML documentation) diff --git a/netlink-notify.c b/netlink-notify.c index d529ed4..5d96afa 100644 --- a/netlink-notify.c +++ b/netlink-notify.c @@ -503,6 +503,10 @@ int main (int argc, char **argv) { signal(SIGINT, received_signal); signal(SIGTERM, received_signal); +#ifdef HAVE_SYSTEMD + sd_notify(0, "READY=1\nSTATUS=Waiting for netlink events..."); +#endif + while (doexit == 0) { if (read_event(nls) != EXIT_SUCCESS) { fprintf(stderr, "%s: read_event returned error.\n", program); diff --git a/netlink-notify.h b/netlink-notify.h index 9f1f6e8..eea7cb9 100644 --- a/netlink-notify.h +++ b/netlink-notify.h @@ -30,6 +30,11 @@ #include #include +/* systemd headers */ +#ifdef HAVE_SYSTEMD +#include +#endif + #include #include "version.h" diff --git a/systemd/netlink-notify.service b/systemd/netlink-notify.service index 2db23c7..1aba5e3 100644 --- a/systemd/netlink-notify.service +++ b/systemd/netlink-notify.service @@ -2,7 +2,7 @@ Description=Netlink Notification [Service] -Type=simple +Type=notify ExecStart=/usr/bin/netlink-notify [Install] -- cgit v1.2.3-54-g00ecf