~martijnbraam/public-inbox

logbookd: logbookd: Add fd activation support via content of environment var v1 APPLIED

Mobin Aydinfar: 1
 logbookd: Add fd activation support via content of environment var

 3 files changed, 19 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~martijnbraam/public-inbox/patches/50918/mbox | git am -3
Learn more about email & git

[PATCH logbookd] logbookd: Add fd activation support via content of environment var Export this patch

It's a simple protocol that the supervisor will supply a already open file desciptor
in LOGBOOKD_READY_FD environment variable in order to find out when logbookd is ready.

It's supported at least on Dinit, s6 and Finit.

See https://davmac.org/projects/dinit/man-pages-html/dinit-service.5.html#ready and
https://skarnet.org/software/s6/notifywhenup.html for more details about this protocol.

Signed-off-by: Mobin Aydinfar <mobin@mobintestserver.ir>
---
 main.c            | 12 ++++++++++++
 meson.build       |  6 +++++-
 meson_options.txt |  3 ++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index f5f8788..0529fa0 100644
--- a/main.c
+++ b/main.c
@@ -892,6 +892,18 @@ main(int argc, char *argv[])
	}

	int log_fd;
#ifdef WITH_FD_ACTIVATION
    char *fd_str = getenv("LOGBOOKD_READY_FD");
    if (fd_str != NULL) {
        int notify_fd = atoi(fd_str);
        if (notify_fd < 3) {
            self_log(SEV_CRIT, "fd received from fd activation is not valid");
            return 1;
        }
        write(notify_fd, "\n", 1);
        close(notify_fd);
    }
#endif
#ifdef WITH_SOCKET_ACTIVATION
	int n_sockets = sd_listen_fds(0);
	if (n_sockets > 1) {
diff --git a/meson.build b/meson.build
index c7e77e7..fb18eea 100644
--- a/meson.build
+++ b/meson.build
@@ -9,6 +9,10 @@ if systemd.found()
    add_project_arguments('-DWITH_SOCKET_ACTIVATION', language: 'c')
endif

if get_option('fd-activation')
    add_project_arguments('-DWITH_FD_ACTIVATION', language: 'c')
endif

add_project_arguments('-DLOGREAD_SOCKET="@0@"'.format(get_option('logread-socket')), language: 'c')

executable('logbookd', 'main.c', 'shared.h', 'shared.c', 'parser.c', 'parser.h', 'bytemess.h',
@@ -40,4 +44,4 @@ if scdoc.found()
endif

test_parser = executable('test_parser', 'test_parser.c', 'shared.c', 'shared.h', 'parser.c', 'parser.h', 'greatest.h')
test('test_parser', test_parser)
\ No newline at end of file
test('test_parser', test_parser)
diff --git a/meson_options.txt b/meson_options.txt
index b913999..2ab0c3d 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,2 +1,3 @@
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
option('logread-socket', type: 'string', value: '/run/logbookd/logread', description: 'Location of the logread socket')
\ No newline at end of file
option('logread-socket', type: 'string', value: '/run/logbookd/logread', description: 'Location of the logread socket')
option('fd-activation', type: 'boolean', value: false, description: 'Build logbookd with fd activation notify support')
-- 
2.43.0