summaryrefslogtreecommitdiff
path: root/src/basic/fileio.c
Commit message (Collapse)AuthorAge
* Prep v239: Unmasked mkdtemp_malloc(), it is needed to test inotify.Sven Eden2018-08-24
|
* Prep v239: Add missing updates that evaded migration.Sven Eden2018-08-24
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* util: allow mkdtemp_malloc() to be called with NULL patternLennart Poettering2018-08-24
| | | | In that case simply place the directory in /tmp.
* util: add new write_string_filef() helperLennart Poettering2018-08-24
| | | | | This new helper combines asprintf() and write_string_file() in one, which is useful at various places to shorten the code a bit.
* path-util: introduce path_simplify()Yu Watanabe2018-08-24
| | | | | | | | The function is similar to path_kill_slashes() but also removes initial './', trailing '/.', and '/./' in the path. When the second argument of path_simplify() is false, then it behaves as the same as path_kill_slashes(). Hence, this also replaces path_kill_slashes() with path_simplify().
* fileio: make sure read_full_stream() works on memory-backed streamsLennart Poettering2018-08-24
|
* fileio: add parse_env_filev() that is like parse_env_file() but takes a va_listLennart Poettering2018-08-24
|
* fileio: accept FILE* in addition to path in parse_env_file()Lennart Poettering2018-08-24
| | | | | | | Most our other parsing functions do this, let's do this here too, internally we accept that anyway. Also, the closely related load_env_file() and load_env_file_pairs() also do this, so let's be systematic.
* fileio.c: fix incorrect mtimeChris Lesiak2018-08-24
| | | | | | | | | | | | | | | A regression was introduced that caused the mtime of /etc/.updated and /var/.updated to be the current time when systemd-update-done ran instead of being copied from /usr. This was nearly fixed, but due to fflush being called after mtime was carefully set, it was overwritten with the current time. Regression introduced in 872c40396384f9fa89b01baf4e739d28ed590299 A fix was just missed in 39c38d773fbe2b4f76ff29ecd3344640efb9a86c Fixes #8806
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | 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)
* fileio: port parse_env_file_internal() to use _cleanup_free_ (#8511)Lennart Poettering2018-08-24
|
* fileio.c: fix incorrect mtimeChris Lesiak2018-06-28
| | | | | | | | | | | | | | | | | A regression was introduced that caused the mtime of /etc/.updated and /var/.updated to be the current time when systemd-update-done ran instead of being copied from /usr. This was nearly fixed, but due to fflush being called after mtime was carefully set, it was overwritten with the current time. Regression introduced in 872c40396384f9fa89b01baf4e739d28ed590299 A fix was just missed in 39c38d773fbe2b4f76ff29ecd3344640efb9a86c Fixes #8806 (cherry picked from commit be83711c7eb6a09e0d0c529c427cebcae87c0c1f)
* tree-wide: make use of fsync_directory_of_file() all over the placeLennart Poettering2018-05-30
| | | | | | Let's make use this at various places we call fsync(), to make things fully reliable, as the kernel devs suggest to first fsync() files and then fsync() the directories they are located in.
* cocci: use strempty() at more placesLennart Poettering2018-05-30
| | | | This shortens the code by a few lines.
* fileio: minor tweak to executable_is_script()Lennart Poettering2018-05-30
| | | | | | If read_line() returns ENOBFUS this means the line was overly long. When we use this for checking whether an executable is a script, then this shouldn't be propagated as-is, but simply as "this is not a script".
* fileio: tweak write_string_stream_ts() to write out trailing \n in one go ↵Lennart Poettering2018-05-30
| | | | | | | | | | | | even if buffering is off This tweaks write_string_stream_ts() in one minor way: when stdio buffering has been turned off, let's append the newline we shall append to the buffer we write ourselves so that the kernel only gets one syscall for the result. When buffering is enabled stdio will take care of that anyway. Follow-up for #7750.
* fileio: write_string_stream_ts: check for file errors immediatelyMike Gilbert2018-05-30
|
* fileio: write_string_stream_ts: return errors from fputs and fputcMike Gilbert2018-05-30
| | | | | | | Ignoring errors from these functions may mask errors returned by the kernel. Fixes: https://github.com/systemd/systemd/issues/7744
* tree-wide: make use of new STRLEN() macro everywhere (#7639)Lennart Poettering2018-05-30
| | | | | | Let's employ coccinelle to do this for us. Follow-up for #7625.
* basic: turn off stdio locking for a couple of helper callsLennart Poettering2018-05-30
| | | | | | These helper calls are potentially called often, and allocate FILE* objects internally for a very short period of time, let's turn off locking for them too.
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* sysctl: disable buffer while writing to /procTiago Salem Herrmann2017-12-12
| | | | | | | | fputs() writes only first 2048 bytes and fails to write to /proc when values are larger than that. This patch adds a new flag to WriteStringFileFlags that make it possible to disable the buffer under specific cases.
* tree-wide: drop a few == NULL and != NULL comparisonLennart Poettering2017-12-08
| | | | | | | 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)
* fileio: include sys/mman.hYu Watanabe2017-11-26
|
* util-lib: mark variable with _unused_ to silence clang warningZbigniew Jędrzejewski-Szmek2017-11-01
| | | | | | _unused_ means "the variable is meant to be possible unused and gcc will not generate a warning about it", which is exactly what we need here, since we're only declaring it for the side effect of _cleanup_.
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-11-23
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* fileio: return 0 from read_one_line_file on successZbigniew Jędrzejewski-Szmek2017-11-22
| | | | Fixup for f4b51a2d09. Suggested by Evgeny Vereshchagin.
* fileio: initialize errno to zero before we do fread()Lennart Poettering2017-09-22
| | | | | if there was something in the read buffer already errno might not be set on error, let's detect that case.
* fileio: try to read one byte too much in read_full_stream()Lennart Poettering2017-09-22
| | | | | | | | Let's read one byte more than the file size we read from stat() on the first fread() invocation. That way, the first read() will already be short and indicate eof to fread(). This is a minor optimization, and replaces #3908.
* fileio: move fsync() logic into write_string_stream_ts()Lennart Poettering2017-09-22
| | | | | | That way, write_string_stream_ts() becomes more powerful, and we can remove duplicate code from write_string_file_atomic() and write_string_file_ts().
* fileio: make write_string_stream() accept flags parameterLennart Poettering2017-09-22
| | | | | | Let's make write_string_stream() and write_string_file() more alike, and pass the same flag set so that we can remove a number of boolean parameters.
* fileio: support writing atomic files with timestampLennart Poettering2017-09-22
| | | | | Let's make sure "ts" is taken into account when writing atomic files, too.
* Add abstraction model for BPF programsDaniel Mack2017-11-20
| | | | | This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code.
* v235: Added missing updatesSven Eden2017-11-19
|
* fileio: return 0 from read_one_line_file on successZbigniew Jędrzejewski-Szmek2017-09-24
| | | | Fixup for f4b51a2d09. Suggested by Evgeny Vereshchagin.
* fileio: use _cleanup_ for FILE unlockingZbigniew Jędrzejewski-Szmek2017-09-25
|
* fileio: initialize errno to zero before we do fread()Lennart Poettering2017-09-22
| | | | | if there was something in the read buffer already errno might not be set on error, let's detect that case.
* fileio: try to read one byte too much in read_full_stream()Lennart Poettering2017-09-22
| | | | | | | | Let's read one byte more than the file size we read from stat() on the first fread() invocation. That way, the first read() will already be short and indicate eof to fread(). This is a minor optimization, and replaces #3908.
* fileio: move fsync() logic into write_string_stream_ts()Lennart Poettering2017-09-22
| | | | | | That way, write_string_stream_ts() becomes more powerful, and we can remove duplicate code from write_string_file_atomic() and write_string_file_ts().
* fileio: make write_string_stream() accept flags parameterLennart Poettering2017-09-22
| | | | | | Let's make write_string_stream() and write_string_file() more alike, and pass the same flag set so that we can remove a number of boolean parameters.
* fileio: support writing atomic files with timestampLennart Poettering2017-09-22
| | | | | Let's make sure "ts" is taken into account when writing atomic files, too.
* fileio: rework read_one_line_file() on top of read_line()Lennart Poettering2017-09-25
|
* fileio: add new helper call read_line() as bounded getline() replacementLennart Poettering2017-09-25
| | | | | | | read_line() is much like getline(), and returns a line read from a FILE*, of arbitrary sizes. In contrast to gets() it will grow the buffer dynamically, and in contrast to getline() it will place a user-specified boundary on the line.
* Prep v235: Apply pending upstream updates in src/basic [1/4]Sven Eden2017-08-30
|
* fileio: rename function parameter to avoid masking global symbolAlan Jenkins2017-08-29
| | | | | | | > glibc exports a function called sync(), we should probably avoid > overloading that as a variable here locally (gcc even used to warn about > that, not sure why it doesn't anymore), to avoid confusion around what > "if (sync)" actually means
* "Don't fear the fsync()"Alan Jenkins2017-08-29
| | | | | | | | | | | | | | | | | | | | | For files which are vital to boot 1. Avoid opening any window where power loss will zero them out or worse. I know app developers all coded to the ext3 implementation, but the only formal documentation we have says we're broken if we actually rely on it. E.g. * `man mount`, search for `auto_da_alloc`. * http://www.linux-mtd.infradead.org/faq/ubifs.html#L_atomic_change * https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ 2. If we tell the kernel we're interested in writing them to disk, it will tell us if that fails. So at minimum, this means we play our part in notifying the user about errors. I refactored error-handling in `udevadm-hwdb` a little. It turns out I did exactly the same as had already been done in the `elogind-hwdb` version, i.e. commit d702dcd.