From dd1cf4c39cfadc74eb1f871c2f2256f4e5c764f7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 5 Jan 2017 16:54:33 +0100 Subject: use systemd service manager notification --- Makefile | 4 ++++ README.md | 1 + systemd/udev-block-notify.service | 2 +- udev-block-notify.c | 4 ++++ udev-block-notify.h | 5 +++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 956defd..142afc4 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ CP := cp CFLAGS += -std=c11 -O2 -fPIC -Wall -Werror CFLAGS += $(shell pkg-config --cflags --libs libudev) 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 c113dad..017f184 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Requirements To compile and run `udev-block-notify` you need: +* [systemd](https://www.github.com/systemd/systemd) * [libnotify](http://library.gnome.org/devel/notification-spec/) * [systemd](http://www.freedesktop.org/wiki/Software/systemd) (or `udev` which has been merge into `systemd`) * [markdown](http://daringfireball.net/projects/markdown/) (HTML documentation) diff --git a/systemd/udev-block-notify.service b/systemd/udev-block-notify.service index 375fc63..b7261b6 100644 --- a/systemd/udev-block-notify.service +++ b/systemd/udev-block-notify.service @@ -2,7 +2,7 @@ Description=Udev Block Notification [Service] -Type=simple +Type=notify ExecStart=/usr/bin/udev-block-notify [Install] diff --git a/udev-block-notify.c b/udev-block-notify.c index 974b6c6..32a761a 100644 --- a/udev-block-notify.c +++ b/udev-block-notify.c @@ -135,6 +135,10 @@ int main (int argc, char ** argv) { notifications->notification = NULL; notifications->next = NULL; +#ifdef HAVE_SYSTEMD + sd_notify(0, "READY=1\nSTATUS=Waiting for udev block events..."); +#endif + while (1) { FD_ZERO(&readfds); if (mon != NULL) diff --git a/udev-block-notify.h b/udev-block-notify.h index df34887..d4573b3 100644 --- a/udev-block-notify.h +++ b/udev-block-notify.h @@ -17,6 +17,11 @@ #include #include +/* systemd headers */ +#ifdef HAVE_SYSTEMD +#include +#endif + #include #include -- cgit v1.2.3-70-g09d2