summaryrefslogtreecommitdiff
path: root/src/basic
Commit message (Collapse)AuthorAge
* tree-wide: drop unused variablesYu Watanabe2018-08-24
| | | | Follow-ups for #8620.
* conf-files: beef up conf-files.[ch] a bitLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds fozr new flags: - If CONF_FILES_DIRECTORY is specified conf_file_list() and friends will look for directories only. - Similar CONF_FILES_REGULAR means we'll look only for regular files. - If CONF_FILES_BASENAME is specified the resulting list will contain only the basenames of all discovered files or directories, not the full paths. - If CONF_FILES_FILTER_MASKED is specified the resulting list will have masked entries removed (i.e. those symlinked to /dev/null and suchlike) These four flags are useful for discovering portable service profile information. While we are at it, also improve a couple of other things: - More debug logging - use path_hash_ops instead of string_hash_ops when putting together the path lists
* fileio: make sure read_full_stream() works on memory-backed streamsLennart Poettering2018-08-24
|
* os-util: add helpers for finding /etc/os-releaseLennart Poettering2018-08-24
| | | | | Place this new helpers in a new source file os-util.[ch], and move the existing and related call path_is_os_tree() to it as well.
* 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.
* process-util: add a new FORK_MOUNTNS_SLAVE flag for safe_fork()Lennart Poettering2018-08-24
| | | | | | | | We already have a flag for creating a new mount namespace for the child. Let's add an extension to that: a new FORK_MOUNTNFS_SLAVE flag. When used in combination will mark all mounts in the child namespace as MS_SLAVE so that the child can freely mount or unmount stuff but it won't leak into the parent.
* fd-util: add new helper call fd_duplicate_data_fd()Lennart Poettering2018-08-24
| | | | | | | | | | | | This call creates an fd from another fd containing the same data. Specifically, repeated read() on the returned fd should return the same data as the original fd. This call is useful when we want to copy data out of disk images and suchlike, and want to be pass fds with the data around without having to keep the disk image continously mounted. The implementation tries to be somewhat smart and tries to prefer memfds/pipes over files in /tmp or /var/tmp based on the size of the data, but has appropropriate fallbacks in place.
* basic: fix raw_clone() on 32-bit sparcMike Gilbert2018-08-24
| | | | | | | The clone syscall uses the same semantics as on 64-bit. The trap number for syscall entry is different. Bug: https://bugs.gentoo.org/656368
* util: add debug logging to system_tasks_max()Lennart Poettering2018-08-24
| | | | | We should always do debug logging when we eat up error conditions. Let's do so here too.
* util: fix physical_memory() to work correctly on cgroupsv2Lennart Poettering2018-08-24
| | | | | | | Let's look into the right cgroupsv2 attribute. Also, while we are at it, add debug logging for all error conditions we eat up silently otherwise.
* nspawn: make sure our container PID 1 keeps logging to the original stderr ↵Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | as long as possible If we log to the pty that is configured as stdin/stdout/stderr of the container too early we risk filling it up in full before we start processing the pty from the parent process, resulting in deadlocks. Let's hence keep a copy of the original tty we were started on before setting up stdin/stdout/stderr, so that we can log to it, and keep using it as long as we can. Since the kernel's pty internal buffer is pretty small this actually triggered deadlocks when we debug logged at lot from nspawn's child processes, see: https://github.com/systemd/systemd/pull/9024#issuecomment-390403674 With this change we won't use the pty at all, only the actual payload we start will, and hence we won't deadlock on it, ever.
* tree-wide: remove some double newlines in headers, tooLennart Poettering2018-08-24
|
* basic/rm-rf: include the path in error messagesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | Attempted to remove disk file system under "/tmp/systemd-temporary-aWPkbQ", and we can't allow that.
* string-table: add new DUMP_STRING_TABLE() macroLennart Poettering2018-08-24
| | | | | | | | | | | The macro is inspired by the other string table macros, and takes the same arguments in the same order and dumps a string table to stdout. Since it's typesafe it's nice to implement this as macro rather than regular function. This new macro is useful for implementing commands such as "systemctl -t help" and similar, i.e. wherever we want to dump all values of an enum to stdout.
* fs-util: don't alter errno in unlink_tempfilep()Lennart Poettering2018-08-24
| | | | | | | | | | | Functions whose only purpose is to be used with _cleanup_() should not touch errno, so that failing removals do not alter errno at unexpected places. This is already done in unlink_and_freep(), rmdir_and_freep(), rm_rf_physical_and_freep(), hence do so for unlink_tempfilep(), too. Follow-up for #9013
* Use STRLEN in two placesZbigniew Jędrzejewski-Szmek2018-08-24
|
* tree-wide: do not wrap assert_se in extra parenthesesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | We were inconsitently using them in some cases, but in majority not. Using assignment in assert_se is very common, not an exception like in 'if', so let's drop the extra parens everywhere.
* fs-util,test: add helper to remove tempfilesZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | This simplifies the use of tempfiles in tests and fixes "leaked" temporary files in test-fileio, test-catalog, test-conf-parser. Not the whole tree is converted.
* path-util: one more empty_or_root() changeLennart Poettering2018-08-24
|
* process-util: add new helper call for adjusting the OOM scoreLennart Poettering2018-08-24
| | | | And let's make use of it in execute.c
* basic: split parsing of the OOM score adjust value into its own function in ↵Lennart Poettering2018-08-24
| | | | | | | | | | parse-util.c And port config_parse_exec_oom_score_adjust() over to use it. While we are at it, let's also fix config_parse_exec_oom_score_adjust() to accept an empty string for turning off OOM score adjustments set earlier.
* basic: be more careful when closing fds based on RLIMIT_NOFILELennart Poettering2018-08-24
| | | | | Let's make sure we properly handle cases where RLIMIT_NOFILE is set to infinity, zero or values outside of the "int" range.
* Turn VALGRIND variable into a meson configuration switchZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Configuration through environment variable is inconvenient with meson, because they cannot be convieniently changed and/or are not preserved during reconfiguration (https://github.com/mesonbuild/meson/issues/1503). This adds -Dvalgrind=true/false, which has the advantage that it can be set at any time with meson configure -Dvalgrind=... and ninja will rebuild targets as necessary. Additional minor advantages are better consistency with the options for hashmap debugging, and typo avoidance with '#if' instead of '#ifdef'.
* basic: add log_level argument to timezone_is_validMike Gilbert2018-08-24
|
* basic: timezone_is_valid: check for magic bytes "TZif"Mike Gilbert2018-08-24
| | | | Fixes: https://github.com/systemd/systemd/issues/8905
* hexdecoct: drop an unnecessary checkYu Watanabe2018-08-24
|
* basic: fix comment styleYu Watanabe2018-08-24
|
* hexdecoct: ignore whitespace within the input hexadecimal text of unhexmem()Yu Watanabe2018-08-24
|
* terminal-util: add a function that shows a pretty separator lineLennart Poettering2018-08-24
| | | | Follow-up for #8824
* string-util: rename strdash_if_empty() to empty_to_dash()Yu Watanabe2018-08-24
|
* path-util: introduce empty_to_root() and use it many placesYu Watanabe2018-08-24
|
* basic/terminal-util: fix output of files without a final newlineZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | If the main config file or one of the drop-ins did not have the final newline, there would be no seperating empty line (or if this was the last file displayed, our own output would end without the final newline, possibly running into the subsequent prompt or such). copy_bytes() does not know anything about lines, so let's just use a normal loop with read_line() and puts().
* analyze: add --root option for cat-configZbigniew Jędrzejewski-Szmek2018-08-24
|
* sysusers: add --cat-configZbigniew Jędrzejewski-Szmek2018-08-24
|
* tmpfiles: add --cat-configZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | This implements similar logic as conf_files_cat(), but with slightly different file gathering logic. I also want to add support for replacement files later on, so it seems better to keep those two file-gathering functions separate.
* analyze: add 'cat-config' verbZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is used as 'systemd-analyze show-config systemd/logind.conf', which will dump /etc/systemd/system/user@.service /etc/systemd/system/user@.service.d/*.conf /run/systemd/system/user@.service.d/*.conf /usr/local/lib/systemd/system/user@.service.d/*.conf /usr/lib/systemd/system/user@.service.d/*.conf The idea is to make it easy to dump the configuration using the same locations and order that systemd programs use themselves (including masking, in the right order, etc.). This is the generic variant that works with any configuration scheme that follows the same general rules: $ systemd-analyze cat-config systemd/system.conf $ systemd-analyze cat-config systemd/user.conf $ systemd-analyze cat-config systemd/logind.conf $ systemd-analyze cat-config systemd/sleep.conf $ systemd-analyze cat-config systemd/journald.conf $ systemd-analyze cat-config systemd/journal-remote.conf $ systemd-analyze cat-config systemd/journal-upload.conf $ systemd-analyze cat-config systemd/coredump.conf $ systemd-analyze cat-config systemd/resolved.conf $ systemd-analyze cat-config systemd/timesyncd.conf $ systemd-analyze cat-config udev/udev.conf
* Move function to cat file & dropins into basic/Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | This fixes a buglet where the second and later drop-in would not be seperated properly by a newline.
* basic: use automatic cleanup moreDavid Tardon2018-08-24
|
* basic: use automatic cleanup moreDavid Tardon2018-08-24
|
* basic/fs-util: remove logically dead codeZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | We can jump to chase_one from two places. In the first 'todo' is set to 'buffer', which comes from path_make_absolute_cwd() and is nonnull In the second 'todo' is set to 'joined' which is checked to be nonull a few lines above the jump. So let's kill the code that deals with null todo there. CID #1390941.
* basic/format-table: add missing va_end()Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | CID #1390930, #1390940.
* meson: recompile all sources for install_libudev_static and ↵Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | install_libsystemd_static This means that when those targets are built, all the sources are built again, instead of reusing the work done to create libbasic.a and other convenience static libraries. It would be nice to not do this, but there seems to be no support in our toolchain for joining multiple static libraries into one. When linking a static library, any -l arguments are simply ignored by ar/gcc-ar, and .a libraries given as positional arguments are copied verbatim into the archive so they objects in them cannot be accessed. https://stackoverflow.com/questions/2157629/linking-static-libraries-to-other-static-libraries suggests either unzipping all the archives and putting them back togather, or using a linker script. Unzipping and zipping back together seems ugly. The other option is not very nice. The linker script language does not allow "+" to appear in the filenames, and filenames that meson generates use that, so files would have to be renamed before a linker script was used. And we would have to generate the linker script on the fly. Either way, this doesn't seem attractive. Since those static libraries are a niche use case, it seems reasonable to just go with the easiest and safest solution and recompile all the source files. Thanks to ccache, this is probably almost as cheap as actually reusing the convenience .a libraries. test-libsystemd-sym.c and test-libudev-sym.c compile fine with the generated static libs, so it seems that they indeed provide all the symbols they should.
* time-util: fix indentation for commentsYu Watanabe2018-08-24
|
* util: rename signal_from_string_try_harder() to signal_from_string()Yu Watanabe2018-08-24
| | | | | Also this makes the new `signal_from_string()` function reject e.g, `SIG3` or `SIG+5`.
* util: make signal_from_string() accept RTMIN, RTMAX, and RTMAX-nYu Watanabe2018-08-24
| | | | | | | | | | Before this, `signal_from_string()` accepts simple signal name or RTMIN+n. This makes the function also accept RTMIN, RTMAX, and RTMAX-n. Note that RTMIN+0 is equivalent to RTMIN, and RTMAX-0 is to RTMAX. This also fixes the integer overflow reported by oss-fuzz #8064. https://oss-fuzz.com/v2/testcase-detail/5648573352902656
* virt: simplificationsLennart Poettering2018-08-24
| | | | | | | | | | Let's simplify the code a bit. Let's reduce the number of redundant if checks a bit, (i.e. if we want to check for equality with VIRTUALIZATION_VM_OTHER there's no need to check for non-equality with VIRTUALIZATION_NONE first). As a very welcome side-effect this means we lose some lines of code and our level of indentation is reduced. No changes in behaviour.
* virt: if we detect Xen by DMI, trust that over CPUIDLennart Poettering2018-08-24
| | | | | | | Apparently Xen sometimes lies about its identity when queried via CPUID. Let's hence prefer DMI tests for CPUID Fixes: #8844
* util: rename signal_from_string_try_harder() to signal_from_string()Yu Watanabe2018-08-24
| | | | | Also this makes the new `signal_from_string()` function reject e.g, `SIG3` or `SIG+5`.
* util: make signal_from_string() accept RTMIN, RTMAX, and RTMAX-nYu Watanabe2018-08-24
| | | | | | | | | | Before this, `signal_from_string()` accepts simple signal name or RTMIN+n. This makes the function also accept RTMIN, RTMAX, and RTMAX-n. Note that RTMIN+0 is equivalent to RTMIN, and RTMAX-0 is to RTMAX. This also fixes the integer overflow reported by oss-fuzz #8064. https://oss-fuzz.com/v2/testcase-detail/5648573352902656