1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
7 <refentry id=
"sd_event_source_set_destroy_callback"
8 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
11 <title>sd_event_source_set_destroy_callback
</title>
12 <productname>systemd
</productname>
16 <refentrytitle>sd_event_source_set_destroy_callback
</refentrytitle>
17 <manvolnum>3</manvolnum>
21 <refname>sd_event_source_set_destroy_callback
</refname>
22 <refname>sd_event_source_get_destroy_callback
</refname>
23 <refname>sd_event_destroy_t
</refname>
25 <refpurpose>Define the callback function for resource cleanup.
</refpurpose>
30 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
33 <funcdef>typedef int (*
<function>sd_event_destroy_t
</function>)
</funcdef>
34 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
38 <funcdef>int
<function>sd_event_source_set_destroy_callback
</function></funcdef>
39 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
40 <paramdef>sd_event_destroy_t
<parameter>callback
</parameter></paramdef>
44 <funcdef>int
<function>sd_event_source_get_destroy_callback
</function></funcdef>
45 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
46 <paramdef>sd_event_destroy_t *
<parameter>callback
</parameter></paramdef>
53 <title>Description
</title>
55 <para><function>sd_event_source_set_destroy_callback()
</function> sets
<parameter>callback
</parameter> as the
56 callback function to be called right before the event source object
<parameter>source
</parameter> is
57 deallocated. The
<parameter>userdata
</parameter> pointer from the event source object will be passed as the
58 <parameter>userdata
</parameter> parameter. This pointer can be set by an argument to the constructor functions, see
59 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>, or directly,
61 <citerefentry><refentrytitle>sd_event_source_set_userdata
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
62 This callback function is called even if
<parameter>userdata
</parameter> is
<constant>NULL
</constant>. Note that
63 this callback is invoked at a time where the event source object itself is already invalidated, and executing
64 operations or taking new references to the event source object is not permissible.
</para>
66 <para><function>sd_event_source_get_destroy_callback()
</function> returns the current callback
67 for
<parameter>source
</parameter> in the
<parameter>callback
</parameter> parameter.
</para>
71 <title>Return Value
</title>
73 <para>On success,
<function>sd_event_source_set_destroy_callback()
</function> returns
0 or a positive integer. On
74 failure, it returns a negative errno-style error code.
</para>
76 <para><function>sd_event_source_get_destroy_callback()
</function> returns positive if the destroy callback function
77 is set,
0 if not. On failure, returns a negative errno-style error code.
</para>
83 <para>Returned errors may indicate the following problems:
</para>
87 <term><constant>-EINVAL
</constant></term>
89 <listitem><para>The
<parameter>source
</parameter> parameter is
<constant>NULL
</constant>.
</para></listitem>
94 <xi:include href=
"libsystemd-pkgconfig.xml" />
97 <title>See Also
</title>
100 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
101 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
102 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
103 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
104 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
105 <citerefentry><refentrytitle>sd_event_add_child
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
106 <citerefentry><refentrytitle>sd_event_add_inotify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
107 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
108 <citerefentry><refentrytitle>sd_event_source_set_userdata
</refentrytitle><manvolnum>3</manvolnum></citerefentry>