summaryrefslogtreecommitdiff
path: root/src/basic/proc-cmdline.c
Commit message (Collapse)AuthorAgeFilesLines
* proc-cmdline: filter PID1 arguments when we are running in a containerYu Watanabe2023-03-291-6/+82
| | | | | | | | Otherwise, PID1 arguments e.g. "--deserialize 16" may be parsed unexpectedly by generators. Fixes the issue reported at https://github.com/systemd/systemd/issues/24452#issuecomment-1475004433.
* proc-cmdline: introduce proc_cmdline_strv()Yu Watanabe2023-03-291-20/+31
| | | | | | | | | | | When we are running in a container, we parse the command line of PID1 in proc_cmdline_parse() or friends. Previously, first we merge the command line nulstr as a single string, and then split by using extract_first_word(). That's not only redundant, but also unsafe when the command line argument contain a space. This drops the redundant steps, hence we can safely parse arguments with space.
* proc-cmdline: split commandline earlier in proc_cmdline_parse() and friendYu Watanabe2023-03-291-114/+116
| | | | No functional change, just preparation for later commits.
* proc-cmdline: make proc_cmdline_parse_given() staticYu Watanabe2023-03-241-1/+1
| | | | | It is used only in proc-cmdline.c and its test. And the test can be covered by proc_cmdline_parse().
* proc-cmdline: use proc_cmdline_key_string() when we search for keyYu Watanabe2023-03-241-1/+1
|
* proc-cmdline: rename variableYu Watanabe2023-03-241-3/+3
|
* proc-cmdline: insert an empty line between variable declaration and assertionYu Watanabe2023-03-241-0/+1
|
* basic: create new basic/initrd-util.[ch] for initrd-related functionsZbigniew Jędrzejewski-Szmek2022-11-081-1/+1
| | | | | | | | | I changed imports of util.h to initrd-util.h, or added an import of initrd-util.h, to keep compilation working. It turns out that many files didn't import util.h directly. When viewing the patch, don't be confused by git rename detection logic: a new .c file is added and two functions moved into it.
* proc-cmdline: allow backslash escapes when parsing /proc/cmdlineLennart Poettering2021-04-071-1/+1
| | | | | | | | | | | | | | | | So far when parsing /proc/cmdline we'd consider backslashes as mechanisms for escaping whitepace or quotes. This changes things so that they are retained as they are instead. The kernel itself doesn't allow such escaping, and hence we shouldn't do so either (see lib/cmdline.c in the kernel sources; it does support "" quotes btw). This fix is useful to allow specifying backslash escapes in the "root=" cmdline option to be passed through to systemd-fstab-generator. Example: root=/dev/disk/by-partlabel/Root\x20Partition Previously we'd eat up the "\" so that we'd then look for a device /dev/disk/by-partlabel/Rootx20Partition which never shows up.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* efi: Skip parsing SystemdOptions if there's an error getting it.Filipe Brandenburger2020-06-141-7/+9
| | | | | | The original logic was logging an "ignored" debug message, but it was still going ahead and calling proc_cmdline_parse_given() on the NULL line. Fix that to skip that explicitly when the EFI variable wasn't really read.
* proc-cmdline: make checking of EFI options variable optionalLennart Poettering2020-05-201-10/+18
| | | | | | | | | | | | | | | And do not use it in the IMPORT{cmdline} udev code. Wherever we expose direct interfaces to check the kernel cmdline, let's not consult our systemd-specific EFI variable, but strictly use the actual kernel variable, because that's what we claim we do. i.e. it's fine to use the EFI variable for our own settings, but for the generic APIs to the kernel cmdline we should not use it. Specifically, this applies to IMPORT{cmdline} and ConditionKernelCommandLine=. In the latter case we weren#t checking the EFI variable anyway, hence let's do the same for the udev case, too. Fixes: #15739
* proc-cmdline: add checking of EFI options variable in ↵Lennart Poettering2020-05-201-4/+19
| | | | proc_cmdline_get_key_many() too
* proc-cmdline: fix return value clobbering in proc_cmdline_get_key()Lennart Poettering2020-05-201-4/+14
| | | | | Let's make sure proc_cmdline_get_key() follows our coding style: never clobber return values on failure, and always initialize on success.
* proc-cmdline: add some explanatory commentsLennart Poettering2020-05-181-3/+3
|
* efi: honour SYSTEMD_EFI_OPTIONS even if we wouldn't honour SystemdOptions ↵Lennart Poettering2020-04-301-14/+2
| | | | | | EFI var due to SecureBoot Fixes: #14864
* Disable reading SystemdOptions EFI Var when in SecureBoot modeArian van Putten2020-01-161-2/+14
| | | | | | | | | In SecureBoot mode this is probably not what you want. As your cmdline is cryptographically signed like when using Type #2 EFI Unified Kernel Images (https://systemd.io/BOOT_LOADER_SPECIFICATION/) The user's intention is then that the cmdline should not be modified. You want to make sure that the system starts up as exactly specified in the signed artifact.
* Rename "system-options" to "systemd-efi-options"Zbigniew Jędrzejewski-Szmek2019-11-181-2/+2
| | | | | | | | | | | | | | | | This makes the naming more consistent: we now have bootctl systemd-efi-options, $SYSTEMD_EFI_OPTIONS and the SystemdOptions EFI variable. (SystemdEFIOptions would be redundant, because it is only used in the context of efivars, and users don't interact with that name directly.) bootctl is adjusted to use 2sp indentation, similarly to systemctl and other programs. Remove the prefix with the old name from 'bootctl systemd-efi-options' output, since it's redundant and we don't want the old name anyway.
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* Add support for SystemdOptions EFI var to augment /proc/cmdlineZbigniew Jędrzejewski-Szmek2019-09-161-24/+58
| | | | | | | | | | | | In various circumstances, overriding the kernel commandline can be inconvenient. People have different bootloaders, and e.g. the grub config can be pretty scary. grubby helps, but it isn't always available. This option adds an alternative mechanism that can quite convenient on EFI systems. cmdline settings have higher priority, because they can be (usually) changed on the bootloader prompt. $SYSTEMD_EFI_OPTIONS can be used to override, same as $SYSTEMD_PROC_CMDLINE.
* util-lib: move shall_restore_state() to shared/reboot-utilZbigniew Jędrzejewski-Szmek2019-09-161-11/+0
| | | | | It's just a small function, but it is higher-level functionality. I don't see a good place for it, reboot-util.[ch] seems least bad
* util-lib: move runlevel_to_target() to shared/unit-fileZbigniew Jędrzejewski-Szmek2019-09-161-44/+0
| | | | | | | It if of course related to /proc/cmdline parsing, but is higher-level functionality built on top of it. It should be in shared/ because it is something to be used by pid1 and related utilities, not something for level-level libraries.
* Rename EXTRACT_QUOTES to EXTRACT_UNQUOTEZbigniew Jędrzejewski-Szmek2019-06-281-1/+1
| | | | | | Whenever I see EXTRACT_QUOTES, I'm always confused whether it means to leave the quotes in or to take them out. Let's say "unquote", like we say "cunescape".
* basic/process-util: convert bool arg to flagsZbigniew Jędrzejewski-Szmek2019-05-221-1/+1
| | | | In preparation for the next commit…
* Rework cmdline printing to use unicodeZbigniew Jędrzejewski-Szmek2019-05-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The functions to retrieve and print process cmdlines were based on the assumption that they contain printable ASCII, and everything else should be filtered out. That assumption doesn't hold in today's world, where people are free to use unicode everywhere. This replaces the custom cmdline reading code with a more generic approach using utf8_escape_non_printable_full(). For kernel threads, truncation is done on the parenthesized name, so we'll get "[worker]", "[worker…]", …, "[w…]", "[…", "…" as we reduce the number of available columns. This implementation is most likely slower for very long cmdlines, but I don't think this is very important. The common case is to have short commandlines, and should print those properly. Absurdly long cmdlines are the exception, which needs to be handled correctly and safely, but speed is not too important. Fixes #12532. v2: - use size_t for the number of columns. This change propagates into various other functions that call get_process_cmdline(), increasing the size of the patch, but the changes are rather trivial.
* proc-cmdline: introduce new proc_cmdline_get_key_many() helperLennart Poettering2018-11-141-0/+56
| | | | This is like parse_env_file(), but from the kernel command line
* proc-cmdline: split out rd. prefix handling in proc_cmdline_parse_given() ↵Lennart Poettering2018-11-141-45/+62
| | | | | | | | | | | | and proc_cmdline_get_key() This introduces a wrapper around extrac_first_word() called proc_cmdline_extract_first(), which suppresses "rd." parameters depending on the specified calls. This allows us to share more code between proc_cmdline_parse_given() and proc_cmdline_get_key(), and makes it easier to reuse this logic for other purposes.
* proc-cmdline: turn flags parameter into a proper typedef'ed enumLennart Poettering2018-11-141-3/+3
| | | | Let's add some extra typesafety.
* proc-cmdline: teach proc_cmdline_get_key() the same flags magic as ↵Lennart Poettering2018-10-261-4/+14
| | | | proc_cmdline_parse()
* proc-cmdline: use FLAGS_SET() where appropriateLennart Poettering2018-10-261-5/+6
| | | | | | | This was mostly prompted by seeing the expression "in_initrd() && flags & PROC_CMDLINE_RD_STRICT", which uses & and && without any brackets. Let's make that a bit more readable and hide all doubts about operator precedence.
* proc-cmdline: introduce PROC_CMDLINE_RD_STRICTLukas Nykryn2018-10-251-1/+2
| | | | | | | | Our current set of flags allows an option to be either use just in initrd or both in initrd and normal system. This new flag is intended to be used in the case where you want apply some settings just in initrd or just in normal system.
* basic/proc-cmdline: allow parsing of cmdline from a stringZbigniew Jędrzejewski-Szmek2018-10-081-6/+14
| | | | | | | | | Comes with tests. Also add direct test for $SYSTEMD_PROC_CMDLINE. In test-proc-cmdline, "true" was masquerading as PROC_CMDLINE_STRIP_RD_PREFIX, fix that. Also, reorder functions to match call order.
* Drop empty lines in proc-cmdline.cZbigniew Jędrzejewski-Szmek2018-10-081-3/+0
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | 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-06-141-2/+0
| | | | | | | | | | | | | | | | 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.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | 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.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-4/+2
| | | | | | | | | | | | | | | | 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)
* Merge pull request #7198 from poettering/stdin-stdoutLennart Poettering2017-11-191-5/+9
|\ | | | | Add StandardInput=data, StandardInput=file:... and more
| * proc-cmdline: minor runlevel_to_target() coding style fixesLennart Poettering2017-11-171-5/+9
| | | | | | | | | | Let's not mix function calls and variable declarations, as well as assignments and comparison in one expression.
* | Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
|/ | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* Fix missing space in comments (#5439)AsciiWolf2017-02-241-1/+1
|
* tree-wide: remove consecutive duplicate words in comments (#5148)Stefan Schweter2017-01-241-1/+1
|
* util-lib: various improvements to kernel command line parsingLennart Poettering2016-12-211-25/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves kernel command line parsing in a number of ways: a) An kernel option "foo_bar=xyz" is now considered equivalent to "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and "_" are now considered equivalent (this only applies to the option names though, not the option values!). Most of our kernel options used "-" as word separator in kernel command line options so far, but some used "_". With this change, which was a source of confusion for users (well, at least of one user: myself, I just couldn't remember that it's systemd.debug-shell, not systemd.debug_shell). Considering both as equivalent is inspired how modern kernel module loading normalizes all kernel module names to use underscores now too. b) All options previously using a dash for separating words in kernel command line options now use an underscore instead, in all documentation and in code. Since a) has been implemented this should not create any compatibility problems, but normalizes our documentation and our code. c) All kernel command line options which take booleans (or are boolean-like) have been reworked so that "foobar" (without argument) is now equivalent to "foobar=1" (but not "foobar=0"), thus normalizing the handling of our boolean arguments. Specifically this means systemd.debug-shell and systemd_debug_shell=1 are now entirely equivalent. d) All kernel command line options which take an argument, and where no argument is specified will now result in a log message. e.g. passing just "systemd.unit" will no result in a complain that it needs an argument. This is implemented in the proc_cmdline_missing_value() function. e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key() that parses booleans (following the logic explained in c). f) The proc_cmdline_parse() call's boolean argument has been replaced by a new flags argument that takes a common set of bits with proc_cmdline_get_key(). g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix. h) There are now tests for much of this. Yay!
* util-lib: read $SYSTEMD_PROC_CMDLINE if set when looking for the kernel cmdlineLennart Poettering2016-12-211-0/+14
| | | | | | if we want to parse the kernel command line, let's check the $SYSTEMD_PROC_CMDLINE environment variable first. This is useful for debugging purposes.
* tree-wide: make parse_proc_cmdline() strip "rd." prefix automaticallyZbigniew Jędrzejewski-Szmek2016-10-221-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | This stripping is contolled by a new boolean parameter. When the parameter is true, it means that the caller does not care about the distinction between initrd and real root, and wants to act on both rd-dot-prefixed and unprefixed parameters in the initramfs, and only on the unprefixed parameters in real root. If the parameter is false, behaviour is the same as before. Changes by caller: log.c (systemd.log_*): changed to accept rd-dot-prefix params pid1: no change, custom logic cryptsetup-generator: no change, still accepts rd-dot-prefix params debug-generator: no change, does not accept rd-dot-prefix params fsck: changed to accept rd-dot-prefix params fstab-generator: no change, custom logic gpt-auto-generator: no change, custom logic hibernate-resume-generator: no change, does not accept rd-dot-prefix params journald: changed to accept rd-dot-prefix params modules-load: no change, still accepts rd-dot-prefix params quote-check: no change, does not accept rd-dot-prefix params udevd: no change, still accepts rd-dot-prefix params I added support for "rd." params in the three cases where I think it's useful: logging, fsck options, journald forwarding options.
* tree-wide: allow state to be passed through to parse_proc_cmdline_itemZbigniew Jędrzejewski-Szmek2016-10-221-2/+2
| | | | No functional change.
* core: parse `rd.rescue` and `rd.emergency` as initrd-specific shorthands (#3488)Ivan Shapovalov2016-06-131-3/+15
| | | Typing `rd.rescue` is easier than `rd.systemd.unit=rescue.target`.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-0/+4
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* Merge pull request #1744 from evverx/fix-debug-generatorLennart Poettering2015-11-031-0/+29
|\ | | | | debug-generator: respect kernel parameters for default unit setting