Systemd-Daemon

 view release on metacpan or  search on metacpan

lib/Systemd/Daemon.pm  view on Meta::CPAN

#pod
#pod =cut

# --------------------------------------------------------------------------------------------------

#pod =func notify
#pod
#pod     $int = notify( VAR => VALUE, … );
#pod
#pod C<notify> is Perl wrapper for C functions C<sd_notify> and C<sd_pid_notify>, so read
#pod L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> first.
#pod
#pod C functions accept status as one string of newline-separated variable assignments, e. g.:
#pod
#pod     sd_notify( 0, "RELOADING=1\nSTATUS=50% done\n" );
#pod
#pod Unlike to C functions, C<notify> accepts each variable separately as Perl "named arguments", e. g.:
#pod
#pod     notify( RELOADING => 1, STATUS => '50% done' );
#pod
#pod C<unset_environment> and C<pid> parameters can be specified as named arguments C<unset> and C<pid>
#pod respectively, e. g.:
#pod
#pod     notify( pid => $pid, unset => 1, ... );
#pod
#pod If C<pid> value is defined, C<notify> calls C<sd_pid_notify>, otherwise C<sd_notify> is called.
#pod C<unset> is defaulted to zero.
#pod
#pod L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> describes some
#pod "well-known" variable assignments, for example, C<RELOADING=1>. Systemd's reaction on assignment
#pod C<RELOADING=2> is not defined. In my experiments with systemd v217 any value but C<1> does not have
#pod any effect. To make C<notify> more Perlish, C<READY>, C<RELOADING>, C<STOPPING>, C<WATCHDOG>, and
#pod C<FDSTORE> arguments are normalized: if its value is false (e. g. undef, zero or empty string), the
#pod respective variable is not passed to underlying C function at all; if its value is true (not
#pod false), the respective variable is set to C<1>.
#pod
#pod C<notify> returns result of underlying C<sd_notify> (or C<sd_pid_notify>). It should be negative
#pod integer in case of error, zero if C<$ENV{ NOTIFY_SOCKET }> is not set (and so, C<systemd> cannot be
#pod notified), and some positive value in case of success. However, L<sd_notify(3)> recommends to

lib/Systemd/Daemon.pm  view on Meta::CPAN

    };
};

push( @EXPORT_OK, 'notify' );

#pod =head1 BUGS
#pod
#pod =head1 SEE ALSO
#pod
#pod =for :list
#pod *   L<systemd|https://wiki.freedesktop.org/www/Software/systemd/>
#pod *   L<daemon|http://www.freedesktop.org/software/systemd/man/daemon.html>
#pod *   L<sd-daemon|http://www.freedesktop.org/software/systemd/man/sd-daemon.html>
#pod
#pod =head1 COPYRIGHT AND LICENSE
#pod
#pod Copyright (C) 2015 Van de Bugger
#pod
#pod License GPLv3+: The GNU General Public License version 3 or later
#pod <http://www.gnu.org/licenses/gpl-3.0.txt>.
#pod
#pod This is free software: you are free to change and redistribute it. There is
#pod NO WARRANTY, to the extent permitted by law.

lib/Systemd/Daemon.pm  view on Meta::CPAN

The module re-exports (by explicit request) all the functions from underlying implementation,
see L<Systemd::Daemon::XS/"FUNCTIONS">.

Additionally, the module defines following functions:

=head2 notify

    $int = notify( VAR => VALUE, … );

C<notify> is Perl wrapper for C functions C<sd_notify> and C<sd_pid_notify>, so read
L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> first.

C functions accept status as one string of newline-separated variable assignments, e. g.:

    sd_notify( 0, "RELOADING=1\nSTATUS=50% done\n" );

Unlike to C functions, C<notify> accepts each variable separately as Perl "named arguments", e. g.:

    notify( RELOADING => 1, STATUS => '50% done' );

C<unset_environment> and C<pid> parameters can be specified as named arguments C<unset> and C<pid>
respectively, e. g.:

    notify( pid => $pid, unset => 1, ... );

If C<pid> value is defined, C<notify> calls C<sd_pid_notify>, otherwise C<sd_notify> is called.
C<unset> is defaulted to zero.

L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> describes some
"well-known" variable assignments, for example, C<RELOADING=1>. Systemd's reaction on assignment
C<RELOADING=2> is not defined. In my experiments with systemd v217 any value but C<1> does not have
any effect. To make C<notify> more Perlish, C<READY>, C<RELOADING>, C<STOPPING>, C<WATCHDOG>, and
C<FDSTORE> arguments are normalized: if its value is false (e. g. undef, zero or empty string), the
respective variable is not passed to underlying C function at all; if its value is true (not
false), the respective variable is set to C<1>.

C<notify> returns result of underlying C<sd_notify> (or C<sd_pid_notify>). It should be negative
integer in case of error, zero if C<$ENV{ NOTIFY_SOCKET }> is not set (and so, C<systemd> cannot be
notified), and some positive value in case of success. However, L<sd_notify(3)> recommends to

lib/Systemd/Daemon.pm  view on Meta::CPAN

L<Systemd::Daemon::XS/"CONSTANTS">.

=head1 BUGS

=head1 SEE ALSO

=over 4

=item *

L<systemd|https://wiki.freedesktop.org/www/Software/systemd/>

=item *

L<daemon|http://www.freedesktop.org/software/systemd/man/daemon.html>

=item *

L<sd-daemon|http://www.freedesktop.org/software/systemd/man/sd-daemon.html>

=back

=head1 AUTHOR

Van de Bugger <van.de.bugger@gmail.com>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2015 Van de Bugger

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

        #   tries to extract debug information from files which were wiped out.
    ;

#pod =pod
#pod
#pod =func sd_listen_fds
#pod
#pod     int sd_listen_fds( int unset_environment );
#pod
#pod
#pod See L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.
#pod
#pod =func sd_notify
#pod
#pod =func sd_notifyf
#pod
#pod =func sd_pid_notify
#pod
#pod =func sd_pid_notify_with_fds
#pod
#pod =func sd_pid_notifyf
#pod
#pod     int sd_notify( int unset_environment, const char * state );
#pod     // int sd_notifyf( int unset_environment, const char * format, ... );
#pod     int sd_pid_notify( pid_t pid, int unset_environment, const char * state );
#pod     // int sd_pid_notify_with_fds( pid_t pid, int unset_environment, const char * state, const int * fds, unsigned n_fds );
#pod     // int sd_pid_notifyf( int pid, int unset_environment, const char * format, ... );
#pod
#pod
#pod See L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> for details.
#pod
#pod The binding for C<sd_pid_notify_with_fds> function is not yet implemented.
#pod
#pod The bindings for C<sd_notifyf> and C<sd_pid_notifyf> will not be implemented likely. These
#pod C<printf>-like functions accept format string and variable argument list. They are quite convenient
#pod in C, but in Perl they do not have much value — they may be easily replaced either by string
#pod interpolation and/or by using C<sprintf> function, e. g.:
#pod
#pod     sd_notify( 0, "STATUS=Done $percent\%.\n" );
#pod     sd_notify( 0, sprintf( "STATUS=Done %03d\%.\n", $percent ) );

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

#pod     }
#pod
#pod Such implementation is not included into C<Systemd::Daemon::XS> because it is not a binding to
#pod C<libsystemd>.
#pod
#pod =func sd_booted
#pod
#pod     int sd_booted();
#pod
#pod
#pod See L<sd_booted(3)|http://www.freedesktop.org/software/systemd/man/sd_booted.html>.
#pod
#pod =func sd_is_fifo
#pod
#pod =func sd_is_mq
#pod
#pod =func sd_is_socket
#pod
#pod =func sd_is_socket_inet
#pod
#pod =func sd_is_socket_unix

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

#pod =func sd_is_special
#pod
#pod     int sd_is_fifo( int fd, const char * path );
#pod     int sd_is_mq( int fd, const char * path );
#pod     int sd_is_socket( int fd, int family, int type, int listening );
#pod     int sd_is_socket_inet( int fd, int family, int type, int listening, uint16_t port );
#pod     int sd_is_socket_unix( int fd, int family, int type, int listening, const char * path, size_t length );
#pod     int sd_is_special( int fd, const char * path );
#pod
#pod
#pod See L<sd_is_fifo(3)|http://www.freedesktop.org/software/systemd/man/sd_is_fifo.html>.
#pod
#pod =func sd_watchdog_enabled
#pod
#pod     // int sd_watchdog_enabled( int unset_environment, uint64_t * usec );
#pod
#pod
#pod See L<sd_watchdog_enabled(3)|http://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html>.
#pod
#pod The binding for C<sd_watchdog_enabled> function is not yet implemented.
#pod
#pod =cut

#pod =head1 CONSTANTS
#pod
#pod Constants described below are not traditional 0-ary functions created by C<constant> pragma, but
#pod immutable variables created by C<Readonly> module, so you have to use sigils but can interpolate
#pod constants to strings.

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

#pod
#pod =const $SD_ERR
#pod
#pod =const $SD_INFO
#pod
#pod =const $SD_NOTICE
#pod
#pod =const $SD_WARNING
#pod
#pod
#pod See L<sd-daemon(3)|http://www.freedesktop.org/software/systemd/man/sd-daemon.html>.
#pod
#pod =const $SD_LISTEN_FDS_START
#pod
#pod
#pod See L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.
#pod
#pod =cut

use Readonly;
our $SD_LISTEN_FDS_START; Readonly $SD_LISTEN_FDS_START => 3;
our $SD_ALERT; Readonly $SD_ALERT => '<1>';
our $SD_CRIT; Readonly $SD_CRIT => '<2>';
our $SD_DEBUG; Readonly $SD_DEBUG => '<7>';
our $SD_EMERG; Readonly $SD_EMERG => '<0>';
our $SD_ERR; Readonly $SD_ERR => '<3>';

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

        return $name => \${ $name };
    } else {
        return $class->SUPER::_exporter_expand_sub( @_ );
    };
};


#pod =head1 SEE ALSO
#pod
#pod =for :list
#pod *   L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>
#pod *   L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html>
#pod *   L<sd_booted(3)|http://www.freedesktop.org/software/systemd/man/sd_booted.html>
#pod *   L<sd_is_fifo(3)|http://www.freedesktop.org/software/systemd/man/sd_is_fifo.html>
#pod *   L<sd_watchdog_enabled(3)|http://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html>
#pod *   L<Exporter::Tiny>
#pod *   L<Readonly>
#pod
#pod =head1 COPYRIGHT AND LICENSE
#pod
#pod Copyright (C) 2015 Van de Bugger
#pod
#pod License GPLv3+: The GNU General Public License version 3 or later
#pod <http://www.gnu.org/licenses/gpl-3.0.txt>.
#pod

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

=head2 $SD_EMERG

=head2 $SD_ERR

=head2 $SD_INFO

=head2 $SD_NOTICE

=head2 $SD_WARNING

See L<sd-daemon(3)|http://www.freedesktop.org/software/systemd/man/sd-daemon.html>.

=head2 $SD_LISTEN_FDS_START

See L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.

=head1 FUNCTIONS

=head2 sd_listen_fds

    int sd_listen_fds( int unset_environment );

See L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>.

=head2 sd_notify

=head2 sd_notifyf

=head2 sd_pid_notify

=head2 sd_pid_notify_with_fds

=head2 sd_pid_notifyf

    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 L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html> for details.

The binding for C<sd_pid_notify_with_fds> function is not yet implemented.

The bindings for C<sd_notifyf> and C<sd_pid_notifyf> will not be implemented likely. These
C<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 C<sprintf> function, e. g.:

    sd_notify( 0, "STATUS=Done $percent\%.\n" );
    sd_notify( 0, sprintf( "STATUS=Done %03d\%.\n", $percent ) );

lib/Systemd/Daemon/XS.pm  view on Meta::CPAN

        return sd_notify( shift( @_ ), sprintf( @_ ) );
    }

Such implementation is not included into C<Systemd::Daemon::XS> because it is not a binding to
C<libsystemd>.

=head2 sd_booted

    int sd_booted();

See L<sd_booted(3)|http://www.freedesktop.org/software/systemd/man/sd_booted.html>.

=head2 sd_is_fifo

=head2 sd_is_mq

=head2 sd_is_socket

=head2 sd_is_socket_inet

=head2 sd_is_socket_unix

=head2 sd_is_special

    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 L<sd_is_fifo(3)|http://www.freedesktop.org/software/systemd/man/sd_is_fifo.html>.

=head2 sd_watchdog_enabled

    // int sd_watchdog_enabled( int unset_environment, uint64_t * usec );

See L<sd_watchdog_enabled(3)|http://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html>.

The binding for C<sd_watchdog_enabled> function is not yet implemented.

=for test_synopsis my ( $pid );

=head1 SEE ALSO

=over 4

=item *

L<sd_listen_fds(3)|http://www.freedesktop.org/software/systemd/man/sd_listen_fds.html>

=item *

L<sd_notify(3)|http://www.freedesktop.org/software/systemd/man/sd_notify.html>

=item *

L<sd_booted(3)|http://www.freedesktop.org/software/systemd/man/sd_booted.html>

=item *

L<sd_is_fifo(3)|http://www.freedesktop.org/software/systemd/man/sd_is_fifo.html>

=item *

L<sd_watchdog_enabled(3)|http://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html>

=item *

L<Exporter::Tiny>

=item *

L<Readonly>

=back



( run in 0.372 second using v1.01-cache-2.11-cpan-299005ec8e3 )