Commit Graph
95 Commits
Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 52abc9fe96 basic/stdio-util: introduce asprintf_safe
asprintf is nice to use, but the _documented_ error return convention is
unclear:
> If  memory  allocation  wasn't possible, or some other error occurs,
> these functions will return -1, and the contents of strp are undefined.

What exactly "undefined" means is up for debate: if it was really
undefined, the caller wouldn't be able to meaningfully clean up, because
they wouldn't know if strp is a valid pointer. So far we interpreted
"undefined" — in some parts of the code base — as "either NULL or a
valid pointer that needs to be freed", and — in other parts of the
codebase — as "always NULL". I checked glibc and musl, and they both
uncoditionally set the output pointer to NULL on failure.

There is also no information _why_ asprintf failed. It could be an
allocation error or format string error. But we just don't have this
information.

Let's add a wrapper that either returns a good string or a NULL pointer.
Since there's just one failure result, we don't need a separate return
value and an output argument and can simplify callers.
2026-03-06 17:46:59 +01:00
Yu Watanabe 618952f07e CODING_STYLE: fix typo
Follow-up for 83b4a5bb3d.
2026-02-16 14:35:21 +09:00
Lennart Poettering 83b4a5bb3d CODING_STYLE: add a brief log msg style guide 2026-02-12 18:00:37 +01:00
Lennart Poettering 43ef7c944c CODING_STYLE: document how to handle kernel compat
Let's define a way how to mark codepaths that are subject to
deletion once the kernel baseline reaches a certain version, to make it
easier to find these cases.

WHile we are at it, introuce a whole section in CODING_STYLE about
kernel version compat.

I followed the new scheme in #39621, but we can merge the coding style
guidelines on this already.
2026-02-06 21:01:37 +01:00
Lennart Poettering 3775fab341 CODING_STYLE: suggest a clear order for func params that combine fd and path 2026-01-24 20:52:00 +01:00
DaanDeMeyer 90e80b9e8b docs: Document practice of using comments for argument names 2026-01-14 16:52:58 +01:00
Daan De MeyerandYu Watanabe ee6b3d1aa2 test: Stop using grep -q in integration test
When a TTY is attached to the test unit, grep -q will generate SIGPIPE
for the previous command in the pipeline which in combo with `pipefail`
will cause the command to fail with exit status 141 which will fail the
test.

Replace with >/dev/null to avoid this from happening.

See also https://www.gnu.org/software/grep/manual/html_node/Usage.html
> There is a related problem with Bash’s set -e -o pipefail. Since grep
> does not always read all its input, a command outputting to a pipe read
> by grep can fail when grep exits before reading all its input, and the
> command’s failure can cause Bash to exit.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-12-10 12:09:10 +01:00
Daan De Meyer dd281e19a7 docs: Document cast formatting rules 2025-11-22 23:41:46 +01:00
Daan De Meyer 7e5a07c24a Various documentation updates 2025-11-18 10:09:19 +00: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
Daan De Meyer f228115a69 docs: Mention newline requirement for multi-line function decl 2025-10-06 20:06:03 +09:00
Daan De Meyer 686bbf1e7f Introduce forward.h header with forward declarations
In preparation for adopting forward declarations to reduce unnecessary
transitive includes across the tree, let's introduce a forward.h header
with forward declarations for all libc, libsystemd, basic and shared types.

Additionally, this header exports all basic integer types and errno constants,
as well as all macros including assertions macros. These header files contain
types often used in headers and are always included in every source file one
way or another anyway.

To avoid having to include memory-util.h and alloc-util.h in forward.h, we
split off the parts we need from both into cleanup-util.h and only include
cleanup-util.h in forward.h.

To keep this commit self-contained, we include cleanup-fundamental.h and
cleanup-util.h from the headers that originally contained the same macros.
We'll remove these again in a later commit that optimizes the includes in
src/basic and src/fundamental.

Split out of #37364
2025-05-14 15:44:17 +02:00
Daan De Meyer 352fee103b docs: Add note to keep header files as lean as possible to CODING_STYLE.md 2025-04-19 11:52:58 +02:00
Daan De Meyer c7e42c2705 docs: Add paragraph about circular includes to CODING_STYLE.md 2025-04-19 11:51:07 +02:00
Mike Yuan 9cd064aa9f meson: bump C std to gnu17
GCC 8.4 (our baseline) defaults to gnu17 already.
2025-01-17 19:46:37 +00:00
Lennart Poettering c9b477415a man: document preference for secure_getenv() in coding style 2024-10-14 12:31:37 +01:00
Mike Yuan 4b7249111a docs/CODING_STYLE: document that we nowadays prefer (const char*) for func ret type
Addresses https://github.com/systemd/systemd/pull/33567#discussion_r1662818225
2024-07-02 23:35:58 +02:00
Lennart Poettering 7811864b08 CODING_STYLE: document "reterr_" return parameters
In some recent PRs (e.g. #32628) I started to systematically name return
parameters that shall only be initialized on failure (because they carry
additional error meta information, such as the line/column number of
parse failures or so). Let's make this official in the coding style.
2024-06-13 09:51:35 +02:00
Zbigniew Jędrzejewski-Szmek 9f74901a1e Merge pull request #31648 from neighbourhoodie/review-content
I did the merge manually to resolve a trivial conflict.
2024-04-17 17:41:07 +02:00
Daan De Meyer 5c041971eb docs: Add Tests section to coding style doc 2024-04-10 18:24:29 +02:00
hulkoba f757c5a4bf docs/CODING_STYLE: remove whitespace 2024-03-27 06:49:16 +01:00
Mike Yuan 3d3c42773d docs/CODING_STYLE: fix typo (CLONE_VORK -> VFORK) 2024-02-24 13:26:19 +08:00
Zbigniew Jędrzejewski-Szmek 8e3fee33af Revert "docs: use collections to structure the data"
This reverts commit 5e8ff010a1.

This broke all the URLs, we can't have that. (And actually, we probably don't
_want_ to make the change either. It's nicer to have all the pages in one
directory, so one doesn't have to figure out to which collection the page
belongs.)
2024-02-23 09:48:47 +01:00
hulkoba 5e8ff010a1 docs: use collections to structure the data 2024-02-22 10:11:54 +01:00
Lennart Poettering ce4801c42b doc: readd vanished ```
This disappeared in 1e8f5f79e1, let's
restore it.
2023-10-11 11:41:56 +02:00
Yu Watanabe ec88da9146 docs: fix typo 2023-08-01 15:53:32 +09:00
Zbigniew Jędrzejewski-Szmek da89046643 tree-wide: "<n>bit" → "<n>-bit"
In some places, "<n> bits" is used when more appropriate.
2023-07-02 11:10:12 +01:00
Lennart Poettering 2499d32022 docs: document threading situation in coding style 2023-06-23 10:05:16 +02:00
Lennart Poettering 4d26b2277a doc: say in CODING_STYLE that AT_EMPTY_PATH should be implied on openat() style APIs (and NULL path is OK)
As discussed here:

https://github.com/systemd/systemd/pull/27397#issuecomment-1521630044
2023-04-25 14:05:08 +02:00
Dmitry V. Levin ba1ca5ef26 CODING_STYLE: note that 'unsigned' form is preferred over 'unsigned int' 2023-03-08 21:17:23 +00:00
Zbigniew Jędrzejewski-Szmek 1e8f5f79e1 docs/CODING_STYLE: add sentence about redirection operators 2023-02-06 09:19:04 +01:00
Dmitry V. Levin 5c7a4f21dd docs, man: consistently use comma after "For example" 2023-01-23 22:52:34 +00:00
Dmitry V. Levin e347d53ace docs: fix grammar a bit 2023-01-23 22:52:34 +00:00
Dmitry V. Levin d8b67e05fb docs: fix a few typos 2023-01-23 22:52:34 +00:00
Lennart Poettering f591cf66f0 doc: document how we expect empty lines to be used 2023-01-17 21:26:13 +01:00
Sam James 4e11b54b31 CODING_STYLE: fix 'better' typo 2023-01-06 14:03:19 +01:00
Lennart Poettering bbb71e5c98 CODING_STYLE: fix header level 2022-09-08 16:13:07 +02:00
Lennart Poettering e8a587dca2 docs: Some CODING_STYLE additions 2022-09-07 10:05:46 +02:00
Lennart Poettering e109541fe6 docs: suggests people use path_extract_filename() + path_extract_directory() 2022-08-23 15:10:15 +02:00
Yu Watanabe 74223cbe14 tree-wide: fix typo 2022-06-10 08:26:08 +09:00
Zbigniew Jędrzejewski-Szmek a5b28b7721 CODING_STYLE: say that inet_ntop() is a no no 2022-06-06 09:52:52 +02:00
Lennart Poettering e28770e367 docs: document how we usually define enums 2022-03-14 19:10:11 +00:00
Lennart Poettering 40f55f6998 docs: document we use C11 with GNU extensions now
Follow-up for: #22711
2022-03-14 18:43:49 +00:00
bearhoney d0515a289a Update CODING_STYLE.md
Fixed typo.
2022-02-07 10:46:22 +00:00
Erik Sjölund f223fd6add docs: fix typos and improve language
Fix typos and improve the language by
adding a few commas and a missing word.
2022-01-26 22:35:33 +00:00
Lennart Poettering 947796eac3 docs: mention RET_NERRNO() in CODING_STYLE.md 2021-11-16 08:04:09 +01:00
Emily Gonyer be7148ebed Change gendered terms to be gender-neutral (#21325)
Some typos are also fixed.
2021-11-12 16:09:56 +01:00
Zbigniew Jędrzejewski-Szmek 9214f2999b CODING_STYLE: allow joined variable declarations and function calls
… but only for a single variable.

The guidelines already allowed declaring variables at the point of
initialization. But not making a function call to do that. Let's allow that
now.  The existing style of declaring and initializing seperate is still
allowed, and whatever makes most sense should be used.
2021-11-03 10:30:36 +01:00
Lennart Poettering e3bde91293 doc: document that alloca_safe() and friends are the APIs to use 2021-10-14 15:57:52 +02:00
Zbigniew Jędrzejewski-Szmek 0aff7b7584 docs: add spdx tags to all .md files
I have no idea if this is going to cause rendering problems, and it is fairly
hard to check. So let's just merge this, and if it github markdown processor
doesn't like it, revert.
2021-09-27 09:19:02 +02:00