Commit Graph
42 Commits
Author SHA1 Message Date
Yu Watanabe 459000e8c5 errno-util: avoid double evaluation in STRERROR_OR_EOF()
Follow-up for f69ae8585f.
2025-11-20 09:04:35 +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
Zbigniew Jędrzejewski-Szmek 56631ac8df udev: downgrade ENOMEDIUM warnings
I noticed similar warnings in many VM boots:
  fedora (udev-worker)[475]: sr0: Failed to open device node: No medium found
This particular one is from src/udev/udev-builtin-uaccess.c:125, but I think the
same principle should be used in all places: if we are ignoring errors that the
device has been removed, we should also ignore ENOMEDIUM.
2025-07-24 10:42:50 +02:00
Yu Watanabe e28d408c6b errno-util: introduce ERRNO_IS_NEG_FS_WRITE_REFUSED() 2025-07-10 14:02:00 +09:00
Mike Yuan 5a881f7f71 errno-list: errno_from_name() is pure but not const
Follow-up for 0c15577abe
2025-05-26 20:24:43 +02:00
Daan De Meyer 0c15577abe basic + fundamental: Clean up includes
Split out of #37344.
2025-05-25 10:06:07 +02:00
Daan De Meyer 3b7d332047 macro: Reduce transitive includes 2025-05-09 11:33:31 +02:00
Mike Yuan c0239e5f11 macro: implement ABS via __builtin_imaxabs() 2025-05-06 17:39:01 +02:00
Daan De Meyer 40a6cdc29e macro: Introduce ABS() macro and use it in header files
abs() requires including the entirety of stdlib.h just for a single
trivial function. Let's introduce the ABS() macro and use it in header
files instead so we can get rid of stdlib.h transitive includes in header
files in a later commit.
2025-05-06 10:14:26 +02:00
Daan De Meyer 03e17cbe6e basic: Move assertion specific functions to assert-util.h
Various functions in log.h are only used by asserts, and there's
enough assertion related stuff in macro.h to justify a separate header
which also makes it easier to avoid circular dependencies.

Let's introduce assert-util.h and an accompanying fundamental header
and move all the assertion related stuff over there. PROJECT_FILE is
moved over to macro.h.
2025-04-18 13:59:06 +02:00
Mike Yuan 9a7b20b6a6 errno-util: add ERRNO_IS_IOCTL_NOT_SUPPORTED that checks EINVAL additionally 2025-01-04 17:07:58 +01:00
Lennart Poettering 47bb0b8c29 errno-util: consider ENOPROTOOPT another "not supported"
It's generated by not supported getsocktopt()/setsockopt() options, and
it's just another way for saying "not supported", hence treat it as
such.
2024-04-25 12:43:21 +02:00
Zbigniew Jędrzejewski-Szmek fe0feacb9e errno-util: allow ERRNO_IS_* to accept types wider than int
This is useful if the variable is ssize_t and we don't want to trigger a
warning or truncation.

With gcc (gcc-13.2.1-1.fc38.x86_64), the resulting systemd binary is identical,
so I assume that the compiler is able to completely optimize away the type.
2023-08-16 12:52:56 +02:00
Zbigniew Jędrzejewski-Szmek b0be985cdd basic/errno-util: add wrappers which only accept negative errno
We do 'IN_SET(r, -CONST1, -CONST2)', instead of 'IN_SET(-r, CONST1, CONST2)'
because -r is undefined if r is the minimum value (i.e. INT_MIN). But we know
that the constants are small, so their negative values are fine.
2023-08-16 12:52:56 +02:00
Zbigniew Jędrzejewski-Szmek 809c3a84e1 Introduce RET_GATHER and use it in src/shared/
The idea is to make it easier to implement the common pattern of
accumulating errors (negative values) in an accumulator to return
the first error.
2023-07-13 11:12:00 +02:00
Luca Boccassi da60182759 Merge pull request #24933 from keszybz/erradicate-strerror
Erradicate strerror
2022-10-11 21:47:38 +02:00
Zbigniew Jędrzejewski-Szmek 0cf1a4b3a7 Get rid of strerror_safe() 2022-10-11 16:59:00 +02:00
Zbigniew Jędrzejewski-Szmek f37508d506 tree-wide: get rid of lgtm annotations
We now use CodeQL, and LGTM itself is gone. Those old annotations are not
useful for anythign now.
2022-10-11 16:59:00 +02:00
Zbigniew Jędrzejewski-Szmek f69ae8585f tree-wide: define and use STRERROR_OR_EOF() 2022-10-11 16:58:21 +02:00
Zbigniew Jędrzejewski-Szmek 2c5d05b3cd basic: add STRERROR() wrapper for strerror_r() 2022-10-11 16:10:21 +02:00
Lennart Poettering 00675c363f tree-wide: add ERRNO_IS_XATTR_ABSENT() helper
We check the same list of error codes on various xattr operations, and
we should on some more. Add a common helper for this purpose.
2022-10-10 16:00:15 +02:00
Zbigniew Jędrzejewski-Szmek 50c5b991df basic/errno-util: add helper to protect and set errno in one step
This pattern is used in a few places. Those are changed in this patch.
Subsequent patches will add more.
2022-10-10 09:12:21 +02:00
Lennart Poettering 3f2ada89f3 errno-util: add ERRNO_IS_DEVICE_ABSENT() macro
Inspired by: https://github.com/systemd/systemd/pull/22717#discussion_r834254495
2022-03-24 16:19:48 +01:00
Yu Watanabe 7aad83580f errno-util: introduce ERRNO_IS_TRANSIENT() 2021-11-30 23:06:43 +09:00
Zbigniew Jędrzejewski-Szmek 1990bc64cd basic/errno-util: adjust indentation
It was bothering me that this backslash wasn't aligned with the
ones below.
2021-11-16 09:21:22 +01:00
Lennart Poettering ef470ffa23 macro: add new helper RET_NERRNO()
This new helper converts libc style syscall return values into
systemd-kernel (actually: kernel style) negative errno values.

It's implemented as macro-like inline function, and propagates return
values >= 0 as themselves and returns -errno for negative error returns.

THis is supposed to be little more than syntactic sugar so that we can
reduce a lot of (short, but still) boilerplate code whever we convert
libc style error handling into our own.

As discussed here:

https://github.com/systemd/systemd/pull/21326#discussion_r748413537
2021-11-16 08:04:09 +01:00
Luca Boccassi 82cdb75b8d errno-util: suppress LGTM warning about strerror 2021-04-08 13:08:38 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 8d50c14252 errno: ETIMEDOUT is also a connection error 2020-11-06 14:42:18 +01:00
Lennart Poettering 0648f9beb9 errno-util: let's beef up ERRNO_IS_NOT_SUPPORTED() with socket not supported errors 2020-04-17 16:05:56 +02:00
Lennart Poettering 9933a47808 errno-util: add new ERRNO_IS_DISK_SPACE() helper 2019-12-04 10:57:44 +01:00
Lennart Poettering e884e00071 errno-util: add ERRNO_IS_PRIVILEGE() helper 2019-11-20 12:29:54 +01:00
Lennart Poettering e6376b6a41 errno: add new ERRNO_IS_NOT_SUPPORTED() helper 2019-11-19 19:12:09 +01:00
Thomas Haller 6fd79cca68 errno-util: return const string from strerror_safe()
C's strerror() function does not return a "const char *" pointer
for the string. That has historic reasons and C99 even comments
that "[t]he array pointed to shall not be modified by the program".

Make the strerror_safe() wrapper correct this and be more strict
in this regard.
2019-07-26 18:42:49 +02:00
Lennart Poettering fed813778f errno-util: add new errno_or_else() helper 2019-07-11 23:20:31 +02:00
Yu Watanabe 4bbccb02ea tree-wide: introduce strerror_safe() 2019-07-05 02:43:56 +09:00
Lennart Poettering fb0302ddbc errno-util: add new ERRNO_IS_ACCEPT_AGAIN() test
This is modelled after the existing ERRNO_IS_RESOURCES() and in
particular ERRNO_IS_DISCONNECT(). It returns true for all transient
network errors that should be handled like EAGAIN whenever we call
accept() or accept4(). This is per documentation in the accept(2) man
page that explicitly says to do so in the its "RETURN VALUE" section.

The error list we cover is a bit more comprehensive, and based on
existing code of ours. For example EINTR is included too (since we need
that to cover cases where we call accept()/accept4() on a blocking
socket), and of course ERRNO_IS_DISCONNECT() is a bit more comprehensive
than the list in the man page too.
2019-04-10 20:03:38 +02:00
Lennart Poettering 7f00010601 errno-util: rework ERRNO_IS_RESOURCE() from macro into static inline function
No technical reason, except that later on we want to add a new
ERRNO_IS() which uses the parameter twice and where we want to avoid
double evaluation, and where we'd like to keep things in the same style.
2019-04-10 20:03:38 +02:00
Lennart Poettering 916a9ec7c6 errno-util: add three more error codes to ERRNO_IS_DISCONNECT()
This is based on the recommendations in accept4() and the listed error
codes there.
2019-04-10 20:03:38 +02:00
Lennart Poettering dd90e39cb6 util: add one more disconnect errno code 2019-03-19 15:39:07 +01:00
Lennart Poettering c3fecddf0d util: move ERRNO_IS_xyz macros to errno-util.h
It's where they fit much better.
2019-03-19 15:29:44 +01:00
Lennart Poettering 2b2fec7db0 util: split out errno related stuff 2019-03-14 13:25:51 +01:00