1SD_BUS_NEW(3)                     sd_bus_new                     SD_BUS_NEW(3)
2
3
4

NAME

6       sd_bus_new, sd_bus_ref, sd_bus_unref, sd_bus_unrefp,
7       sd_bus_close_unref, sd_bus_close_unrefp, sd_bus_flush_close_unref,
8       sd_bus_flush_close_unrefp - Create a new bus object and create or
9       destroy references to it
10

SYNOPSIS

12       #include <systemd/sd-bus.h>
13
14       int sd_bus_new(sd_bus **bus);
15
16       sd_bus *sd_bus_ref(sd_bus *bus);
17
18       sd_bus *sd_bus_unref(sd_bus *bus);
19
20       sd_bus *sd_bus_close_unref(sd_bus *bus);
21
22       sd_bus *sd_bus_flush_close_unref(sd_bus *bus);
23
24       void sd_bus_unrefp(sd_bus **busp);
25
26       void sd_bus_close_unrefp(sd_bus **busp);
27
28       void sd_bus_flush_close_unrefp(sd_bus **busp);
29

DESCRIPTION

31       sd_bus_new() creates a new bus object. This object is
32       reference-counted, and will be destroyed when all references are gone.
33       Initially, the caller of this function owns the sole reference and the
34       bus object will not be connected to any bus. To connect it to a bus,
35       make sure to set an address with sd_bus_set_address(3) or a related
36       call, and then start the connection with sd_bus_start(3).
37
38       In most cases, it is a better idea to invoke sd_bus_default_user(3),
39       sd_bus_default_system(3) or related calls instead of the more low-level
40       sd_bus_new() and sd_bus_start(). The higher-level calls not only
41       allocate a bus object but also start the connection to a well-known bus
42       in a single function invocation.
43
44       sd_bus_ref() increases the reference counter of bus by one.
45
46       sd_bus_unref() decreases the reference counter of bus by one. Once the
47       reference count has dropped to zero, bus is destroyed and cannot be
48       used anymore, so further calls to sd_bus_ref() or sd_bus_unref() are
49       illegal.
50
51       sd_bus_unrefp() is similar to sd_bus_unref() but takes a pointer to a
52       pointer to an sd_bus object. This call is useful in conjunction with
53       GCC's and LLVM's Clean-up Variable Attribute[1]. Note that this
54       function is defined as inline function. Use a declaration like the
55       following, in order to allocate a bus object that is freed
56       automatically as the code block is left:
57
58           {
59             __attribute__((cleanup(sd_bus_unrefp)) sd_bus *bus = NULL;
60             int r;
61             ...
62             r = sd_bus_default(&bus);
63             if (r < 0)
64               fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r));
65             ...
66           }
67
68       sd_bus_ref() and sd_bus_unref() execute no operation if the passed in
69       bus object address is NULL.  sd_bus_unrefp() will first dereference its
70       argument, which must not be NULL, and will execute no operation if that
71       is NULL.
72
73       sd_bus_close_unref() is similar to sd_bus_unref(), but first executes
74       sd_bus_close(3), ensuring that the connection is terminated before the
75       reference to the connection is dropped and possibly the object freed.
76
77       sd_bus_flush_close_unref() is similar to sd_bus_unref(), but first
78       executes sd_bus_flush(3) as well as sd_bus_close(3), ensuring that any
79       pending messages are synchronously flushed out before the reference to
80       the connection is dropped and possibly the object freed. This call is
81       particularly useful immediately before exiting from a program as it
82       ensures that any pending outgoing messages are written out, and
83       unprocessed but queued incoming messages released before the connection
84       is terminated and released.
85
86       sd_bus_close_unrefp() is similar to sd_bus_close_unref(), but may be
87       used in GCC's and LLVM's Clean-up Variable Attribute, see above.
88       Similarly, sd_bus_flush_close_unrefp() is similar to
89       sd_bus_flush_close_unref().
90

RETURN VALUE

92       On success, sd_bus_new() returns 0 or a positive integer. On failure,
93       it returns a negative errno-style error code.
94
95       sd_bus_ref() always returns the argument.
96
97       sd_bus_unref() and sd_bus_flush_close_unref() always return NULL.
98
99   Errors
100       Returned errors may indicate the following problems:
101
102       -ENOMEM
103           Memory allocation failed.
104

NOTES

106       These APIs are implemented as a shared library, which can be compiled
107       and linked to with the libsystemd pkg-config(1) file.
108

SEE ALSO

110       systemd(1), sd-bus(3), sd_bus_default_user(3),
111       sd_bus_default_system(3), sd_bus_open_user(3), sd_bus_open_system(3),
112       sd_bus_close(3)
113

NOTES

115        1. Clean-up Variable Attribute
116           https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
117
118
119
120systemd 243                                                      SD_BUS_NEW(3)
Impressum