]> git.ipfire.org Git - thirdparty/systemd.git/blame - docs/ARCHITECTURE.md
docs: add ARCHITECTURE.md with code map
[thirdparty/systemd.git] / docs / ARCHITECTURE.md
CommitLineData
2ecce1f1
LB
1---
2title: systemd repository architecture
3category: Contributing
4layout: default
5---
6
7# Code Map
8
9This section will attempt to provide a high-level overview of the various
10components of the systemd repository.
11
12# Source Code
13
14Directories in `src/` provide the implementation of all daemons, libraries and
15command-line tools shipped by the project. There are many, and more are
16constantly added, so we will not enumerate them all here - the directory
17names are self-explanatory.
18
19## Shared Code
20
21You might wonder what kind of common code belongs in `src/shared/` and what
22belongs in `src/basic/`. The split is like this: anything that is used to
23implement the public shared object we provide (sd-bus, sd-login, sd-id128,
24nss-systemd, nss-mymachines, nss-resolve, nss-myhostname, pam_systemd), must
25be located in `src/basic` (those objects are not allowed to link to
26libsystemd-shared.so). Conversely, anything which is shared between multiple
27components and does not need to be in `src/basic/`, should be in
28`src/shared/`.
29
30To summarize:
31
32`src/basic/`
33- may be used by all code in the tree
34- may not use any code outside of `src/basic/`
35
36`src/libsystemd/`
37- may be used by all code in the tree, except for code in `src/basic/`
38- may not use any code outside of `src/basic/`, `src/libsystemd/`
39
40`src/shared/`
41- may be used by all code in the tree, except for code in `src/basic/`,
42`src/libsystemd/`, `src/nss-*`, `src/login/pam_systemd.*`, and files under
43`src/journal/` that end up in `libjournal-client.a` convenience library.
44- may not use any code outside of `src/basic/`, `src/libsystemd/`, `src/shared/`
45
46## PID 1
47
48Code located in `src/core/` implements the main logic of the systemd system (and user)
49service manager.
50
51BPF helpers written in C and used by PID 1 can be found under `src/core/bpf/`.
52
53## UDEV
54
55Sources for the udev daemon and command-line tool (single binary) can be found under
56`src/udev/`.
57
58## Unit Tests
59
60Source files found under `src/test/` implement unit-level testing, mostly for
61modules found in `src/basic/` and `src/shared/`, but not exclusively. Each test
62file is compiled in a standalone binary that can be run to exercise the
63corresponding module. While most of the tests can be ran by any user, some
64require privileges, and will attempt to clearly log about what they need
65(mostly in the form of effective capabilities). These tests are self-contained,
66and generally safe to run on a host without side effects.
67
68Ideally, every module in `src/basic/` and `src/shared/` should have a corresponding
69unit test under `src/test/`, which exercises every helper function.
70
71# Integration Tests
72
73Sources in `test/` implement system-level testing for executables, libraries and
74daemons that are shipped by the project. They require privileges to run, and
75are not safe to execute directly on a host. By default they will build an image
76and run the test under it via `QEMU` or `systemd-nspawn`.
77
78Most of those tests should be able to run via `systemd-nspawn`, which is orders of
79magnitude faster than `QEMU`, but some tests require privileged operations like
80using `dm-crypt` or `loopdev`. They are clearly marked if that is the case.
81
82See `test/README.testsuite` for more specific details.
83
84# HWDB
85
86Rules built in the static `HWDB` database shipped by the project can be found
87under `hwdb.d/`. Some of these files are updated automatically, some are filled
88by contributors.
89
90# Documentation
91
92## systemd.io
93
94Markdown files found under `docs/` are automatically published on the
95[systemd.io](https://systemd.io) website using Github Pages. A minimal unit test
96to ensure the formatting doesn't have errors is included in the
97`meson test -C build/ github-pages` run as part of the CI.
98
99## MAN pages
100
101Manpages for binaries and libraries, and the DBUS interfaces, can be found under
102`man/` and should ideally be kept in sync with changes to the corresponding
103binaries and libraries.
104
105## Translations
106
107Translations files for binaries and daemons, provided by volunteers, can be found
108under `po/` in the usual format. They are kept up to date by contributors and by
109automated tools.
110
111# System Configuration files and presets
112
113Presets (or templates from which they are generated) for various daemons and tools
114can be found under various directories such as `factory/`, `modprobe.d/`, `network/`,
115`presets/`, `rules.d/`, `shell-completion/`, `sysctl.d/`, `sysusers.d/`, `tmpfiles.d/`.
116
117# Utilities for Developers
118
119`tools/`, `coccinelle/`, `.github/`, `.semaphore/`, `.lgtm/`, `.mkosi/` host various
120utilities and scripts that are used by maintainers and developers. They are not
121shipped or installed.