Commit Graph

7046 Commits

Author SHA1 Message Date
Yu Watanabe
38704f5dc9 include: update syscall list
open_tree_attr is since kernel 6.15-rc1:
c4a16820d9
2025-06-25 03:59:25 +09:00
Yu Watanabe
65a7665939 fs-util: use int for argument that takes F_OK and friends
access_nofollow() is a simple wrapper of faccessat(), and it is defined as
```
int faccessat(int dirfd, const char *pathname, int mode, int flags);
```
2025-06-25 03:59:25 +09:00
Yu Watanabe
4d0fe93cba fs-util: include fcntl.h in fs-util.h
fs-util.h provides access_nofollow() but it did not include neither
fcntl.h nor unistd.h, which define F_OK and friends. Hence we cannot use
the function without including one of the headers. Let's include fcntl.h
in fs-util.h, then we can use the function by simply including fs-util.h.
2025-06-25 03:59:25 +09:00
Yu Watanabe
118ac16b6e include: import kernel headers for several struct and enum definitions
- mempolicy.h for MPOL_DEFAULT and friends,
- sched/types.h for struct sched_attr,
- xattr.h for struct xattr_args.
2025-06-25 00:50:06 +09:00
Yu Watanabe
50cda6433b namespace-util: include sched.h
To make CLONE_NEWNS and friends defined, which is used by clone_flag_to_namespace_type().
2025-06-25 00:50:06 +09:00
Yu Watanabe
8227088e2b meson: sort file list 2025-06-25 00:50:06 +09:00
Yu Watanabe
fbf6836812 tree-wide: include missing_fs.h only where necessary
The additional definitions provided by the header are
- EXT4_IOC_RESIZE_FS, used in resize-fs.c,
- FILEID_KERNFS, used in cgroup-util.c and pidfd-util.c.

Let's drop the inclusion at other places.
2025-06-25 00:50:06 +09:00
Yu Watanabe
f117272f66 glob-util: drop unused _cleanup_globfree_ 2025-06-23 23:11:44 +09:00
Yu Watanabe
2a5f950e56 glob-util: rework safe_glob()
Currently, callers of safe_glob() set an empty glob_t or glob_t with
opendir func, and all other components are always zero.
So, let's introduce safe_glob_full() which optionally takes opendir
function, rather than glob_t, and returns result strv, rather than
storing results in glob_t.
Also, introduce safe_glob() which is a trivial wrapper of
safe_glob_full() without opendir func.

No functional change, just refactoring.
2025-06-23 23:11:44 +09:00
Valentin David
0dc39dffbd Use paths specified from environment variables for /etc configuration files
Some configuration files that need updates are directly under in /etc. To
update them atomically, we need write access to /etc. For Ubuntu Core this is
an issue as /etc is not writable. Only a selection of subdirectories can be
writable. The general solution is symlinks or bind mounts to writable places.
But for atomic writes in /etc, that does not work. So Ubuntu has had a patch
for that that did not age well.

Instead we would like to introduce some environment variables for alternate
paths.

 * SYSTEMD_ETC_HOSTNAME: /etc/hostname
 * SYSTEMD_ETC_MACHINE_INFO: /etc/machine-info
 * SYSTEMD_ETC_LOCALTIME: /etc/localtime
 * SYSTEMD_ETC_LOCALE_CONF: /etc/locale.conf
 * SYSTEMD_ETC_VCONSOLE_CONF: /etc/vconsole.conf
 * SYSTEMD_ETC_ADJTIME: /etc/adjtime

While it is for now expected that there is a symlink from the standard, we
still try to read them from that alternate path. This is important for
`/etc/localtime`, which is a symlink, so we cannot have an indirect symlink or
bind mount for it.

Since machine-id is typically written only once and not updated. This commit
does not cover it. An initrd can properly create it and bind mount it.
2025-06-23 15:32:11 +02:00
Yu Watanabe
cef4ec347f ioprio-util: move from basic/ to shared/
It is not used by libsystemd.
2025-06-19 19:08:45 +09:00
Yu Watanabe
d26faa3186 missing_network: IPPROTO_MPTCP is already defined in linux/in.h
And the header is already included through (our implementation of)
netinet/in.h, hence we can safely drop the definition here.
2025-06-19 19:08:45 +09:00
Yu Watanabe
92b64168f6 sd-lldp: replace ETHERTYPE_LLDP with ETH_P_LLDP
ETH_P_LLDP is defined in linux/if_ether.h.
2025-06-19 19:08:45 +09:00
Yu Watanabe
dbfe2faa48 port write_env_file() to label_os_pre() + teach firstboot a bit of relabelling (#37869)
This is a clean-up, and also addresses some of the points of #37857.
2025-06-19 18:03:12 +09:00
Lennart Poettering
ea71d34738 fd-util: move cmsg_close_all() to socket-util.[ch]
This call only makes sense on sockets, it's not a generic fd concept,
hence let's move this over.
2025-06-18 19:06:11 +09:00
Yu Watanabe
43aacae83a dirent-util: use getdents64() as is
This partially reverts e86a492ff0.

The function getdents64() was introduced in glibc-2.30, and our baseline
on glibc is 2.31. Hence, we can assume the function always exists.
The posix_getdents() wrapper was introduced for compatibility with musl.
However, even the latest release of musl does not provide posix_getdents()
yet. Also, even with musl, by defining _LARGEFILE64_SOURCE, we can get
getdents64() and struct dirent64. Hence, the wrapper is anyway not
necessary.
2025-06-18 10:45:49 +02:00
Yu Watanabe
abb99d3168 mallinfo-util: assume mallinfo() exists
The check existed for musl. Let's remove it, as we explicitly request glibc.

While removing the check, this also drops generic_mallinfo, introduces
a tiny converter from struct mallinfo to struct mallinfo2 if mallinfo2()
does not exist, and renames mallinfo-util.h to malloc.h.

With this change, we can drop many ifdefs and casts in .c files.
2025-06-18 10:45:27 +02:00
Lennart Poettering
3e5320e27d env-file: port write_env_file() to label_ops_pre()
Let's make more use of label_ops_pre()/label_ops_post(), and replace
write_env_file_label() by a flag to write_env_file().

This simplifies and normalizes the code.

This also makes one relevant change: it sets the new
WRITE_ENV_FILE_LABEL flag in firstboot.c when we write locale.conf,
where we previously did not (but should have). This should address one
detail of #37857.
2025-06-18 10:21:26 +02:00
Lennart Poettering
9ea5a6e7d6 fs-util: replace symlink_atomic_full_label() by a flag to symlinkat_atomic_full()
More porting work to label_ops_pre()/label_ops_post()

This also enables labelling of the /etc/localtime symlink in
systemd-firstboot, which should address one small facet of #37857
2025-06-18 10:21:25 +02:00
Daan De Meyer
4fe348cfdf cgroup-util: Always open cgroupv2 attribute files in O_NONBLOCK mode
As explained in https://lore.kernel.org/all/20250419183545.1982187-1-shakeel.butt@linux.dev/,
writing to memory.max or memory.high triggers synchronous memory reclaim
if the limit is lowered. This can end up taking nonnegligible amounts
of time, completely blocking pid1 from doing any other work while the
reclaim is ongoing.

To address this problem, the kernel going to add O_NONBLOCK semantics
to memory.max and memory.high. If the file is opened with O_NONBLOCK,
the synchronous memory reclaim is skipped and only triggered later
without blocking the process writing the file. Let's make sure we make
use of this by opening cgroupv2 attribute files with O_NONBLOCK.

We opt to do this for all cgroupv2 attribute files, to make sure that
if the same problem happens elsewhere in the future and is fixed in the
same way, we immediately take advantage of that fix without having to
make changes in systemd as well. We probably never want to block when
writing cgroupv2 attributes and any cases where we do want to block should
indicate so explicitly instead of blocking by default.
2025-06-17 15:07:32 +01:00
Lennart Poettering
ef3a0ed834 various: turn off SO_PASSRIGHTS where fds are not expected (#37759) 2025-06-17 15:37:35 +02:00
Mike Yuan
f66eeedf6f missing_socket: add SO_PASSRIGHTS 2025-06-17 13:16:42 +02:00
Mike Yuan
020d85c8e3 log: drop redundant forward decl
These are defined in forward.h already.
2025-06-17 11:44:50 +02:00
Mike Yuan
4c6fbe733b hostname-util: introduce machine_spec_valid() 2025-06-17 01:39:57 +02:00
Mike Yuan
d2e727bf68 hostname-util: do not allow empty machine spec
Follow-up for 2ae32e9d8f

Let's not open this up even further and rather disallow
--machine="".
2025-06-17 01:39:56 +02:00
Yu Watanabe
a4eb5094e6 terminal-util: fix doubled 'to' in log messages
Follow-up for 3390be38d1.
2025-06-16 22:25:27 +09:00
Mike Yuan
deedd5c26e terminal-util: modernize ptsname_malloc a bit 2025-06-16 20:08:52 +09:00
Mike Yuan
2a1338242d socket-util: drop duplicate SCM_MAX_FD definition
We already carry it in missing_socket.h
2025-06-16 12:16:03 +02:00
Yu Watanabe
38de38a70d ordered-set: introduce ordered_set_put_strdup_full() and friends which take hash ops 2025-06-14 00:06:43 +09:00
Yu Watanabe
361b13ca7e include/linux: update kernel headers from v6.16-rc1 2025-06-12 16:04:40 +01:00
Mike Yuan
d9bf815093 string-util: introduce strprepend_with_separator() 2025-06-11 12:50:51 +09:00
Yu Watanabe
58bb08be6d dirent-util: follow our coding style 2025-06-10 12:57:01 +09:00
Mike Yuan
0e9667fd9a basic/forward: replace tab with space 2025-06-09 20:39:23 +02:00
Yu Watanabe
4081e072ee Several follow-ups for recent header cleanups (#37785) 2025-06-10 01:01:05 +09:00
Yu Watanabe
169d270e81 meson: update generating lists
- config.h is not necessary when generating lists, hence drop it.
- linux/audit.h and libaudit.h are included by missing_audit.h,
  hence not necessary to include them explicitly.
2025-06-09 16:29:49 +01:00
Yu Watanabe
afe1567297 include: net/if.h requires features.h
The header uses __THROW, which is defined in features.h, to make the
header self-consistent.
Note, src/basic/include/sys/mount.h also uses __THROW, and includes
features.h.
2025-06-09 22:45:23 +09:00
Yu Watanabe
afcb6d671b forward: also include paths.h
It provides several important constants, especially _PATH_BSHELL, which
is used in PID1, executor, and run. The header has been included
indirectly through e.g. libmount.h, mntent.h, utmpx.h, and so on.
Let's explicitly include it in forward.h, as libmount.h and friends that
includes paths.h are irrelevant to _PATH_BSHELL, and we may easily fail
to build when code is touched.
The header is not heavy, hence should not hurt anything.
2025-06-09 22:45:23 +09:00
Daan De Meyer
1b4645d762 forward: Drop socklen_t forward declaration
This is glibc specific and doesn't exist on musl, since removing only
means adding one more include in selinux-util.h, let's drop it.

Fixes #37779
2025-06-08 10:58:56 +09:00
Lennart Poettering
1de31f23a0 conf-files: use proper enum for flags parameters 2025-06-06 09:04:38 +02:00
Lennart Poettering
4295c0db5f hostname-util: add new helper split_user_at_host()
Let's introduce a common helper for splitting user@host specifications
like we use them for --machine=.
2025-06-05 12:44:08 +02:00
Mike Yuan
a842c26be3 pidfd-util: extract pidfd_get_inode_id_impl() and make it thread safe
Preparation for later commits.
2025-06-05 00:28:01 +02:00
Mike Yuan
e09b7ced65 pidfd-util: open an internal pidfd if none is passed in pidfd_check_pidfs()
I'd like to introduce a libsystemd helper for acquiring pidfd
inode id, which however means the fd passed to pidfd_check_pidfs()
can no longer be trusted. Let's add back the logic of allocating
a genuine pidfd allocated internally, which was remove in
5dc9d5b4ea.
2025-06-05 00:28:01 +02:00
Lennart Poettering
4f4113ee33 sd-login: various modernizations (#37728) 2025-06-04 22:24:57 +02:00
Lennart Poettering
874c4beb24 io-util: protect against INT_MAX overflow in flush_fd() 2025-06-04 22:06:52 +02:00
Lennart Poettering
e74c1e1cac compress: get rid of a bunch of 'else' 2025-06-04 18:04:27 +02:00
Lennart Poettering
eac4a028df sd-login: modernize return parameter handling
Let's rename the return parameters as "ret_xyz" systematically in
sd-login.

Also, let's make the return parameters systematically optional, like we
typically do these days. So far some where optional, other's weren't.
Let's clean this up.
2025-06-04 17:58:42 +02:00
Jelle van der Waa
93117b0fbd cgroup-util: rename 'fsfd' -> 'cgroups_fd'
Makes the header and implementation consistent.
2025-06-04 10:45:54 +02:00
Lennart Poettering
d483ac1d0d compress: avoid a bunch of div-by-zeroes
Follow-up for #37706. Implements the same logic for all compression
algorithms we have.
2025-06-03 18:27:02 +02:00
Yu Watanabe
a491eca403 Bugprone argument comment 8 (#37678)
Follow up from https://github.com/systemd/systemd/pull/37556
2025-06-03 10:58:52 +09:00
Alex
2584f745e0 compress: prevent divide-by-zero when no data is read (#37706)
If the first call to `loop_read()` returns 0 (no input), `total_in`
remains 0, causing `total_out/total_in` to potential divide by zero.

We add a check before logging the compression ratio to skip the
percentage calculation when total_in is zero.

Co-authored-by: jinyaoguo <guo846@purdue.edu>
2025-06-03 10:51:00 +09:00