Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v255 batch #370

Merged
merged 99 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
aacffcc
meson: fix installation of html doc aliases
fbuihuu Jan 30, 2024
c15b855
network: fix typo
yuwata Feb 9, 2024
67f2821
network: do not bring down a bonding port interface when it is alread…
yuwata Feb 2, 2024
4076adc
test-network: add test case for issue #31165
yuwata Feb 2, 2024
576604a
wait-online: by default not all interface need to be online
yuwata Feb 2, 2024
095b0ec
network/dhcp4: disable IPv6OnlyMode= by default
yuwata Feb 4, 2024
b08b89e
login/user-runtime-dir: properly check for mount point
YHNdnzj Feb 4, 2024
4fc2ce0
executor: really set POSIX_SPAWN_SETSIGDEF for posix_spawn
bluca Feb 5, 2024
3411bcf
copy: do not ignore chattr_flags and friends passed to copy_file_atom…
yuwata Feb 8, 2024
3395aed
core: escape spaces when serializing as well
mrc0mmand Feb 12, 2024
a9f1b20
network/dhcp6: deem DHCPv6 configuration to be finished even if no IA…
yuwata Feb 16, 2024
42edf6e
network: do not request DHCP addresses configured on checking prefix …
yuwata Feb 16, 2024
ff09a84
test-network: split test_dhcp6pd() into small pieces
yuwata Feb 16, 2024
a3a176a
test-network: add one more test case for DHCP prefix delegation
yuwata Feb 16, 2024
a56b549
sd-radv: fix potential buffer overflow
yuwata Feb 19, 2024
32e05d4
core/exec: do not crash with UtmpMode=user without User= setting
yuwata Feb 19, 2024
839cae8
test: add a test for #31384
dtardon Feb 16, 2024
b9b9da8
gpt-auto-generator: fix argument passed to `parse_image_policy_argument`
aafeijoo-suse Feb 19, 2024
495d69f
Fallback from pidfd_open on permission errors too
bluca Feb 23, 2024
d8c23c7
efi: de-inline xmalloc to fix build failure with gcc 12.2 and -O2
bluca Feb 22, 2024
2a80f4a
resolved: limit the number of signature validations in a transaction
rpigott Feb 25, 2024
ff6ead0
resolved: reduce the maximum nsec3 iterations to 100
rpigott Feb 25, 2024
f8f72da
test: skip TEST-43-PRIVATEUSER-UNPRIV if unprivileged userns is restr…
enr0n Jan 12, 2024
d7c4a7d
bus-socket: Clarify that inotify is supposed to watch all components
DaanDeMeyer Jan 15, 2024
60a9b6d
udev: even if a device is a zac device, scsi-$ID_SERIAL will be reser…
YoruStar Jan 16, 2024
7b2f2bf
ci: install python3-pytest for ukify tests
mrc0mmand Jan 16, 2024
559370b
Restart the DHCPv4 client when max REQUEST attempts is reached
andresbeltranmsft Nov 21, 2023
d6d0a89
man: add more suggestions on how to use StartUnit and JobRemoved
bluca Jan 17, 2024
366cb2c
man: explicitly say that portable1's Attach/Detach are synchronous
bluca Jan 17, 2024
a922ff9
boot: don't print error if device tree fixup protocol isn't supported
craftyguy Jan 19, 2024
28e813d
bash-completion: add missing options to systemd-cryptenroll
aafeijoo-suse Jan 19, 2024
a50dc21
bash-completion: add missing options to systemd-dissect
aafeijoo-suse Jan 19, 2024
cd82f0a
test: skip a systemd-run test if unprivileged userns is restricted
enr0n Jan 18, 2024
fb15c80
man: clarify description of Attach/Detach flags
bluca Jan 19, 2024
06d767d
portable: log structured message when attach/detach succeeds
bluca Jan 18, 2024
ea8702d
core: path: Re-enter waiting if target is deactivating
AdrianVovk Dec 30, 2023
15567e4
user-util: validate the right field
poettering Jan 19, 2024
f3d7a88
bootctl: return earlier with `--print-esp-path`
aafeijoo-suse Jan 23, 2024
52a5ed3
test-execute: skip tests that are broken without unprivileged userns
enr0n Jan 18, 2024
6f7f589
repart: don't try to determine sector size from a disk image we shoul…
poettering Jan 23, 2024
7ed9d3c
docs/UID-GIDS: mention that ranges are actually configurable
keszybz Jan 9, 2024
7a29057
docs/UID-GIDS: use the modern spellings of pkg-config variables
keszybz Jan 9, 2024
dd932cb
cgroup: don't enable bpf pseudo-controllers when doing a wildcard del…
poettering Jan 24, 2024
3b30b43
sd-bus: fix exiting event loop when sd_bus_set_exit_on_disconnect is …
bluca Jan 25, 2024
82bb055
test: set -ex separately
mrc0mmand Jan 26, 2024
71489b7
man: add working example for sd_bus_set_watch_bind()
bluca Dec 13, 2023
19c5305
test: fix the container ID check
mrc0mmand Jan 26, 2024
042aea9
timesyncd: make the transmit timestamp in requests fully random
davidv1992 Jan 26, 2024
f85dbd3
Fix bug where systemd-tmpfiles gets stuck on fifos in tmp.
r-vdp Jan 29, 2024
9c866c6
conf-parser: fix OOM check
aafeijoo-suse Jan 30, 2024
d2e3dd8
mkosi: Stop using file provides with CentOS/Fedora
DaanDeMeyer Jan 30, 2024
2ff26aa
namespace: don't invoke loopback_setup() unless we allocate a CLONE_N…
poettering Jan 31, 2024
7b2c764
test-namespace: SOCK_CLOEXEC'ify all the things
poettering Jan 31, 2024
aeea0c5
core/exec-invoke: call pam_setcred(PAM_DELETE_CRED) after pam_close_s…
yuwata Jan 25, 2024
09138a5
pam: do not warn closing bus connection which is opened after the fork
yuwata Jan 21, 2024
a78a874
test: check pam warning message
yuwata Jan 21, 2024
9185375
man: fix default behavior of RequiredFamilyForOnline=
yuwata Feb 2, 2024
e83ceb8
nspawn: permit --ephemeral with --link-journal=try-* (treat as =no)
intelfx Jan 20, 2024
17a902b
cryptenroll: Fix reading keyfile from socket
Feb 2, 2024
b49086b
detect-virt: fix Google Compute Engine support
anthisfan Feb 8, 2024
24c9944
Install pacman in Arch Linux image
DaanDeMeyer Feb 9, 2024
0e73301
sysusers,tmpfiles: clarify error message for --replace
keszybz Dec 3, 2023
36f0ef8
test-69: send SIGTERM to ask systemd-nspawn to properly stop the cont…
fbuihuu Feb 8, 2024
4547adc
test: clean up the code a bit
mrc0mmand Feb 9, 2024
ef46182
core/service: make error msg match with conditions
YHNdnzj Jan 31, 2024
fdaabb5
man/systemd.service: document that Restart=always/on-success are refused
YHNdnzj Jan 31, 2024
94c18ee
firstboot: validate keymap entry
Feb 9, 2024
f17b9bd
missing: change our close_range() syscall wrapper to map glibc's
poettering Feb 12, 2024
1071fcf
btrfs-util: rework btrfs_is_nocow_fd() around fd_is_fs_type() + read_…
poettering Feb 12, 2024
b4d05e0
btrfs-util: use memdup_suffix0() instead of strndup() at one more place
poettering Feb 12, 2024
e335bf0
btrfs-util: apparently btrfs ioctls return unaligned data. deal with it.
poettering Feb 12, 2024
05d59d4
test: install systemd-boot in openSUSE test images
fbuihuu Feb 13, 2024
982fad7
test: make sure that sd-boot is installed before testing bootctl
fbuihuu Feb 13, 2024
7a6b484
test: make sure to install the filesystem package in the test image o…
fbuihuu Feb 14, 2024
48eee92
journald: when getting journal data via memfd, check flags are valid
poettering Feb 14, 2024
7de28dd
meson: do not attempt to install tests when they are disabled
bluca Feb 13, 2024
01b8c83
efi-loader: make efi_loader_get_entries() handling missing NUL termin…
poettering Feb 12, 2024
5b9a09d
Improve IgnoreSIGPIPE description
Winterhuman Feb 14, 2024
a58c060
keyring-util: Use reported key size to resize buf
AdrianVovk Feb 1, 2024
1a6b7d4
man: enchance sd_bus_set_watch_bind() example to handle one more failure
bluca Feb 14, 2024
59b7b55
fs-util: readlinkat() supports an empty string
yuwata Feb 14, 2024
76a80d4
chase: do not wrap xopenat() with RET_NERRNO()
yuwata Feb 15, 2024
df326cd
chattr-util: fix error code
yuwata Feb 15, 2024
4a58464
loop-util: fix error handling
yuwata Feb 15, 2024
c1160ca
test: always try to install the ext4 module
mrc0mmand Feb 14, 2024
7ac1922
test: make TEST-08-INITRD slightly less annoying to debug
mrc0mmand Feb 14, 2024
ffe2c6c
test: use btrfs' mkswapfile on btrfs
mrc0mmand Feb 14, 2024
7b834b1
test: don't abbreviate log messages when dumping the test journal
mrc0mmand Feb 16, 2024
2eb5d63
test: "modernize" TEST-55-OOMD's init
mrc0mmand Feb 16, 2024
b87642f
Set SYSTEMD_LOG_LEVEL=info explicitly in test-sysusers
DaanDeMeyer Feb 19, 2024
bb33490
udev: String substitutions can be done in ENV, too
runiq Feb 19, 2024
527c4b8
test: support TEST_MATCH_* stuff in TEST-23-UNIT-FILE as well
mrc0mmand Feb 19, 2024
8a7a160
missing_fcntl: Fix RAW_O_LARGEFILE
AdrianVovk Feb 20, 2024
4b11fd0
test: temporarily enable session lingering for the test user #2
mrc0mmand Feb 21, 2024
bee2f20
tree-wide: be more careful when passing literal integers to "t" bus m…
poettering Feb 21, 2024
1a88460
test-ukify: skip signing in tests when slow tests are disabled
keszybz Feb 22, 2024
d7f71e4
test-nss-hosts: treat negative host lookup as slow
keszybz Feb 22, 2024
bd3a510
detect-virt: allow detection via device-tree on RISC-V
xypron Feb 23, 2024
b97a999
detect-virt: allow detection via SMBIOS on RISC-V
xypron Feb 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ADDITIONAL_DEPS=(
python3-pefile
python3-pyelftools
python3-pyparsing
python3-pytest
rpm
zstd
)
Expand Down
20 changes: 20 additions & 0 deletions catalog/systemd.catalog.in
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,23 @@ Compatibility support for System V services in systemd is deprecated. Please
make sure to update the package in question to provide proper, native systemd
unit files. Contact vendor if necessary. Compatibility support for System V
services is deprecated and will be removed soon.

-- 187c62eb1e7f463bb530394f52cb090f
Subject: A Portable Service has been attached
Defined-By: systemd
Support: %SUPPORT_URL%
Documentation: https://systemd.io/PORTABLE_SERVICES/

A new Portable Service @PORTABLE_ROOT@ (with extensions: @PORTABLE_EXTENSION@) has
been attached to the system and is now available for use. The list of attached
Portable Services can be queried with 'portablectl list'.

-- 76c5c754d628490d8ecba4c9d042112b
Subject: A Portable Service has been detached
Defined-By: systemd
Support: %SUPPORT_URL%
Documentation: https://systemd.io/PORTABLE_SERVICES/

A Portable Service @PORTABLE_ROOT@ (with extensions: @PORTABLE_EXTENSION@) has been
detached from the system and is no longer available for use. The list of attached
Portable Services can be queried with 'portablectl list'.
32 changes: 16 additions & 16 deletions docs/UIDS-GIDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ validity for GIDs too.
In theory, the range of the C type `uid_t` is 32-bit wide on Linux,
i.e. 0…4294967295. However, four UIDs are special on Linux:

1. 0 → The `root` super-user
1. 0 → The `root` super-user.

2. 65534 → The `nobody` UID, also called the "overflow" UID or similar. It's
where various subsystems map unmappable users to, for example file systems
Expand Down Expand Up @@ -57,20 +57,20 @@ Distributions generally split the available UID range in two:

2. 1000…65533 and 65536…4294967294 → Everything else, i.e. regular (human) users.

Note that most distributions allow changing the boundary between system and
regular users, even during runtime as user configuration. Moreover, some older
systems placed the boundary at 499/500, or even 99/100. In `systemd`, the
boundary is configurable only during compilation time, as this should be a
decision for distribution builders, not for users. Moreover, we strongly
discourage downstreams to change the boundary from the upstream default of
999/1000.
Some older systems placed the boundary at 499/500, or even 99/100,
and some distributions allow the boundary between system and regular users to be changed
via local configuration.
In `systemd`, the boundary is configurable during compilation time
and is also queried from `/etc/login.defs` at runtime,
if the `-Dcompat-mutable-uid-boundaries=true` compile-time setting is used.
We strongly discourage downstreams from changing the boundary from the upstream default of 999/1000.

Also note that programs such as `adduser` tend to allocate from a subset of the
available regular user range only, usually 1000..60000. And it's also usually
user-configurable, too.
available regular user range only, usually 1000..60000.
This range can also be configured using `/etc/login.defs`.

Note that systemd requires that system users and groups are resolvable without
networking available — a requirement that is not made for regular users. This
network — a requirement that is not made for regular users. This
means regular users may be stored in remote LDAP or NIS databases, but system
users may not (except when there's a consistent local cache kept, that is
available during earliest boot, including in the initrd).
Expand Down Expand Up @@ -155,15 +155,15 @@ The most important boundaries of the local system may be queried with
`pkg-config`:

```
$ pkg-config --variable=systemuidmax systemd
$ pkg-config --variable=system_uid_max systemd
999
$ pkg-config --variable=dynamicuidmin systemd
$ pkg-config --variable=dynamic_uid_min systemd
61184
$ pkg-config --variable=dynamicuidmax systemd
$ pkg-config --variable=dynamic_uid_max systemd
65519
$ pkg-config --variable=containeruidbasemin systemd
$ pkg-config --variable=container_uid_base_min systemd
524288
$ pkg-config --variable=containeruidbasemax systemd
$ pkg-config --variable=container_uid_base_max systemd
1878982656
```

Expand Down
4 changes: 2 additions & 2 deletions man/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ foreach tuple : manpages
output : htmlalias,
command : [ln, '-fs', html, '@OUTPUT@'])
if want_html
meson.add_install_script(sh, '-c', ln_s.format(html, docdir / 'html' / htmlalias))
meson.add_install_script(sh, '-c', ln_s.format(docdir / 'html' / html, docdir / 'html' / htmlalias))
p2 += link
endif
html_pages += link
Expand Down Expand Up @@ -155,7 +155,7 @@ foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directiv
output : htmlalias,
command : [ln, '-fs', html, '@OUTPUT@'])
if want_html
meson.add_install_script(sh, '-c', ln_s.format(html, docdir / 'html' / htmlalias))
meson.add_install_script(sh, '-c', ln_s.format(docdir / 'html' / html, docdir / 'html' / htmlalias))
p2 += link
endif
html_pages += link
Expand Down
15 changes: 9 additions & 6 deletions man/org.freedesktop.portable1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ node /org/freedesktop/portable1 {
<listitem><para>mkdir</para></listitem>
</itemizedlist>
Note that an image cannot be attached if a unit that it contains is already present
on the system.</para>
on the system. Note that this method returns only after all the listed operations are completed,
and due to the I/O involved it might take some time.</para>

<para><function>AttachImageWithExtensions()</function> attaches a portable image to the system.
This method is a superset of <function>AttachImage()</function> with the addition of
Expand All @@ -271,7 +272,9 @@ node /org/freedesktop/portable1 {
<itemizedlist>
<listitem><para>unlink</para></listitem>
</itemizedlist>
Note that an image cannot be detached if a unit that it contains is running.</para>
Note that an image cannot be detached if a unit that it contains is running. Note that this method
returns only after all the listed operations are completed, and due to the I/O involved it might take
some time.</para>

<para><function>DetachImageWithExtensions()</function> detaches a portable image from the system.
This method is a superset of <function>DetachImage()</function> with the addition of
Expand Down Expand Up @@ -307,11 +310,11 @@ node /org/freedesktop/portable1 {
<para>The <function>AttachImageWithExtensions()</function>,
<function>DetachImageWithExtensions()</function> and
<function>ReattachImageWithExtensions()</function> methods take in options as flags instead of
booleans to allow for extendability. <varname>SD_SYSTEMD_PORTABLE_FORCE_ATTACH</varname> will cause
safety checks that ensure the units are not running while the new image is attached or detached
to be skipped. <varname>SD_SYSTEMD_PORTABLE_FORCE_EXTENSION</varname> will cause the check that the
booleans to allow for extendability. <varname>SD_SYSTEMD_PORTABLE_FORCE_ATTACH</varname> will bypass
the safety checks that ensure the units are not running while the image is attached or detached.
<varname>SD_SYSTEMD_PORTABLE_FORCE_EXTENSION</varname> will bypass the check that ensures the
<filename>extension-release.<replaceable>NAME</replaceable></filename> file in the extension image
matches the image name to be skipped. They are defined as follows:</para>
matches the image name. They are defined as follows:</para>

<programlisting>
#define SD_SYSTEMD_PORTABLE_RUNTIME (UINT64_C(1) &lt;&lt; 0)
Expand Down
8 changes: 7 additions & 1 deletion man/org.freedesktop.systemd1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,13 @@ node /org/freedesktop/systemd1 {
and terminate all units that aren't dependencies of it. If <literal>ignore-dependencies</literal>, it
will start a unit but ignore all its dependencies. If <literal>ignore-requirements</literal>, it will
start a unit but only ignore the requirement dependencies. It is not recommended to make use of the
latter two options. On completion, this method returns the newly created job object.</para>
latter two options. On reply, if successful, this method returns the newly created job object
which has been enqueued for asynchronous activation. Callers that want to track the outcome of the
actual start operation need to monitor the result of this job. This can be achieved in a race-free
manner by first subscribing to the <function>JobRemoved()</function> signal, then calling
<function>StartUnit()</function> and using the returned job object to filter out unrelated
<function>JobRemoved()</function> signals, until the desired one is received, which will then carry
the result of the start operation.</para>

<para><function>StartUnitReplace()</function> is similar to <function>StartUnit()</function> but
replaces a job that is queued for one unit by a job for another unit.</para>
Expand Down
223 changes: 223 additions & 0 deletions man/sd_bus_service_reconnect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/* SPDX-License-Identifier: MIT-0 */

/* Implements a D-Bus service that automatically reconnects when the system bus is restarted.
*
* Compile with 'cc sd_bus_service_reconnect.c $(pkg-config --libs --cflags libsystemd)'
*
* To allow the program to take ownership of the name 'org.freedesktop.ReconnectExample',
* add the following as /etc/dbus-1/system.d/org.freedesktop.ReconnectExample.conf
* and then reload the broker with 'systemctl reload dbus':

<?xml version="1.0"?> <!--*-nxml-*-->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.freedesktop.ReconnectExample"/>
<allow send_destination="org.freedesktop.ReconnectExample"/>
<allow receive_sender="org.freedesktop.ReconnectExample"/>
</policy>

<policy context="default">
<allow send_destination="org.freedesktop.ReconnectExample"/>
<allow receive_sender="org.freedesktop.ReconnectExample"/>
</policy>
</busconfig>

*
* To get the property via busctl:
*
* $ busctl --user get-property org.freedesktop.ReconnectExample \
* /org/freedesktop/ReconnectExample \
* org.freedesktop.ReconnectExample \
* Example
* s "example"
*/

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>

#define _cleanup_(f) __attribute__((cleanup(f)))

#define check(x) ({ \
int _r = (x); \
errno = _r < 0 ? -_r : 0; \
printf(#x ": %m\n"); \
if (_r < 0) \
return EXIT_FAILURE; \
})

typedef struct object {
const char *example;
sd_bus **bus;
sd_event **event;
} object;

static int property_get(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {

object *o = userdata;

if (strcmp(property, "Example") == 0)
return sd_bus_message_append(reply, "s", o->example);

return sd_bus_error_setf(error,
SD_BUS_ERROR_UNKNOWN_PROPERTY,
"Unknown property '%s'",
property);
}

/* https://www.freedesktop.org/software/systemd/man/sd_bus_add_object.html */
static const sd_bus_vtable vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY(
"Example", "s",
property_get,
0,
SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_VTABLE_END
};

static int setup(object *o);

static int on_disconnect(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
check(setup((object *)userdata));
return 0;
}

/* Ensure the event loop exits with a clear error if acquiring the well-known service name fails */
static int request_name_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
if (!sd_bus_message_is_method_error(m, NULL))
return 1;

const sd_bus_error *error = sd_bus_message_get_error(m);

if (sd_bus_error_has_names(error, SD_BUS_ERROR_TIMEOUT, SD_BUS_ERROR_NO_REPLY))
return 1; /* The bus is not available, try again later */

printf("Failed to request name: %s\n", error->message);
object *o = userdata;
check(sd_event_exit(*o->event, -sd_bus_error_get_errno(error)));

return 1;
}

static int setup(object *o) {
/* If we are reconnecting, then the bus object needs to be closed, detached from
* the event loop and recreated.
* https://www.freedesktop.org/software/systemd/man/sd_bus_detach_event.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_close_unref.html
*/
if (*o->bus) {
check(sd_bus_detach_event(*o->bus));
*o->bus = sd_bus_close_unref(*o->bus);
}

/* Set up a new bus object for the system bus, configure it to wait for D-Bus to be available
* instead of failing if it is not, and start it. All the following operations are asyncronous
* and will not block waiting for D-Bus to be available.
* https://www.freedesktop.org/software/systemd/man/sd_bus_new.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_address.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_bus_client.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_negotiate_creds.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_watch_bind.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_set_connected_signal.html
* https://www.freedesktop.org/software/systemd/man/sd_bus_start.html
*/
check(sd_bus_new(o->bus));
check(sd_bus_set_address(*o->bus, "unix:path=/run/dbus/system_bus_socket"));
check(sd_bus_set_bus_client(*o->bus, 1));
check(sd_bus_negotiate_creds(*o->bus, 1, SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_EFFECTIVE_CAPS));
check(sd_bus_set_watch_bind(*o->bus, 1));
check(sd_bus_start(*o->bus));

/* Publish an interface on the bus, specifying our well-known object access
* path and public interface name.
* https://www.freedesktop.org/software/systemd/man/sd_bus_add_object.html
* https://dbus.freedesktop.org/doc/dbus-tutorial.html
*/
check(sd_bus_add_object_vtable(*o->bus,
NULL,
"/org/freedesktop/ReconnectExample",
"org.freedesktop.ReconnectExample",
vtable,
o));
/* By default the service is only assigned an ephemeral name. Also add a well-known
* one, so that clients know whom to call. This needs to be asynchronous, as
* D-Bus might not be yet available. The callback will check whether the error is
* expected or not, in case it fails.
* https://www.freedesktop.org/software/systemd/man/sd_bus_request_name.html
*/
check(sd_bus_request_name_async(*o->bus,
NULL,
"org.freedesktop.ReconnectExample",
0,
request_name_callback,
o));
/* When D-Bus is disconnected this callback will be invoked, which will
* set up the connection again. This needs to be asynchronous, as D-Bus might not
* yet be available.
* https://www.freedesktop.org/software/systemd/man/sd_bus_match_signal_async.html
*/
check(sd_bus_match_signal_async(*o->bus,
NULL,
"org.freedesktop.DBus.Local",
NULL,
"org.freedesktop.DBus.Local",
"Disconnected",
on_disconnect,
NULL,
o));
/* Attach the bus object to the event loop so that calls and signals are processed.
* https://www.freedesktop.org/software/systemd/man/sd_bus_attach_event.html
*/
check(sd_bus_attach_event(*o->bus, *o->event, 0));

return 0;
}

int main(int argc, char **argv) {
/* The bus should be relinquished before the program terminates. The cleanup
* attribute allows us to do it nicely and cleanly whenever we exit the
* block.
*/
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
object o = {
.example = "example",
.bus = &bus,
.event = &event,
};

/* Create an event loop data structure, with default parameters.
* https://www.freedesktop.org/software/systemd/man/sd_event_default.html
*/
check(sd_event_default(&event));

/* By default the event loop will terminate when all sources have disappeared, so
* we have to keep it 'occupied'. Register signal handling to do so.
* https://www.freedesktop.org/software/systemd/man/sd_event_add_signal.html
*/
check(sd_event_add_signal(event, NULL, SIGINT|SD_EVENT_SIGNAL_PROCMASK, NULL, NULL));
check(sd_event_add_signal(event, NULL, SIGTERM|SD_EVENT_SIGNAL_PROCMASK, NULL, NULL));

check(setup(&o));

/* Enter the main loop, it will exit only on sigint/sigterm.
* https://www.freedesktop.org/software/systemd/man/sd_event_loop.html
*/
check(sd_event_loop(event));

/* https://www.freedesktop.org/software/systemd/man/sd_bus_release_name.html */
check(sd_bus_release_name(bus, "org.freedesktop.ReconnectExample"));

return 0;
}
Loading
Loading