summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-journal/compress.c
Commit message (Collapse)AuthorAgeFilesLines
* basic: move compress.[ch] → src/basic/Lennart Poettering2022-04-261-1081/+0
| | | | | | | | | | | | The compression helpers are used both in journal code and in coredump code, and there's a good chance we'll use them later for other stuff. Let's hence move them into src/basic/, to make them a proper internal API we can use from everywhere where that's desirable. (pstore might be a candidate, for example) No real code changes, just some moving around, build system rearrangements, and stripping of journal-def.h inclusion.
* meson: simplify setting of default compressionZbigniew Jędrzejewski-Szmek2022-04-221-6/+6
| | | | | | | | | | | | | | | | | Follow-up for da13d2ca0731b413841663052f2cc6832a855334. Instead of having separate definitions of the bitmask flags, just define DEFAULT_COMPRESSION_FOO=0|1 directly. (It *should* be possible to do this more simply, but the problem is that anything that is used in #if cannot refer to C constants or enums. This is the simplest I could come up with that preserves the property that we don't use #ifdef.) The return value from compress_blob() is changed to propagate the error instead of always returning -EOPNOTSUPP. The callers don't care about the specific error value. compress_blob_*() are changed to return the compression method on success, so that compress_blob() can be simplified. compress_stream_*() and compress_stream() are changed in the same way for consistency, even though the callers do not currently use this information (outside of tests).
* core: check size before mmapTobias Stoeckmann2022-03-031-0/+4
| | | | | | | | | | | | | | | The data type off_t can be 64 on 32 bit systems if they have large file support. Since mmap expects a size_t with 32 bits as second argument truncation could occur. At worst these huge files could lead to mmaps smaller than the previous check for small files. This in turn shouldn't have a lot of impact because mmap allocates at page size boundaries. This also made the PAGE_ALIGN call in open_mmap unneeded. In fact it was neither in sync with other mmap calls nor with its own munmap counterpart in error path. If such large files are encountered, which is very unlikely in these code paths, treat them with the same error as if they are too small.
* compress: return uncompressed size to the callerLuca Boccassi2021-06-081-5/+15
| | | | Useful when compressing anonymous FDs that cannot be rewund
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-191-76/+93
| | | | | | | | | | | | | | | | | | | | | | | | We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
* compress: support streaming lz4 without full input mmapLuca Boccassi2021-03-311-48/+36
| | | | | | | | The advantage of stream compression is keeping a low memory profile, but the lz4 stream compressor usage mmaps the whole file in memory. Change it to read bits by bits, like the other stream compression helpers.
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-051-7/+7
|
* tree-wide: reset the cleaned-up variable in cleanup functionsZbigniew Jędrzejewski-Szmek2021-02-161-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the cleanup function returns the appropriate type, use that to reset the variable. For other functions (usually the foreign ones which return void), add an explicit value to reset to. This causes a bit of code churn, but I think it might be worth it. In a following patch static destructors will be called from a fuzzer, and this change allows them to be called multiple times. But I think such a change might help with detecting unitialized code reuse too. We hit various bugs like this, and things are more obvious when a pointer has been set to NULL. I was worried whether this change increases text size, but it doesn't seem to: -Dbuildtype=debug: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494520 Feb 16 15:06 build/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494576 Feb 16 15:10 build/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 4117672 Feb 16 14:36 build/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 4494640 Feb 16 15:15 build/systemd* -Dbuildtype=release: before "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:09 build-rawhide/systemd* after "tree-wide: return NULL from freeing functions": -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:10 build-rawhide/systemd* now: -rwxrwxr-x 1 zbyszek zbyszek 5252256 Feb 14 14:47 build-rawhide/libsystemd.so.0.30.0* -rwxrwxr-x 1 zbyszek zbyszek 1834184 Feb 16 15:16 build-rawhide/systemd* I would expect that the compiler would be able to elide the setting of a variable if the variable is never used again. And this seems to be the case: in optimized builds there is no change in size whatsoever. And the change in size in unoptimized build is negligible. Something strange is happening with size of libsystemd: it's bigger in optimized builds. Something to figure out, but unrelated to this patch.
* sd-journal: add forgotten unmap in error pathZbigniew Jędrzejewski-Szmek2021-02-111-4/+5
| | | | | | Bug introduced in 4b5bc5396c090ee41c45cab9052372d296c4a2f4 :( Coverity CID#1444709.
* sd-journal: move source files for sd-journal to src/libsystemd/sd-journalYu Watanabe2021-01-191-0/+1061