Email or username:

Password:

Forgot your password?
Lennart Poettering

PSA: In context of the xzpocalypse we now added an example reimplementation of sd_notify() to our man page:

freedesktop.org/software/syste

It's pretty comprehensive (i.e. uses it for reload notification too), but still relatively short.

In the past, I have been telling anyone who wanted to listen that if all you want is sd_notify() then don't bother linking to libsystemd, since the protocol is stable and should be considered the API, not our C wrapper around it. After all, the protocol is so trivial

8 comments
Lennart Poettering

that one can explain it in one sentence: send an AF_UNIX datagram containing READY=1 to a socket whose path you find in the $NOTIFY_SOCKET env var.

But apparently turning that sentence (which appears in similar fashion in the man page) into code is not trivial, hence this new example code.

Hence, copy away, the thing is MIT licensed. And the protocol has been stable for a decade, and I am pretty sure it's going to remain stable for another decade at least.

bluca

@pid_eins

> And the protocol has been stable for a decade, and I am pretty sure it's going to remain stable for another decade at least.

setting reminder for April 2034: break notify protocol

ldvsoft

@pid_eins could you possibly provide it as a header-only library out of the box? Static function, shouldn't be that crazy.

Lennart Poettering

@ldvsoft i am not a fan of those. Static inline funcs suggest inlining to the compiler and we typically want that services call these functions multiple times (ready notification + reload notification at least) hence inlining is the wrong thing. I mean hopefully the compiler figures this out on its own, but given LTO is not pervasively used today there'll be plenty cases where the code wont be reduced to a single copy.

ldvsoft

@pid_eins duuuh. Is notify used more than than a couple times anyway to mess up that much?

But I guess you're right that the standard doesn't give us out of the box easy experience to declare I-don't-care-about-address-uniqueness-just-link-it functions. @thephd sorry to bother, is it even a popular use case? I definenelty wrote a couple of static-not-inline function in some internal headers of my projects.

bluca

@ldvsoft @pid_eins @thephd on startup, on reload, on watchdog ping are the most common use cases

ldvsoft

@bluca @pid_eins yeah, those three. I'd think that ready/reload are quite cold on the runtime. Watchdog probably not the hostest thing in the world.

Björkus "No time_t to Die" Dorkus

@ldvsoft @pid_eins It's not an entirely uncommon use case but the fix is to provide a header file and a source file with the usual boilerplate to make it link either statically with a public-visibility function or a DLL with a public-visibility exported entry in the DLL. your distro maintainers will fight over who gets the honor of making it an official dependable package if they care.

Go Up