summaryrefslogtreecommitdiff
path: root/src/shared/fileio.c
AgeCommit message (Collapse)Author
2015-06-11build-sys: split internal basic/ library from shared/Kay Sievers
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
2014-11-07fileio: simplify write_string_file_atomic() by reusing write_string_stream()Lennart Poettering
2014-11-07copy: teach copy_bytes() sendfile() support, and then replace ↵Lennart Poettering
sendfile_full() by it
2014-09-25fileio: make parse_env_file() return number of parsed itemsMichal Sekletar
This commit introduces possibility to call parse_env_file_internal() and hand over extra argument where we will accumulate how many items were successfully parsed and pushed by callback. We make use of this in parse_env_file() and return number of parsed items on success instead of always returning zero. As a side-effect this commit should fix bug that locale settings in /etc/locale.conf are not overriden by options passed via kernel command line.
2014-08-15cgroup: never try to create files in cgroupfs, only open them for writingLennart Poettering
This should have the benefit that cg_set_attribute() returns ENOENT instead of EACCESS when we use it for non-existing attributes.
2014-07-13fileio: quote more shell characters in envfilesMantas Mikulėnas
Turns out, making strings shell-proof is harder than expected: # machinectl set-hostname "foo|poweroff" && . /etc/machine-info (This could be simplified by quoting *and* escaping all characters, which is harmless in shell but unnecessary.)
2014-07-07fileio: simplify write_env_file()Lennart Poettering
2014-07-07util: don't consider tabs special in string_has_cc() anymoreLennart Poettering
Instead, take a list of exceptions to our usual CC check
2014-07-03machinectl: show /etc/os-release information of container in status outputLennart Poettering
2014-06-22consistently order cleanup attribute before typeThomas Hindoe Paaboel Andersen
2014-04-12Unify GREEDY_REALLOC and GREEDY_REALLOC_TZbigniew Jędrzejewski-Szmek
greedy_realloc() and greedy_realloc0() now store the allocated size as the count, not bytes. Replace GREEDY_REALLOC uses with GREEDY_REALLOC_T everywhere, and then rename GREEDY_REALLOC_T to GREEDY_REALLOC. It is just too error-prone to have two slightly different macros which do the same thing.
2014-03-04Do not print invalid UTF-8 in error messagesZbigniew Jędrzejewski-Szmek
Inexplicably, 550a40ec ('core: do not print invalid utf-8 in error messages') only fixed two paths. Convert all of them now.
2014-03-04Introduce strv_consume which takes ownershipZbigniew Jędrzejewski-Szmek
This mirrors set_consume and makes the common use a bit nicer.
2014-02-13everywhere: always use O_CLOEXEC where it makes senseLennart Poettering
2014-02-08core: do not print invalid utf-8 in error messagesZbigniew Jędrzejewski-Szmek
2014-02-08core: fix crashes if locale.conf contains invalid utf-8 stringGoffredo Baroncelli
In the parse_env_file_push() and load_env_file_push() functions, there are two assert() call to check if the key or value parameters are utf8 valid. If the strings aren't utf8 valid, assert does abort. These function are used early by systemd to parse some files. For example '/etc/locale.conf'. In my case this file contained a not utf8 sequence, which is bad, but systemd crashed during the boot, which is even worse! The enclosed patch removes the assert and return -EINVAL if the sequence is invalid. This is possible because the caller of these function [1] checks the errors. So the check of an invalid utf8 sequence is still performed, but systemd doesn't crash anymore and logs the error. [1] parse_env_file_internal(), invoked by load_env_file() and parse_env_file()
2013-11-30fix regression of read_full_file() in fileio.cShawn Landden
my e93c33d4aa broke this stupidly
2013-11-30systemctl: add "systemctl cat"Shawn Landden
2013-10-13Never call qsort on potentially NULL arraysZbigniew Jędrzejewski-Szmek
This extends 62678ded 'efi: never call qsort on potentially NULL arrays' to all other places where qsort is used and it is not obvious that the count is non-zero.
2013-09-19Add more tests and fix capability loggingZbigniew Jędrzejewski-Szmek
2013-09-18Spelling fix from later revision of committed patch from Shawn Landden ↵David Strauss
<shawn@churchofgit.com>.
2013-09-18Fix capability logging when effective caps are 0Zbigniew Jędrzejewski-Szmek
Shawn Landen> Doesn't this also skip the last '0' when it is all '0's? You need to keep the last one.
2013-09-17util: restore get_process_capeff behaviourZbigniew Jędrzejewski-Szmek
69ab8088 unified parsing of status files and removed the logic of skipping extra '0's when getting the effective capabilities. Restore that logic, so that the same capabilities are always mapped to the same strings in the journal.
2013-09-13Advertise hibernation only if there's enough free swapZbigniew Jędrzejewski-Szmek
Condition that is checked is taken from upower: active(anon) < free swap * 0.98 This is really stupid, because the kernel knows the situation better, e.g. there could be two swap files, and then hibernation would be impossible despite passing this check, or the kernel could start supporting compressed swap and/or compressed hibernation images, and then this this check would be too stringent. Nevertheless, until we have something better, this should at least return a true negative if there's no swap. Logging of capabilities in the journal is changed to not strip leading zeros. I consider this more readable anyway. http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613 https://bugzilla.redhat.com/show_bug.cgi?id=1007059
2013-08-28Disallow invalid UTF-8 configurationZbigniew Jędrzejewski-Szmek
It is best to catch such errors early. If invalid UTF-8 ends up being given to dbus methods, the program will crash: process 20801: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file dbus-message.c line 2598.
2013-07-26journalctl: use _COMM= match for scriptsZbigniew Jędrzejewski-Szmek
In case of scripts, _EXE is set to the interpreter name, and _COMM is set based on the file name. Add a match for _COMM, and _EXE if the interpreter is not a link (e.g. for yum, the interpreter is /usr/bin/python, but it is a link to /usr/bin/python2, which in turn is a link to /usr/bin/python2.7, at least on Fedora, so we end up with _EXE=/usr/bin/python2.7). I don't think that such link chasing makes sense, because the final _EXE name is more likely to change.
2013-06-27core: general cgroup reworkLennart Poettering
Replace the very generic cgroup hookup with a much simpler one. With this change only the high-level cgroup settings remain, the ability to set arbitrary cgroup attributes is removed, so is support for adding units to arbitrary cgroup controllers or setting arbitrary paths for them (especially paths that are different for the various controllers). This also introduces a new -.slice root slice, that is the parent of system.slice and friends. This enables easy admin configuration of root-level cgrouo properties. This replaces DeviceDeny= by DevicePolicy=, and implicitly adds in /dev/null, /dev/zero and friends if DeviceAllow= is used (unless this is turned off by DevicePolicy=).
2013-05-06fileio: split write_one_line_file into twoZbigniew Jędrzejewski-Szmek
The new function allows one to write to an already open file.
2013-04-24fileio: unify how we chop off whitespace from key and value in ↵Lennart Poettering
parse_env_file_internal()
2013-04-18fileio.c: do not parse comments after non-whitespace charsHarald Hoyer
systemd does not want to understand comments after the first non-whitespace char occured. key=foo #comment will result into key == "foo #comment" key="foo" #comment will result into key == "foo#comment" "key= #comment" will result into key == "#comment" "key #comment" is an invalid line
2013-04-18move _cleanup_ attribute in front of the typeHarald Hoyer
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-17core/execute: report invalid environment variables from filesHarald Hoyer
Because "export key=val" is not supported by systemd, an error is logged where the invalid assignment is coming from. Introduce strv_env_clean_log() to log invalid environment assignments, where logging is possible and allowed. parse_env_file_internal() is modified to allow WHITESPACE in keys, to report the issues later on.
2013-04-17fileio:parse_env_file_internal() fix environment file parsingHarald Hoyer
parse_env_file_internal() could not parse the following lines correctly: export key="val" key="val"#comment
2013-04-17fileio: also escape $ and ` when writing out env varsMantas Mikulėnas
These are also considered special by sh and bash.
2013-04-03fileio: don't check for errors more often than really necessaryLennart Poettering
2013-04-03fileio: write proper env var write-out codeLennart Poettering
This will properly escape all weird chars when writing env var files. With this in place we can now read and write environment files where the values contain arbitrary weird chars. This enables hostnamed and suchlike to finally properly save pretty host names with backlashes or quotes in them.
2013-04-03shared: rework env file readerLennart Poettering
Implement this with a proper state machine, so that newlines and escaped chars can appear in string assignments. This should bring the parser much closer to shell.
2013-04-03util: rename write_one_line_file() to write_string_file()Lennart Poettering
You can write much more than just one line with this call (and we frequently do), so let's correct the naming.
2013-03-29Always use errno > 0 to help gccZbigniew Jędrzejewski-Szmek
gcc thinks that errno might be negative, and functions could return something positive on error (-errno). Should not matter in practice, but makes an -O4 build much quieter.
2013-03-13fileio: use _cleanup_Zbigniew Jędrzejewski-Szmek
2013-02-14honor SELinux labels, when creating and writing config filesHarald Hoyer
Also split out some fileio functions to fileio.c and provide a SELinux aware pendant in fileio-label.c see https://bugzilla.redhat.com/show_bug.cgi?id=881577