Systemd::Daemon::XS - Perl bindings to libsystemd.
Version 0.07, released on 2015-11-12 13:35 UTC.
use Systemd::Daemon::XS qw{ :all }; sd_notify( 0, "READY=1\nSTATUS=Ready\n" ); sd_pid_notify( $pid, 0, "RELOADING=1" ); if ( sd_booted() ) { ...; }; ...;
This module provides Perl bindings to the part of libsystemd shared library declared in <systemd/sd-daemon.h> header.
The module exports nothing by default. You have to specify symbols to import explicitly:
# Import function sd_listen_fds and constant $SD_LISTEN_FDS_START: use Systemd::Daemon::XS qw{ sd_listen_fds $SD_LISTEN_FDS_START };
or use tags to import groups of related symbols:
# The same as as above: use Systemd::Daemon::XS qw{ :sd_listen };
Either colon (:) or dash (-) can be used as tag prefix:
:
-
# Ditto: use Systemd::Daemon::XS qw{ -sd_listen };
The module uses Exporter::Tiny to export symbols, so all advanced import features like renaming symbols, importing to another package, to a hash, by regexp, etc, can be used:
use Systemd::Daemon::XS '$SD_ERR' => { -as => 'ERR' }, '$SD_DEBUG' => { -as => 'DBG' }; use Systemd::Daemon::XS qw{ -all !sd_notify };
See tips and tricks.
The module defines following export tags (all tag is not listed):
all
sd_booted.
sd_is_fifo, sd_is_mq, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_special.
$SD_LISTEN_FDS_START, sd_listen_fds.
$SD_ALERT, $SD_CRIT, $SD_DEBUG, $SD_EMERG, $SD_ERR, $SD_INFO, $SD_NOTICE, $SD_WARNING.
sd_notify, sd_pid_notify.
All above.
Constants described below are not traditional 0-ary functions created by constant pragma, but immutable variables created by Readonly module, so you have to use sigils but can interpolate constants to strings.
constant
Readonly
See sd-daemon(3).
See sd_listen_fds(3).
int sd_listen_fds( int unset_environment );
int sd_notify( int unset_environment, const char * state ); // int sd_notifyf( int unset_environment, const char * format, ... ); int sd_pid_notify( pid_t pid, int unset_environment, const char * state ); // int sd_pid_notify_with_fds( pid_t pid, int unset_environment, const char * state, const int * fds, unsigned n_fds ); // int sd_pid_notifyf( int pid, int unset_environment, const char * format, ... );
See sd_notify(3) for details.
The binding for sd_pid_notify_with_fds function is not yet implemented.
sd_pid_notify_with_fds
The bindings for sd_notifyf and sd_pid_notifyf will not be implemented likely. These printf-like functions accept format string and variable argument list. They are quite convenient in C, but in Perl they do not have much value — they may be easily replaced either by string interpolation and/or by using sprintf function, e. g.:
sd_notifyf
sd_pid_notifyf
printf
sprintf
sd_notify( 0, "STATUS=Done $percent\%.\n" ); sd_notify( 0, sprintf( "STATUS=Done %03d\%.\n", $percent ) );
Also, it can be reimplemented in Perl:
sub sd_notifyf($$@) { return sd_notify( shift( @_ ), sprintf( @_ ) ); }
Such implementation is not included into Systemd::Daemon::XS because it is not a binding to libsystemd.
Systemd::Daemon::XS
libsystemd
int sd_booted();
See sd_booted(3).
int sd_is_fifo( int fd, const char * path ); int sd_is_mq( int fd, const char * path ); int sd_is_socket( int fd, int family, int type, int listening ); int sd_is_socket_inet( int fd, int family, int type, int listening, uint16_t port ); int sd_is_socket_unix( int fd, int family, int type, int listening, const char * path, size_t length ); int sd_is_special( int fd, const char * path );
See sd_is_fifo(3).
// int sd_watchdog_enabled( int unset_environment, uint64_t * usec );
See sd_watchdog_enabled(3).
The binding for sd_watchdog_enabled function is not yet implemented.
sd_watchdog_enabled
sd_listen_fds(3)
sd_notify(3)
sd_booted(3)
sd_is_fifo(3)
sd_watchdog_enabled(3)
Exporter::Tiny
Van de Bugger <van.de.bugger@gmail.com>
Copyright (C) 2015 Van de Bugger
License GPLv3+: The GNU General Public License version 3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
To install Systemd::Daemon, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Systemd::Daemon
CPAN shell
perl -MCPAN -e shell install Systemd::Daemon
For more information on module installation, please visit the detailed CPAN module installation guide.