X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=docs%2FCODING_STYLE.md;h=d945f8cdbe7f3fb3d59c1e29ed2d3f9586216520;hb=HEAD;hp=0e761227348bd15fa52a98daa94a41f202e28da3;hpb=72bdf0ac67d704defd449ea91bfd9af779e7574c;p=thirdparty%2Fsystemd.git diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index 0e761227348..8f687e66623 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -297,7 +297,7 @@ SPDX-License-Identifier: LGPL-2.1-or-later t.bar = "bazz"; ``` -- To implement an endless loop, use `for (;;)` rather than `while (1)`. The +- To implement an endless loop, use `for (;;)` rather than `while (1)`. The latter is a bit ugly anyway, since you probably really meant `while (true)`. To avoid the discussion what the right always-true expression for an infinite while loop is, our recommendation is to simply write it without any @@ -774,9 +774,19 @@ SPDX-License-Identifier: LGPL-2.1-or-later - A corollary of the above is: never use `clone()` where a `fork()` would do too. Also consider using `posix_spawn()` which combines `clone()` + `execve()` into one and has nice properties since it avoids becoming a CoW - trap by using `CLONE_VORK` and `CLONE_VM` together. + trap by using `CLONE_VFORK` and `CLONE_VM` together. - While we avoid forking off threads on our own, writing thread-safe code is a good idea where it might end up running inside of libsystemd.so or similar. Hence, use TLS (i.e. `thread_local`) where appropriate, and maybe the occasional `pthread_once()`. + +## Tests + +- Use the assertion macros from `tests.h` (`ASSERT_GE()`, `ASSERT_OK()`, ...) to + make sure a descriptive error is logged when an assertion fails. If no assertion + macro exists for your specific use case, please add a new assertion macro in a + separate commit. + +- When modifying existing tests, please convert the test to use the new assertion + macros from `tests.h` if it is not already using those.