Commit Graph
384 Commits
Author SHA1 Message Date
Daan De Meyer a14adac423 meson: drop libdl, threads, and librt dependencies
Our baseline glibc is 2.34, which merged libdl, libpthread (the
dependency('threads') target), and librt into libc. Empty .so/.a stubs
remain for backward compatibility with old binaries, but new builds
resolve dl_*, pthread_*, mq_*, timer_*, etc. directly from libc.
On musl the same libraries are likewise empty stubs.

Drop the libdl, threads, and librt entries from every meson.build, and
remove the now-stale 'Libs.private: -lrt -pthread' from libudev.pc.in
since both flags resolve to empty link-time stubs on glibc 2.34+ and
musl.

Verified with readelf -d that libsystemd.so, libudev.so, and systemd no
longer carry DT_NEEDED entries for libdl/libpthread/librt.
2026-05-18 21:17:38 +00:00
Daan De Meyer b2bfe5b474 tree-wide: Use our own macros instead of fabs()/fmax()/fmin()
To make this work, ABS() is made generic so it also works on
floats and doubles.

While at it, fold the __ABS_INTEGER indirection and the
assert_cc(sizeof(long long) == sizeof(intmax_t)) away. The previous
form switched between __builtin_llabs (clang) and __builtin_imaxabs
(gcc), with the assert keeping the two paths behaviorally identical
on every platform we build for. imaxabs was originally chosen because
intmax_t is conceptually the widest signed integer type the platform
exposes, but the _Generic ABS already casts to (long long) before the
call, so the extra width imaxabs could in theory carry was being
narrowed away immediately anyway. With both paths collapsed to
__builtin_llabs((long long) (a)), the size relationship between
long long and intmax_t is no longer relevant.

Also add explicit unsigned long long / unsigned long / unsigned int
cases that pass the argument through unchanged. The previous default
branch cast unsigned values to (long long); for values above LLONG_MAX
this reinterprets them as negative, and __builtin_llabs(LLONG_MIN) is
UB. Unsigned values are already non-negative, so passing them through
is both correct and avoids the narrowing. Smaller unsigned types
(unsigned char, unsigned short) still go through the default branch
but promote to int first and fit in long long losslessly.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 21:17:38 +00:00
Frantisek Sumsal 335cc8f39c timesync: verify the actual size of the received data
iov.iov_len doesn't change after calling recvmsg() so it remains set to
sizeof(ntpmsg), which makes the check for a short packet always false.
Let's fix that by checking the actual size of the received data instead.
2026-04-16 19:19:02 +01:00
Zbigniew Jędrzejewski-Szmek a28dbc9d88 timesyncd: drop obsolete privilege dropping code
systemd-timesyncd always runs as an unprivileged user via the service
file, so the code to resolve the systemd-timesync user, drop privileges
adjust file ownership/permissions, or even create the directory cannot
do anything useful and is unnecessary.

Follow-up for 00a415fc8f, which made
running under an unprivileged user unconditional.
2026-03-20 09:57:55 +01:00
Yu Watanabe 1b1799e9ba timesync: actually disables built-in fallback NTP servers when an empty string is specified
Follow-up for 3745770ae4.
Fixes #40621.
2026-02-16 09:53:03 +09:00
Yu Watanabe b0ca2ef264 timesync: return earlier when an empty string is specified 2026-02-16 09:51:36 +09:00
Yu Watanabe 1bb9306f1e timesync: rename have_fallbacks -> fallback_set 2026-02-16 09:50:46 +09:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Yu Watanabe 929ce35f8d meson: rework include_directories() and finding of tools (#39956)
This is a cleanup in preparation for later additions.
2025-12-02 20:07:37 +09:00
Zbigniew Jędrzejewski-Szmek 963bebd7b0 meson: add source dir to include_directories automatically
Quite often we need to specify include_directories('.'). Normally, meson
does this automatically, but we specify implicit_include_directories : false,
see 30d20907bd for an explanation.
Passing the include_directories argument through the template layers was rather
cumbersome. Let's simplify things by always including the directory of the
first source file. This makes the definitions simpler, at the cost of having an
unnecessary include directory in the list in some cases.

(Tests are excluded from this change, because they happen to not need this, but
also because some tests have source[0] which is a custom target, and we'd need
newer meson to support that.)
2025-12-01 15:35:22 +01:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Daan De Meyer 9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Zbigniew Jędrzejewski-Szmek 5220bb8c3f meson: automatically add 'extract' to 'sources'
In all cases, everything that we list in 'extract', we also list in
'sources'. We can simplify things by automatically appending the first
list to the second.

In the listings, move 'extract' key right below 'sources', since now
they are both "sources", just with slightly different meanings.
2025-11-20 10:03:48 +09:00
Daan De Meyer b8ee7c2206 tree-wide: Various forward header cleanups
- Make sure forward headers have the iwyu pragma to always keep them
- Make sure we always include the daemon specific forward header
  instead of shared-forward.h
- Remove shared-forward.h include where the daemon specific forward
  header is already included
2025-10-17 21:11:23 +09:00
Daan De Meyer f102bc3e5f tree-wide: Introduce sd-forward.h and shared-forward.h headers
Let's not leak details from src/shared and src/libsystemd into
src/basic, even though you can't actually do anything useful with
just forward declarations from src/shared.

The sd-forward.h header is put in src/libsystemd/sd-common as we
don't have a directory for shared internal headers for libsystemd
yet.

Let's also rename forward.h to basic-forward.h to keep things
self-explanatory.
2025-10-16 17:00:29 +02:00
Yu Watanabe 3cc725ca6b timesync: assume link NTP servers are unchanged on error and no servers registered yet
This also silences annoying debug message when networkd is not running,
in which case sd_network_get_ntp() returns -ENOENT.
2025-10-06 04:49:53 +09:00
Yu Watanabe a6b5e24746 timesync: drop redundant space 2025-10-06 04:49:53 +09:00
Lennart Poettering b7f6bdbbd3 service-util: add generic parser for runtime scope 2025-09-25 22:43:59 +02:00
Yu Watanabe 5918ba9c69 tree-wide: fix log messages: "Failed VERB" -> "Failed to VERB" 2025-07-22 03:05:33 +09:00
Yu Watanabe 10b0bc476b timesync,test: explicitly include sys/timex.h when struct timex is used
struct timex is defined by sys/timex.h -> bits/timex.h.
Glibc includes the header in time.h, but let's explicitly include it
when the struct is used.

Similar to 4f18ff2e29, but for sys/timex.h.
2025-07-07 12:44:18 +09:00
Yu Watanabe 4f18ff2e29 tree-wide: include unistd.h where necessary
We use symbols provided by unistd.h without including it. E.g.
open(), close(), read(), write(), access(), symlink(), unlink(), rmdir(),
fsync(), syncfs(), lseek(), ftruncate(), fchown(), dup2(), pipe2(),
getuid(), getgid(), gettid(), getppid(), pipe2(), execv(), _exit(),
environ, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, F_OK, and their
friends and variants, so on.

Currently, unistd.h is indirectly included mainly in the following two paths:
- through missing_syscall.h, which is planned to covert to .c file.
- through signal.h -> bits/sigstksz.h, which is new since glibc-2.34.
  Note, signal.h is included by sd-eevent.h. So, many source files
  indirectly include unistd.h if newer glibc is used.

Currently, our baseline on glibc is 2.31. We need to support glibc older
than 2.34, but unfortunately, we do not have any CI environments with
such old glibc. CIFuzz uses glibc-2.31, but it builds only fuzzers, and
many files are even not compiled.
2025-06-30 09:19:15 +02:00
Zbigniew Jędrzejewski-Szmek 13bdaad1d4 meson: adjust indentation 2025-06-28 17:18:35 +02:00
Zbigniew Jędrzejewski-Szmek 7d247d3cb8 meson: drop explicit custom_target names
[1] says:
> Since 0.60.0 the name argument is optional and defaults to the basename of
> the first output
We specify >= 0.62 as the supported version, so drop the duplicate name in all cases
where it is the same as outputs[0], i.e. almost all cases.

[1] https://mesonbuild.com/Reference-manual_functions.html#custom_target
2025-06-28 17:14:50 +02:00
Yu Watanabe ef27ebab08 Clean up more includes (#37527)
Split out of #37344
2025-05-21 19:43:39 +09:00
Jelle van der Waa 00299a80f7 sd-event: rename 's' -> 'ret' 2025-05-21 10:50:25 +02:00
Daan De Meyer 9301880442 timesync: Clean up includes
Split out of #37344.
2025-05-21 10:49:43 +02:00
Daan De Meyer a583b34416 meson: Extract more objects instead of compiling multiple times
Also, let's deflatten the lists of sources in preparation for the
next commit at the same time.

In systemctl, we split out systemctl-main.c to make sure the definition
of main() is in a separate object which allows us to extract the systemctl.c
object and link it in the fuzzer target without getting a multiple definition
error when linking.
2025-05-20 10:29:58 +02:00
Daan De Meyer 6350d2dbd9 meson: Extract objects instead of creating intermediate static libraries
Currently, when we want to add unit tests for code that is compiled into
an executable, we either compile the code at least twice (once for the
executable, and once for each test that uses it) or we create a static
library which is then used by both the executable and all the tests.

Both of these options are not ideal, compiling source files more than
once slows down the build for no reason and creating the intermediate
static libraries takes a lot of boilerplate.

Instead, let's use the extract_objects() method that meson exposes on
build targets. This allows us to extract the objects corresponding to
specific source files and use them in other executables. Because we
define all executables upfront into a dictionary, we integrate this into
the dictionary approach by adding two new fields:

- 'extract' takes a list of files for which objects should be extracted.
  The extracted objects are stored in a dict keyed by the executable name
  from which they were extracted.
- 'objects' takes the name of an executable from which the extracted
  objects should be added to the current executable.

One side effect of this approach is that we can't build test executables
anymore without building the main executable, so we stop building test
executables unless we're also building the main executable. This allows
us to switch to using subdir_done() in all of these subdirectories to skip
parsing them if the corresponding component is disabled.

These changes get me down from 2439 => 2403 ninja targets on a full rebuild
from scratch.
2025-05-12 13:35:50 +02:00
Daan De Meyer 76d62b63ef main-func: Reduce transitive includes
Let's move some logic from _DEFINE_MAIN_FUNCTION() and other places
in main-func.h into functions that we implement in main-func.c to
allow moving some included headers from the header to the .c file.
2025-05-06 10:07:27 +02:00
Daan De Meyer 792a8bfb8a daemon-util: Rename starting/stopping message constants
Currently, NOTIFY_READY from daemon-util.h conflicts with NOTIFY_READY
from NotifyState from service.h so let's rename the constants to avoid
the conflict.
2025-05-01 14:02:17 +02:00
Daan De Meyer 1cf40697e3 tree-wide: Sort includes
This was done by running a locally built clang-format with
https://github.com/llvm/llvm-project/pull/137617 and
https://github.com/llvm/llvm-project/pull/137840 applied on all .c
and .h files.
2025-04-30 09:30:51 +02:00
Daan De Meyer 44e86153d1 meson: Define our own clang-tidy target
meson's target has a few issues:
- Runs on all source files regardless if they're included in the
  build or not
- Doesn't have any dependencies on generated sources which means we
  have to do a full build first before we can run clang-tidy
- Doesn't allow us to pass any extra arguments

To work around these, let's define our own clang-tidy target instead
using llvm's run-clang-tidy script. Alongside the clang-tidy target,
let's start keeping track of all generated sources which we make the
clang-tidy target depend on. We also add a new target which will only
generate source files which is useful for setting up the source tree
for running code analysis against it.
2025-04-24 12:36:36 +02:00
Daan De Meyer 401a22bfc1 tree-wide: Make sure all headers are standalone
Let's make sure all of our headers include everything they require.
2025-04-23 10:33:38 +02:00
Daan De Meyer f82e233128 timesync: Remove circular header dependencies 2025-04-23 10:33:37 +02:00
Daan De Meyer 93a1f7921a basic: Stop including log.h in macro.h
Now that the necessary functions from log.h have been moved to macro.h,
we can stop including log.h in macro.h. This requires modifying source
files all over the tree to include log.h instead.
2025-04-18 14:19:15 +02:00
Yu Watanabe c7464843ad tree-wide: extend the comment about the issue in __convert_scm_timestamps() 2025-03-31 23:22:38 +09:00
Yu Watanabe 3cf6a3a3d4 tree-wide: check more log message format in log_struct() and friends
This introduce LOG_ITEM() macro that checks arbitrary formats in
log_struct().
Then, drop _printf_ attribute from log_struct_internal(), as it does not
help so much, and compiler checked only the first format string.

Hopefully, this silences false-positive warnings by Coverity.
2025-03-19 01:56:48 +09:00
Yu Watanabe d83bfdd5b0 timesync: add short comment for boolean argument 2025-02-25 13:45:07 +09:00
Yu Watanabe 9c999b53b9 timesync: drop meaningless boolean flag
The boolean flag is always true, as manager_save_time_and_rearm() is
called unconditionally.

Follow-up for 33e82f3ef3.
2025-02-25 13:39:46 +09:00
Yu Watanabe 2960a8cfe8 timesync: use event_reset_time_relative()
No functional change, just refactoring.
2025-02-25 13:29:34 +09:00
Mike Yuan 70923ed358 meson: enable -Wzero-as-null-pointer-constant
Support for C added in gcc 15:
https://github.com/gcc-mirror/gcc/commit/236c0829ee21a179c81b83f0d7f112ca23c47a4d
2025-01-16 02:26:56 +01:00
Mike Yuan 347eb8fbe3 tree-wide: remove unnecessary gcc >= 7 version check
Our baseline is gcc 8.4.
2025-01-16 02:26:56 +01:00
Integral ddb8a639d5 tree-wide: replace for loop with FOREACH_ELEMENT or FOREACH_ARRAY macros (#34893) 2024-10-26 07:10:22 +09:00
Lennart Poettering d7a6bb9891 tree-wide: make sigprocmask() changes more automatic
This tries to get rid of most manual sigprocmask() changes, in favour
of:

1. The SD_EVENT_SIGNAL_PROCMASK flag to sd_event_add_signal()
2. The sd_event_set_signal_exit() call for handling SIGTERM/SIGINT
3. Move masking of SIGWINCH into ptyfwd, out of nspawn/vmspawn/run

And while we are at it get rid of a bunch of event source fields whose
lifetime is bound to the sd_event object they belong to anyway, and make
use of the "floating" event source feature of sd-event instead.
2024-09-13 17:12:28 +02:00
Yu Watanabe 4a851db694 timesync: add support of basic command line options 2024-09-11 04:08:06 +09:00
Yu Watanabe 40108953c5 timesync: use BusObjectImplementation 2024-09-11 04:03:57 +09:00
Yu Watanabe b9f208643b timesync: make manager_is_connected() static 2024-09-06 10:21:07 +09:00
Yu Watanabe c58f4100cc timesync: downgrade log level about network configuration change
These message may be unnecessarily shown multiple times when e.g.
networkd is restarted, system is wakeup from suspend, and so on.

Closes #34262.
2024-09-06 10:20:48 +09:00
Mike Yuan ad501930d7 socket-util: make recvmsg_safe() handle MSG_TRUNC too
Also, unify MSG_TRUNC handling all across the codebase.
2024-09-04 18:51:44 +02:00
Zbigniew Jędrzejewski-Szmek e0c7c9a00d manager: add structured log message about clock bump
Requested in https://github.com/systemd/systemd/pull/33214#discussion_r1630251308.
Also, reword error messages a bit. When /usr/lib/clock-epoch was introduced,
"build time" stopped being acurate. Just say "epoch" instead.

The same message ID is used in the manager and timesyncd. The event is
essentially equivalent for the user, and it seems reasonable that to search for
both at the same time.

The catalog entry is dropped. It provided almost no additional information above
the message. When the same message ID is now applied to messages from PID1 and
timesyncd, and the clock can be both advanced and rewound, it becomes very hard
to make the catalog entry provide something useful, because catalog entries don't
allow conditionalization.
2024-06-15 16:54:37 +02:00