2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
6 <refentry id=
"sd_event_source_set_destroy_callback"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
10 <title>sd_event_source_set_destroy_callback
</title>
11 <productname>systemd
</productname>
15 <refentrytitle>sd_event_source_set_destroy_callback
</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_event_source_set_destroy_callback
</refname>
21 <refname>sd_event_source_get_destroy_callback
</refname>
22 <refname>sd_event_destroy_t
</refname>
24 <refpurpose>Define the callback function for resource cleanup
</refpurpose>
29 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
32 <funcdef>typedef int (*
<function>sd_event_destroy_t
</function>)
</funcdef>
33 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
37 <funcdef>int
<function>sd_event_source_set_destroy_callback
</function></funcdef>
38 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
39 <paramdef>sd_event_destroy_t
<parameter>callback
</parameter></paramdef>
43 <funcdef>int
<function>sd_event_source_get_destroy_callback
</function></funcdef>
44 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
45 <paramdef>sd_event_destroy_t *
<parameter>callback
</parameter></paramdef>
52 <title>Description
</title>
54 <para><function>sd_event_source_set_destroy_callback()
</function> sets
<parameter>callback
</parameter> as the
55 callback function to be called right before the event source object
<parameter>source
</parameter> is
56 deallocated. The
<parameter>userdata
</parameter> pointer from the event source object will be passed as the
57 <parameter>userdata
</parameter> parameter. This pointer can be set by an argument to the constructor functions, see
58 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>, or directly,
60 <citerefentry><refentrytitle>sd_event_source_set_userdata
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
61 This callback function is called even if
<parameter>userdata
</parameter> is
<constant>NULL
</constant>. Note that
62 this callback is invoked at a time where the event source object itself is already invalidated, and executing
63 operations or taking new references to the event source object is not permissible.
</para>
65 <para><function>sd_event_source_get_destroy_callback()
</function> returns the current callback
66 for
<parameter>source
</parameter> in the
<parameter>callback
</parameter> parameter.
</para>
70 <title>Return Value
</title>
72 <para>On success,
<function>sd_event_source_set_destroy_callback()
</function> returns
0 or a positive
73 integer. On failure, it returns a negative errno-style error code.
</para>
75 <para><function>sd_event_source_get_destroy_callback()
</function> returns positive if the destroy
76 callback function is set,
0 if not. On failure, returns a negative errno-style error code.
</para>
81 <para>Returned errors may indicate the following problems:
</para>
85 <term><constant>-EINVAL
</constant></term>
87 <listitem><para>The
<parameter>source
</parameter> parameter is
<constant>NULL
</constant>.
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>