[pve-devel] [PATCH common v2 1/2] systemd: add sd_notify() helper
Fiona Ebner
f.ebner at proxmox.com
Mon Oct 6 13:55:52 CEST 2025
See 'man 3 sd_notify'.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
New in v2.
src/PVE/Systemd.pm | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
index e6d6f88..96e7d80 100644
--- a/src/PVE/Systemd.pm
+++ b/src/PVE/Systemd.pm
@@ -3,9 +3,11 @@ package PVE::Systemd;
use strict;
use warnings;
+use IO::Socket::UNIX;
use Net::DBus qw(dbus_uint32 dbus_uint64 dbus_boolean);
use Net::DBus::Callback;
use Net::DBus::Reactor;
+use Socket qw(SOCK_DGRAM);
use PVE::Tools qw(file_set_contents file_get_contents trim);
@@ -282,4 +284,23 @@ sub write_ini {
file_set_contents($filename, $content);
}
+sub sd_notify {
+ my ($unset_environment, $state) = @_;
+
+ my $socket_path = $unset_environment ? delete($ENV{NOTIFY_SOCKET}) : $ENV{NOTIFY_SOCKET};
+
+ my $socket = IO::Socket::UNIX->new(
+ Type => SOCK_DGRAM(),
+ Peer => $socket_path,
+ ) or die "unable to connect to socket $socket_path to notify systemd\n";
+
+ # we won't be reading from the socket
+ shutdown($socket, 0);
+
+ print {$socket} $state;
+ $socket->flush();
+
+ close($socket);
+}
+
1;
--
2.47.3
More information about the pve-devel
mailing list