From b24304ebe9d45044db4798f904d55cc26bca977c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 1 Dec 2016 21:35:18 +0100 Subject: Use systemd service manager notification Notify systemd service manager when our initialization sequence completed. --- Makefile | 1 + pacredir.c | 3 +++ pacredir.h | 3 +++ systemd/pacredir.service | 1 + 4 files changed, 8 insertions(+) diff --git a/Makefile b/Makefile index c33806f..4b59aa8 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ SED := sed # flags CFLAGS += -std=c11 -O2 -fPIC -Wall -Werror CFLAGS_EXTRA += -lpthread +CFLAGS_EXTRA += $(shell pkg-config --libs --cflags libsystemd) CFLAGS_EXTRA += $(shell pkg-config --libs --cflags libcurl) CFLAGS_EXTRA += $(shell pkg-config --libs --cflags avahi-client) CFLAGS_EXTRA += $(shell pkg-config --libs --cflags libmicrohttpd) diff --git a/pacredir.c b/pacredir.c index b704f1c..afb9e8f 100644 --- a/pacredir.c +++ b/pacredir.c @@ -720,6 +720,9 @@ int main(int argc, char ** argv) { signal(SIGKILL, sig_callback); signal(SIGINT, sig_callback); + /* report ready to systemd */ + sd_notifyf(0, "READY=1\nSTATUS=Waiting for requests to redirect...\nMAINPID=%lu", (unsigned long) getpid()); + /* run the main loop */ avahi_simple_poll_loop(simple_poll); diff --git a/pacredir.h b/pacredir.h index e412db7..7dead59 100644 --- a/pacredir.h +++ b/pacredir.h @@ -24,6 +24,9 @@ #include #include +/* systemd headers */ +#include + /* Avahi headers */ #include #include diff --git a/systemd/pacredir.service b/systemd/pacredir.service index c64a5d5..bc5a13f 100644 --- a/systemd/pacredir.service +++ b/systemd/pacredir.service @@ -4,6 +4,7 @@ Requires=avahi-daemon.service After=avahi-daemon.service network.target network-online.target [Service] +Type=notify User=nobody Group=nobody ExecStart=/usr/bin/pacredir -- cgit v1.2.3-70-g09d2