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 better to use 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 functions not only
41       allocate a bus object but also start the connection to a well-known bus
42       in a single function call.
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 an 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 argument is
69       NULL.  sd_bus_unrefp() will first dereference its argument, which must
70       not be NULL, and will execute no operation if that is NULL.
71
72       sd_bus_close_unref() is similar to sd_bus_unref(), but first executes
73       sd_bus_close(3), ensuring that the connection is terminated before the
74       reference to the connection is dropped and possibly the object freed.
75
76       sd_bus_flush_close_unref() is similar to sd_bus_unref(), but first
77       executes sd_bus_flush(3) as well as sd_bus_close(3), ensuring that any
78       pending messages are synchronously flushed out before the reference to
79       the connection is dropped and possibly the object freed. This call is
80       particularly useful immediately before exiting from a program as it
81       ensures that any pending outgoing messages are written out, and
82       unprocessed but queued incoming messages released before the connection
83       is terminated and released.
84
85       sd_bus_close_unrefp() is similar to sd_bus_close_unref(), but may be
86       used in GCC's and LLVM's Clean-up Variable Attribute, see above.
87       Similarly, sd_bus_flush_close_unrefp() is similar to
88       sd_bus_flush_close_unref().
89

RETURN VALUE

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

NOTES

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

SEE ALSO

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

NOTES

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