summaryrefslogtreecommitdiff
path: root/src/basic
Commit message (Collapse)AuthorAge
...
* nspawn: when running nspawn, set a $PATH including both bin + sbin by ↵Lennart Poettering2018-08-24
| | | | | | | | | | | default (#8756) We don't know what the container payload needs, hence default to a PATH with both bin and sbin included, as well as / and /usr. Follow-up for #8324 Fixes: #8698
* terminal: add internal API to format URLs for display in capable terminalsLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | Newer terminals (in particular gnome-terminal) understand special escape sequence for formatting clickable links. Let's support that to make our tool output more clickable where that's appropriate. For details see this: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda The one big issue is that 'less' currently doesn't grok this, and doesn't ignore sequence like regular terminal implementations do if they don't support it. Hence for now, let's disable URL output if a pager is used. We should revisit that though as soon as less added support for it and enough time passed for it to enter various distributions.
* user-util: trivial coding style fixesLennart Poettering2018-08-24
| | | | | Use C's downgrade-to-bool feature when comparing pointers against NULL, as we usually do.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* fs-util: export how many iterations chase_symlinks() executes at maxLennart Poettering2018-08-24
|
* fs-util: add new CHASE_STEP flag to chase_symlinks()Lennart Poettering2018-08-24
| | | | | | | | If the flag is set only a single step of the normalization is executed, and the resulting path is returned. This allows callers to normalize piecemeal, taking into account every single intermediary path of the normalization.
* sysusers: make sure to reset the returned value when EOF is reached in ↵Franck Bui2018-08-24
| | | | | | | | | | | | fget*ent_sane() wrappers (#8737) To indicate that the there're no more entries, these wrappers return false but did leave the passed pointed unmodified. However EOF is not an error and is a very common case so initialize the output argument to NULL even in this case so callers don't need to do that. Fixes: #8721
* basic: add minimalistic table formatterLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have plenty of code in our codebase that outputs tables to the console, and all is homegrown and awful. Let's replace it with a generic implementation that can do automatically what the old implementations did manually. Features: 1. Ellipsation (for fields overly long) and alignment (for fields overly short) 2. Sorting of rows 3. automatically copies formatting from the same cell in the row above 4. Heavy use of varargs to make putting together tables easy 5. can expand and compress tables, with weights 6. Has a minimal understanding of unicode wide characters in order to match unicode strings to character cell terminals. 7. Columns can be reordered and individually turned off. 8. pretty printing for various data types And more.
* pager: move pager.[ch] src/shared/ → src/basic/Lennart Poettering2018-08-24
| | | | | | | | | pager.[ch] doesn't use any APIs from src/libsystemd/ or src/shared/ hence there's no reason for it to be in src/shared/, let's move it to src/basic/ instead. This enables us to use pager.[ch] APIs from other code in src/basic/, for example pager_have() and suchlike.
* string-util: tweak ellipsation a bitLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | This primarily changes to things: 1. Ellipsation to 0, 1 or 2 characters is now supported. Previously we'd hit an assert if the new lengths was < 3, this is now permitted. The result strings won't show too much info still of course, but the code becomes a bit more generic and robust to use. 2. If a UTF-8 mode is disabled and the input string is pure ASCII, then "..." is used for ellipsation, otherwise (as before) "…". This means on a pure-ASCII system we should remain pure-ASCII, matching behaviour otherwise exposed with special_glyph() and friends. Note that we'll use "…" for ellipsiation as soon as either the locale settings indicate an UTF-8 mode or the input string already contains non-ASCII unicode characters. Testing for these special cases is improved.
* util: add qsort_r_safe(), similar to qsort_safe()Lennart Poettering2018-08-24
|
* utf8: add helper call for counting display width of stringsLennart Poettering2018-08-24
|
* locale: add ellipsis as special glyphLennart Poettering2018-08-24
|
* path-lookup: properly chase paths when reducing with root dir (#8750)Lennart Poettering2018-08-24
| | | | Let's make this correct.
* util-lib: introduce new empty_or_root() helper (#8746)Lennart Poettering2018-08-24
| | | | | | | | 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
* path-util: Finish DEFAULT_PATH_NULSTR with an extra NUL (#8745)Filipe Brandenburger2018-08-24
| | | | | | | | | | | The NULSTR_FOREACH iterator needs to see an empty string at the end, so we need to insert an extra NUL explicitly. Also update PATH0_BIN_SBIN(x) to include an extra NUL terminator, rename it to PATH_BIN_SBIN_NULSTR(x), which is more consistent with the similar CONF_PATHS_NULSTR(x) macro. Fixes: 5008da1ec1cf2cf8c15b702c4052e3a49583095d
* basic/copy: fix awkward sentenceZbigniew Jędrzejewski-Szmek2018-08-24
|
* basic/unit-name: remove duplicate checkZbigniew Jędrzejewski-Szmek2018-08-24
| | | | The check that was right below already covers this case.
* systemd: do not require absolute paths in ExecStartZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | Absolute paths make everything simple and quick, but sometimes this requirement can be annoying. A good example is calling 'test', which will be located in /usr/bin/ or /bin depending on the distro. The need the provide the full path makes it harder a portable unit file in such cases. This patch uses a fixed search path (DEFAULT_PATH which was already used as the default value of $PATH), and if a non-absolute file name is found, it is immediately resolved to a full path using this search path when the unit is loaded. After that, everything behaves as if an absolute path was specified. In particular, the executable must exist when the unit is loaded.
* unit-name: add new unit_name_build_from_type() helperLennart Poettering2018-08-24
| | | | | The new helper is much like unit_name_build() but expects a UnitType value instead of a suffix.
* copy: rearrange flags field definitionLennart Poettering2018-08-24
| | | | Let's use the usual 1U << 0,1,2,3,4 spelling for definiting flags enums.
* copy: reduce number of checksLennart Poettering2018-08-24
| | | | | We check max_bytes twice here, let's simplify that, and reduce one level of indentation.
* copy: drop _unlikely_() that isn't obviously the caseLennart Poettering2018-08-24
| | | | | | | | If a tool only invokes copy_bytes() a single time the _unlikely_() will always be wrong, and is hence not useful. Let's drop it and let the compiler figure our what to do, instead of misleading it. Also, some coding style imprvoements.
* copy: hide in copy_bytes() the strange way splice() handles O_NONBLOCKLennart Poettering2018-08-24
| | | | | | splice() ignores O_NONBLOCK on pipes but not on other fds. Let's handle that properly, and query O_ONBLOCK manually in that case, ensuring systematic behaviour in either case.
* copy: extend copy_bytes() a bitLennart Poettering2018-08-24
| | | | | | | Optionally, when we copy between fds with simple read/write, let's return any remaining data we already read into the buffer if write fails. This is useful to allow callers to use the read data otherwise, perhaps implementing a different fallback for copying.
* copy: tweak reflink logic in copy_bytes() a bitLennart Poettering2018-08-24
| | | | | Let's use btrfs_clone_range() if partial copies are desired. And use btrfs_reflink() only for full-file reflinks.
* copy: add brief comment to copy_bytes() explaining its return valuesLennart Poettering2018-08-24
|
* macro: don't rely on C's downgrade-to-bool feature for numeric comparisonsLennart Poettering2018-08-24
|
* path-util: document a few other special cases for last_path_component()Lennart Poettering2018-08-24
|
* process-util: add TAKE_PID(), similar to TAKE_PTR/TAKE_FD, but for child ↵Lennart Poettering2018-08-24
| | | | process PIDs
* util: introduce typesafe_qsort(), a typesafe version of qsort()/qsort_safe()Lennart Poettering2018-08-24
| | | | | | | | | | | | It does two things: 1. It derives the element size from the array argument type 2. It derives the right type for the function from the array argument type Using this macro call should make the invocations of qsort() quite a bit safer.
* 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.
* tmpfiles: add a new return code for "operational failure" when processingZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | Things can fail, and we have no control over it: - file system issues (immutable bits, file system errors, MAC refusals, etc) - kernel refusing certain arguments when writing to /proc/sys or /sys Let's add a new code for the case where we parsed configuration but failed to execute it because of external errors.
* fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)Lennart Poettering2018-08-24
| | | | | Let's optimize things, and let the kernel chase the paths if none of the features chase_symlinks() offers are actually used.
* fs-util: add calls that combine chase_symlinks() and open()/opendir() in oneLennart Poettering2018-08-24
| | | | | This is useful when opening files within disk images, as we'll then take the relative root directory properly into account.
* fd-util: introduce fd_reopen() helper for reopening an fdLennart Poettering2018-08-24
| | | | | | We have the same code for this in place at various locations, let's unify that. Also, let's repurpose test-fs-util.c as a test for this new helper cal..
* tmpfiles: add a new return code for "operational failure" when processingZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | Things can fail, and we have no control over it: - file system issues (immutable bits, file system errors, MAC refusals, etc) - kernel refusing certain arguments when writing to /proc/sys or /sys Let's add a new code for the case where we parsed configuration but failed to execute it because of external errors.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)Lennart Poettering2018-08-24
| | | | | Let's optimize things, and let the kernel chase the paths if none of the features chase_symlinks() offers are actually used.
* fs-util: add calls that combine chase_symlinks() and open()/opendir() in oneLennart Poettering2018-08-24
| | | | | This is useful when opening files within disk images, as we'll then take the relative root directory properly into account.
* fd-util: introduce fd_reopen() helper for reopening an fdLennart Poettering2018-08-24
| | | | | | We have the same code for this in place at various locations, let's unify that. Also, let's repurpose test-fs-util.c as a test for this new helper cal..
* Rename suspend-to-hibernate to suspend-then-hibernateMario Limonciello2018-08-24
| | | | | Per some discussion with Gnome folks, they would prefer this name as it's more descriptive of what's happening.
* util: check for overflows in xbsearch_r()Lennart Poettering2018-08-24
|
* Fix compilation w/o smack (#8593)Zbigniew Jędrzejewski-Szmek2018-08-24
|
* tree-wide: add bsearch_safe and use where appropriateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | Should fix #8557.
* fuzz-unit-file: add __has_feature(memory_sanitizer) when skipping ListenNetlink=Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | https://clang.llvm.org/docs/MemorySanitizer.html#id5 documents this check as the way to detect MemorySanitizer at compilation time. We only need to skip the test if MemorySanitizer is used. Also, use this condition in cg_slice_to_path(). There, the code that is conditionalized is not harmful in any way (it's just unnecessary), so remove the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION condition. Fixes #8482.
* label: rework label_fix() implementations (#8583)Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | This reworks the SELinux and SMACK label fixing calls in a number of ways: 1. The two separate boolean arguments of these functions are converted into a flags type LabelFixFlags. 2. The operations are now implemented based on O_PATH. This should resolve TTOCTTOU races between determining the label for the file system object and applying it, as it it allows to pin the object while we are operating on it. 3. When changing a label fails we'll query the label previously set, and if matches what we want to set anyway we'll suppress the error. Also, all calls to label_fix() are now (void)ified, when we ignore the return values. Fixes: #8566
* fs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | This rearranges chase_symlinks() a bit: if no special flags are specified it will now revert to behaviour before b12d25a8d631af00b200e7aa9dbba6ba4a4a59ff. However, if the new CHASE_TRAIL_SLASH flag is specified it will follow the behaviour introduced by that commit. I wasn't sure which one to make the beaviour that requires specification of a flag to enable. I opted to make the "append trailing slash" behaviour the one to enable by a flag, following the thinking that the function should primarily be used to generate a normalized path, and I am pretty sure a path without trailing slash is the more "normalized" one, as the trailing slash is not really a part of it, but merely a "decorator" that tells various system calls to generate ENOTDIR if the path doesn't refer to a path. Or to say this differently: if the slash was part of normalization then we really should add it in all cases when the final path is a directory, not just when the user originally specified it. Fixes: #8544 Replaces: #8545
* tree-wide: warn when a directory path already exists but has bad mode/owner/typeZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | | | | | | | When we are attempting to create directory somewhere in the bowels of /var/lib and get an error that it already exists, it can be quite hard to diagnose what is wrong (especially for a user who is not aware that the directory must have the specified owner, and permissions not looser than what was requested). Let's print a warning in most cases. A warning is appropriate, because such state is usually a sign of borked installation and needs to be resolved by the adminstrator. $ build/test-fs-util Path "/tmp/test-readlink_and_make_absolute" already exists and is not a directory, refusing. (or) Directory "/tmp/test-readlink_and_make_absolute" already exists, but has mode 0775 that is too permissive (0755 was requested), refusing. (or) Directory "/tmp/test-readlink_and_make_absolute" already exists, but is owned by 1001:1000 (1000:1000 was requested), refusing. Assertion 'mkdir_safe(tempdir, 0755, getuid(), getgid(), MKDIR_WARN_MODE) >= 0' failed at ../src/test/test-fs-util.c:320, function test_readlink_and_make_absolute(). Aborting. No functional change except for the new log lines.
* basic/mkdir: convert bool flag to enumZbigniew Jędrzejewski-Szmek2018-08-24
| | | | In preparation for subsequent changes...