summaryrefslogtreecommitdiff
path: root/coccinelle
Commit message (Collapse)AuthorAgeFilesLines
* coccinelle: add explicit statement isomorphismsFrantisek Sumsal2019-04-272-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | Coccinelle needs a custom isomorphism file with rules (isomorphisms) how to correctly rewrite conditions with explicit NULL checks (i.e. if (ptr == NULL)) to their shorter form (i.e. if (!ptr)). Coccinelle already contains such isomorphisms in its default .iso file, however, they're in the opposite direction, which results in useless output from coccinelle/equals-null.cocci. With this fix, `spatch` should no longer report patches like: @@ -628,8 +628,9 @@ static int path_deserialize_item(Unit *u f = path_result_from_string(value); if (f < 0) log_unit_debug(u, "Failed to parse result value: %s", value); - else if (f != PATH_SUCCESS) - p->result = f; + else {if (f != PATH_SUCCESS) + p->result = f; + } } else log_unit_debug(u, "Unknown serialization key: %s", key);
* Merge pull request #12217 from keszybz/unlocked-operationsLennart Poettering2019-04-121-0/+71
|\ | | | | Refactor how we do unlocked file operations
| * Add open_memstream_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+8
| |
| * Add fdopen_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+12
| |
| * Make fopen_temporary and fopen_temporary_label unlockedZbigniew Jędrzejewski-Szmek2019-04-121-0/+14
| | | | | | | | | | | | | | | | This is partially a refactoring, but also makes many more places use unlocked operations implicitly, i.e. all users of fopen_temporary(). AFAICT, the uses are always for short-lived files which are not shared externally, and are just used within the same context. Locking is not necessary.
| * Add fopen_unlocked() wrapperZbigniew Jędrzejewski-Szmek2019-04-121-0/+37
| |
* | scripts: use 4 space indentationZbigniew Jędrzejewski-Szmek2019-04-121-13/+13
|/ | | | | | | | | | | | | | | | | | We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed. 4 sp was the most common, in particular the majority of scripts under test/ used that. Let's standarize on 4 sp, because many commandlines are long and there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp also seems to be the default indentation, so this will make it less likely that people will mess up if they don't load the editor config. (I think people often use vi, and vi has no support to load project-wide configuration automatically. We distribute a .vimrc file, but it is not loaded by default, and even the instructions in it seem to discourage its use for security reasons.) Also remove the few vim config lines that were left. We should either have them on all files, or none. Also remove some strange stuff like '#!/bin/env bash', yikes.
* coccinelle: add coccinelle script for empty_or_dash() useLennart Poettering2019-04-081-0/+5
|
* nspawn-oci: use SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2019-03-211-0/+8
|
* tree-wide: more IOVEC_MAKE() conversionsLennart Poettering2018-11-281-0/+5
|
* tree-wide: use IOVEC_MAKE() at many placesLennart Poettering2018-11-271-0/+24
|
* tree-wide: use SWAP_TWO a bit moreLennart Poettering2018-11-261-0/+7
|
* coccinelle: also mark previous synthetic errnos as suchZbigniew Jędrzejewski-Szmek2018-11-221-0/+7
|
* coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek2018-11-221-0/+35
| | | | | | | | | | | Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
* cocci: simplify some if checksLennart Poettering2018-11-161-0/+54
|
* tree-wide: CMP()ify all the thingsLennart Poettering2018-10-161-0/+28
| | | | Let's employ coccinelle to fix everything up automatically for us.
* tree-wide: drop !! casts to booleansZbigniew Jędrzejewski-Szmek2018-06-131-0/+12
| | | | | | | | | | | They are not needed, because anything that is non-zero is converted to true. C11: > 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the > value compares equal to 0; otherwise, the result is 1. https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c
* cocinelle: use GNU parallel to run spatchZbigniew Jędrzejewski-Szmek2018-06-131-2/+8
| | | | | | spatch is single-threaded, i.e. slow. On my machine it allocates 5 GB of memory and starts swapping, which makes it even slower. Using parallel makes the whole thing pleasantly fast.
* tools: make various scripts find the top-levle git dir automaticallyLennart Poettering2018-06-071-1/+2
|
* Add macro for checking if some flags are setZbigniew Jędrzejewski-Szmek2018-06-041-0/+15
| | | | | | | | | This way we don't need to repeat the argument twice. I didn't replace all instances. I think it's better to leave out: - asserts - comparisons like x & y == x, which are mathematically equivalent, but here we aren't checking if flags are set, but if the argument fits in the flags.
* coccinelle: add option to make changes in placeZbigniew Jędrzejewski-Szmek2018-06-041-2/+10
|
* coccinelle: run spatch just on version-controlled filesZbigniew Jędrzejewski-Szmek2018-06-041-2/+5
| | | | | | | Also, allow run-cocinnelle.sh to be started from any directory. Unfortunately set -x does not work nicely anymore, because the list is too verbose. Replace it by an echo line.
* util-lib: introduce new empty_or_root() helper (#8746)Lennart Poettering2018-04-181-0/+10
| | | | | | | We check the same condition at various places. Let's add a trivial, common helper for this, and use it everywhere. It's not going to make things much faster or much shorter, but I think a lot more readable
* coccinelle: fix typo in file name (#8640)Alexander Kurtz2018-04-021-0/+0
|
* run-coccinelle.sh: use set -x for showing command line of "spatch"Lennart Poettering2018-03-231-4/+3
| | | | | Let's make sure run-coccinelle.sh generates similar output as run-integration-tests.sh, hence use the same "set -x" logic.
* macro: introduce new TAKE_FD() macroLennart Poettering2018-03-221-0/+14
| | | | | | | This is similar to TAKE_PTR() but operates on file descriptors, and thus assigns -1 to the fd parameter after returning it. Removes 60 lines from our codebase. Pretty good too I think.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-0/+14
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)Lennart Poettering2018-03-201-0/+5
| | | | Let's avoid fds 0…2 for safety reasons.
* coccinelle: make use of DIV_ROUND_UP() wherever appropriateLennart Poettering2018-03-201-0/+20
| | | | Let's use our macros where we can
* coccinelle: similar to reallocarray() let's also systematically use ↵Lennart Poettering2018-03-021-0/+20
| | | | malloc_multiply()
* coccinelle: add reallocarray() coccinelle scriptLennart Poettering2018-03-021-0/+20
| | | | | Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
* coccinelle: slightly improve run-coccinelle.shLennart Poettering2018-02-281-2/+2
| | | | | | Let's include the command line to use to get the requested output. This makes it easy to copy/paste the command line out, and add "--in-place" to actually apply the changes "run-coccinelle.sh" outputs.
* util: add new safe_close_above_stdio() wrapperLennart Poettering2018-02-281-0/+36
| | | | | | At various places we only want to close fds if they are not stdin/stdout/stderr, i.e. fds 0, 1, 2. Let's add a unified helper call for that, and port everything over.
* coccinelle: drop empty-if.cocci scriptLennart Poettering2018-02-272-57/+0
| | | | | | It doesn't work, spits out only rubbish and was already excluded of run-coccinelle.sh. It's a pitty it doesn't work, but let's drop this dead piece of code for now.
* coccinelle: O_NDELAY → O_NONBLOCKLennart Poettering2018-01-241-0/+4
| | | | | | Apparently O_NONBLOCK is the modern name used in most documentation and for most cases in our sources. Let's hence replace the old alias O_NDELAY and stick to O_NONBLOCK everywhere.
* cocci: there's not ENOTSUP, there's only EOPNOTSUPPLennart Poettering2018-01-111-0/+4
| | | | | | On Linux the former is a compat alias to the latter, and that's really weird, as inside the kernel the two are distinct. Which means we really should stay away from it.
* cocci: use strempty() at more placesLennart Poettering2018-01-101-0/+38
| | | | This shortens the code by a few lines.
* tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we canLennart Poettering2017-12-251-0/+16
|
* coccinelle: beef up isempty() checks (#7729)Lennart Poettering2017-12-231-0/+45
| | | | | | With these additions, coccinelle finds everything fixed by the first commit in PR #7695. In order not to needlessly conflict with that PR this PR won't include those fixes, but only the coccinelle changes to detect them automatically in the future.
* tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on ↵Lennart Poettering2017-12-151-0/+8
| | | | | | | (#7645) This makes things a bit easier to read I think, and also makes sure we always use the _unlikely_ wrapper around it, which so far we used sometimes and other times we didn't. Let's clean that up.
* coccinelle: automatically rewrite memset() to zero() or memzero() where we canLennart Poettering2017-12-141-0/+30
| | | | | We are pretty good at this already, hence only a single case is actually found by this.
* tree-wide: make use of new STRLEN() macro everywhere (#7639)Lennart Poettering2017-12-141-0/+10
| | | | | Let's employ coccinelle to do this for us. Follow-up for #7625.
* tree-wide: drop a few == NULL and != NULL comparisonLennart Poettering2017-12-111-0/+14
| | | | | | | Our CODING_STYLE suggests not comparing with NULL, but relying on C's downgrade-to-bool feature for that. Fix up some code to match these guidelines. (This is not comprehensive, the coccinelle output for this is unfortunately kinda borked)
* core: use empty_to_null() where we canLennart Poettering2017-12-071-0/+5
|
* coccinelle: improve run-coccinelle.sh to take list of scripts to runLennart Poettering2017-12-071-1/+1
| | | | | Let's tweak run-coccinelle.sh to optionally take a list of scripts to run. If not specified, run all scripts, as before.
* coccinelle: add a run-coccinelle.sh script that runs all scriptsLennart Poettering2017-11-291-0/+11
| | | | | One day we should start running something like this as part of CI so that non-well-formed commits are not even accepted...
* coccinelle: fix IN_SET/!IN_SET scripts, and apply some changes it foundLennart Poettering2017-11-292-130/+56
| | | | | | | | IN_SET only works for constant values, hence clarify that. Moreover, we declared a statement "s" we never made use of. Drop it. Also, for both scripts, let's support 10 items. More causes spatch to die with "Stack overflow" for me.
* tree-wide: use strv_isempty() instead of strv_length() == 0Lennart Poettering2017-11-291-0/+15
| | | | It's a lot faster in many cases, since it's O(1) rather than O(n).
* tree-wide: use `!IN_SET(..)` for `a != b && a != c && …`Andreas Rammhold2017-10-021-0/+147
| | | | | | The included cocci was used to generate the changes. Thanks to @flo-wer for pointing this case out.
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-10-021-0/+35
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.