1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
'\" t
.TH "SD_BUS_SEND" "3" "" "systemd 255" "sd_bus_send"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_bus_send, sd_bus_send_to, sd_bus_message_send \- Queue a D\-Bus message for transfer
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_bus_send('u
.BI "int sd_bus_send(sd_bus\ *" "bus" ", sd_bus_message\ *" "m" ", uint64_t\ *" "cookie" ");"
.HP \w'int\ sd_bus_send_to('u
.BI "int sd_bus_send_to(sd_bus\ *" "bus" ", sd_bus_message\ *" "m" ", const\ char\ *" "destination" ", uint64_t\ *" "cookie" ");"
.HP \w'int\ sd_bus_message_send('u
.BI "int sd_bus_message_send(sd_bus_message\ *" "m" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_send()\fR
queues the bus message object
\fIm\fR
for transfer\&. If
\fIbus\fR
is
\fBNULL\fR, the bus that
\fIm\fR
is attached to is used\&.
\fIbus\fR
only needs to be set when the message is sent to a different bus than the one it\*(Aqs attached to, for example when forwarding messages\&. If the output parameter
\fIcookie\fR
is not
\fBNULL\fR, it is set to the message identifier\&. This value can later be used to match incoming replies to their corresponding messages\&. If
\fIcookie\fR
is set to
\fBNULL\fR
and the message is not sealed,
\fBsd_bus_send()\fR
assumes the message
\fIm\fR
doesn\*(Aqt expect a reply and adds the necessary headers to indicate this\&.
.PP
Note that in most scenarios,
\fBsd_bus_send()\fR
should not be called directly\&. Instead, use higher level functions such as
\fBsd_bus_call_method\fR(3)
and
\fBsd_bus_reply_method_return\fR(3)
which call
\fBsd_bus_send()\fR
internally\&.
.PP
\fBsd_bus_send_to()\fR
is a shorthand for sending a message to a specific destination\&. It\*(Aqs main use case is to simplify sending unicast signal messages (signals that only have a single receiver)\&. It\*(Aqs behavior is similar to calling
\fBsd_bus_message_set_destination\fR(3)
followed by calling
\fBsd_bus_send()\fR\&.
.PP
\fBsd_bus_send()\fR/\fBsd_bus_send_to()\fR
will write the message directly to the underlying transport (e\&.g\&. kernel socket buffer) if possible\&. If the connection is not set up fully yet the message is queued locally\&. If the transport buffers are congested any unwritten message data is queued locally, too\&. If the connection has been closed or is currently being closed the call fails\&.
\fBsd_bus_process\fR(3)
should be invoked to write out any queued message data to the transport\&.
.PP
\fBsd_bus_message_send()\fR
is the same as
\fBsd_bus_send()\fR
but without the first and last argument\&.
\fBsd_bus_message_send(m)\fR
is equivalent to
\fBsd_bus_send(sd_bus_message_get_bus(m), m, NULL)\fR\&.
.SH "RETURN VALUE"
.PP
On success, these functions return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
The input parameter
\fIm\fR
is
\fBNULL\fR\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-EOPNOTSUPP\fR
.RS 4
The bus connection does not support sending file descriptors\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ECHILD\fR
.RS 4
The bus connection was allocated in a parent process and is being reused in a child process after
\fBfork()\fR\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ENOBUFS\fR
.RS 4
The bus connection\*(Aqs write queue is full\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ENOTCONN\fR
.RS 4
The input parameter
\fIbus\fR
is
\fBNULL\fR
or the bus is not connected\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ECONNRESET\fR
.RS 4
The bus connection was closed while waiting for the response\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ENOMEM\fR
.RS 4
Memory allocation failed\&.
.sp
Added in version 246\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_bus_send()\fR
and
\fBsd_bus_send_to()\fR
were added in version 246\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-bus\fR(3),
\fBsd_bus_call_method\fR(3),
\fBsd_bus_message_set_destination\fR(3),
\fBsd_bus_reply_method_return\fR(3),
\fBsd_bus_process\fR(3)
|