summaryrefslogtreecommitdiff
path: root/src/basic/fileio.c
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: check if errno is greater then zeroZbigniew Jędrzejewski-Szmek2016-01-131-2/+2
| | | | | | | | | | | | | | gcc is confused by the common idiom of return errno ? -errno : -ESOMETHING and thinks a positive value may be returned. Replace this condition with errno > 0 to help gcc and avoid many spurious warnings. I filed a gcc rfe a long time ago, but it hard to say if it will ever be implemented [1]. Both conventions were used in the codebase, this change makes things more consistent. This is a follow up to bcb161b0230f. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
* basic: re-sort includesThomas Hindoe Paaboel Andersen2015-12-011-3/+3
| | | | | My previous patch to only include what we use accidentially placed the added inlcudes in non-sorted order.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-1/+12
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* util-lib: optionally, when writing a string to a file, verify string on failureLennart Poettering2015-11-131-14/+69
| | | | | | | | | | | | | | | | | | | With this change, the idiom: r = write_string_file(p, buf, 0); if (r < 0) { if (verify_one_line_file(p, buf) > 0) r = 0; } gets reduced to: r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); i.e. when writing the string fails and the new flag WRITE_STRING_FILE_VERIFY_ON_FAILURE is specified we'll not return a failure immediately, but check the contents of the file. If it matches what we wanted to write we suppress the error and exit cleanly.
* journald: rework --sync/--rotate logic to use CLOCK_MONOTONIC timestamp filesLennart Poettering2015-11-121-0/+36
| | | | | | | | | | | | | Previously, we'd rely on the mtime timestamps of the touch files to see if our sync/rotation requests were already suppressed. This means we rely on CLOCK_REALTIME timestamps. With this patch we instead store the CLOCK_MONOTONIC timestamp *in* the touch files, and avoid relying on mtime. This should make things more reliable when the clock or underlying mtime granularity is not very good. This also adds warning messages if writing any of the flag files fails.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out umask-related code to umask-util.hLennart Poettering2015-10-271-0/+1
|
* util-lib: move a number of fs operations into fs-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: move more file I/O related calls into fileio.[ch]Lennart Poettering2015-10-271-2/+300
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-1/+2
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-0/+1
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* util: split out escaping code into escape.[ch]Lennart Poettering2015-10-241-2/+3
| | | | This really deserves its own file, given how much code this is now.
* fileio: make get_status_field() more genericAaro Koskinen2015-09-301-8/+32
| | | | | | | | | | | | All users of get_status_field() expect the field pattern to occur in the beginning of a line, and the delimiter is ':'. Hardcode this into the function, and also skip any whitespace before ':' to support fields in files like /proc/cpuinfo. Add support for returning the full field value (currently stops on first whitespace). Rename the function so it's easier to ensure all callers switch to new semantics.
* tree-wide: port everything over to fflush_and_check()Lennart Poettering2015-07-291-8/+2
| | | | | | | | Some places invoked fflush() directly with their own manual error checking, let's unify all that by using fflush_and_check(). This also unifies the general error paths of fflush()+rename() file writers.
* fileio: get_status_field() don't clobber arg on OOMLennart Poettering2015-07-231-3/+4
| | | | | According to our coding style guidelines we shouldn't clobber pass-by-ref arguments on failure, hence don't do so here either.
* fileio: consolidate write_string_file*()Daniel Mack2015-07-061-37/+37
| | | | | | | Merge write_string_file(), write_string_file_no_create() and write_string_file_atomic() into write_string_file() and provide a flags mask that allows combinations of atomic writing, newline appending and automatic file creation. Change all users accordingly.
* fileio: add 'enforce_newline' argument to write_string_stream()Daniel Mack2015-07-061-5/+5
| | | | | Add a flag to control whether write_string_stream() should always enforce a trailing newline character in the file.
* networkd: be more defensive when writing to ipv4/ipv6 forwarding settingsLennart Poettering2015-07-061-0/+11
| | | | | | | | | | 1) never bother with setting the flag for loopback devices 2) if we fail to write the flag due to EROFS (which is likely to happen in containers where /proc/sys is read-only) or any other error, check if the flag already has the right value. If so, don't complain. Closes #469
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-0/+817
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/