Commit graph

66 commits

Author SHA1 Message Date
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
Zbigniew Jędrzejewski-Szmek 388d2993ec shared/bootspec: avoid going through -1 when calculating array index
Coverity was complaining in CID#1399407 that config->entries might be used
while NULL. Let's add an assert to make sure it's not.

Also, let's quit early if we have no entries to loop through. The code was
not incorrect, but it's cleaner to avoid any negative indices.
2019-03-12 13:32:45 +01:00
Zbigniew Jędrzejewski-Szmek bd29f9de69 shared/bootspec: do not fail on errors when reading EFI vars
It seems that my EFI storage is corrupted. The kernel reports the file as present, but returns
an error when reading. Nevertheless, this shouldn't prevent me from reading the entry
list.

Fixes #11909.
2019-03-06 22:49:52 +01:00
Zbigniew Jędrzejewski-Szmek 1f18d94215 shared/bootspec: treat empty EFI vars as missing
We shouldn't really make any fuss about this. Also, change 'var' to 'variable'
for consistency with systemctl.c.
2019-03-06 22:45:37 +01:00
Zbigniew Jędrzejewski-Szmek f40999f878 shared/bootspec: minor simplification 2019-03-06 22:21:34 +01:00
Lennart Poettering eed7210a5c bootspec: validate bootpsec entry ids before we use them 2019-03-05 16:50:58 +01:00
Lennart Poettering 38bd74d67e bootspec: get rid of find_default_boot_entry() entirely
Now only two operations are left. Let's just move this into the caller,
since it should make things simpler, clearer and shorter, in particular
as there's only a single user for this.
2019-03-05 16:50:58 +01:00
Lennart Poettering b1a8771996 bootspec: rework find_default_boot_entry() to use boot_entries_load_config_auto()
it's pretty much the same code now, hence use it.
2019-03-05 16:50:58 +01:00
Lennart Poettering eea4ce1ec7 bootspec: introduce new helper boot_entries_load_config_auto()
It's a simple wrapper around boot_entries_load_config(), but determines
the ESP/XBOOTLDR paths automatically at first. Also, it looks for a path
/run/boot-loader-entries/ and loads the entries from there if it
exists. This is supposed to be a hook for other boot loaders to make our
tools aware of their own entries.
2019-03-05 16:50:58 +01:00
Lennart Poettering dba33c4a2c bootspec: correct error code shown in log msg 2019-03-05 16:50:58 +01:00
Lennart Poettering 93f14ce28d bootspec: move augmentation of loader-discovered entries into bootspec.c
Previously, bootctl would show boot loader entries discovered by the
boot loader which couldn't found locally separately in the output.

Let's move this code into bootspec.c, and beef it up a bit. This way we
can use it later on for logind, and correctly show automatically
discovered windows/macos entries too.
2019-03-05 16:50:58 +01:00
Lennart Poettering 5b1da1ba6d bootspec: simplify find_default_boot_entry()
If the only caller passes NULL for the two paths, let's remove the
parameter altogether.
2019-03-05 16:50:58 +01:00
Lennart Poettering 7800322ca5 bootspec: move log msg from systemctl.c to bootspec.c
find_default_boot_entry() is only used by systemctl.c, and currently
handles one log message in the caller instead of the callee. Let's
simplify that and move it over, too
2019-03-05 16:50:58 +01:00
Lennart Poettering 8312d69409 bootspec: stat() on an autofs mount point doesn't trigger it, let's hence do it explicitly 2019-03-01 12:41:32 +01:00
Lennart Poettering dd2bf34cd0 bootspec: only sort entries list once
Instead of re-sorting entries list each time we loaded enrties from a
specific source, let's just sort them once at the end.
2019-03-01 12:41:32 +01:00
Lennart Poettering 5e146a75b3 bootspec: also look for boot loader spec type 2 entries (i.e. unified kernel images)
sd-boot reads them, and hence we should from our userspace side too
2019-03-01 12:41:32 +01:00
Lennart Poettering 4a4994b68d bootspec: use verify_fsroot_dir() in verify_xbootldr() too
Let's share some code between verify_xbootldr() and verify_esp().
2019-03-01 12:41:32 +01:00
Lennart Poettering 85d021023f bootspec: also optoinally validate XBOOTLDR partition with udev insteado of blkid 2019-03-01 12:41:32 +01:00
Lennart Poettering 18ae9ef1a5 bootspec: split out code that validates whether directory is top-level dir of fs
Let's add a new function that checks whether some directory is the
top-level directory inside an fs, splitting out the code for this from
verify_esp().

While we are at it, let's slightly improve the code, so that we can
correctly work if we have no priviliges but the ESP is mounted
unaccessible: if we can't stat() the path "$ESP/.." then manually remove
the last component of $ESP and check that instead. Which is very similar
in behaviour, and hopefully good enough in the unprivileged case.
2019-03-01 12:41:32 +01:00
Lennart Poettering cedb9eec76 bootspec: if unprivileged validate partition data with udev rather than blkid directly
udev metadata access works unprivileged, which the blkid stuff doesn't
(as that needs raw device node access). Hence let's use udev if we lack
privs, and raw device access only if root.
2019-03-01 12:41:32 +01:00
Lennart Poettering ad95aa44d6 bootspec: also split out XBOOTLDR partition blkid code into its own function 2019-03-01 12:41:32 +01:00
Lennart Poettering 575d437032 bootspec: split out ESP blkid validation into function of its own
This makes it easier to add an alternative implementation for this that
uses sd-device instead of blkid directly.
2019-03-01 12:41:32 +01:00
Lennart Poettering 23953a3ef8 bootspec: add comment explaining verify_esp() return codes 2019-03-01 12:41:32 +01:00
Lennart Poettering a7afbd60e3 bootspec: use SYNTHETIC_ERRNO() where appropriate 2019-03-01 12:41:32 +01:00
Lennart Poettering a2f8664e9a bootspec: load entries from both the ESP and XBOOTLDR partitions
Let's simply search in both.
2019-03-01 12:41:32 +01:00
Lennart Poettering 43b736a84b bootspec: store 'root' field in each bootspec entry we load
This 'root' field contains the root path of the partition we found the
snippet in. The 'kernel', 'initrd', 'efi', … fields are relative to this
path.

This becomes particularly useful later when we add support for loading
snippets from both the ESP and XBOOTLDR, but already simplifies the code
for us a bit in systemctl.
2019-03-01 12:41:32 +01:00
Lennart Poettering 15cb6c9897 bootspec: add internal APIs to discover the XBOOTLDR partition 2019-03-01 12:41:32 +01:00
Lennart Poettering 46bba8a51c bootspec: use SYNTHETIC_ERRNO() at one more place 2019-03-01 12:41:32 +01:00
Lennart Poettering feb41f1ffe bootspec: update log message, to indicate the error is ignored 2019-03-01 12:41:32 +01:00
Lennart Poettering 54b22b2643 tree-wide: port various parts of the code over to the new device_major_minor_path() calls 2018-11-29 20:21:39 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Lennart Poettering cc7a0bfa15 bootspec: introduce SYSTEMD_ESP_PATH for overriding where to look for the ESP (#10834) 2018-11-20 12:37:01 +09:00
Lennart Poettering 8cbb7d8783 efi: allow ESP validity checks to be turned off
let's add an env var for this, as this really shouldn't be a top-level
feature, as it turning off the validity checks certainly isn't
advisable.

Fixes: #4925
2018-10-08 21:40:44 +02:00
Lennart Poettering 9c4a6c1319 bootspec: access EFI variables on on EFI boots 2018-10-08 21:40:44 +02:00
Lennart Poettering f91ed3dc81 bootspec: it's fine if loader.conf is absent
We shouldn't generate an error in that case, as the file is optional.
2018-10-08 21:40:44 +02:00
Lennart Poettering 0de2e1fd2e bootspec: reduce number of functions we export
Let's internalize these four calls as noone else calls them.
2018-10-08 21:40:44 +02:00
Lennart Poettering 21f7a622d5 bootspec: remove redundant logging
boot_loader_read_conf(), boot_entries_find(), boot_entries_load_config()
all log their errors internally, hence no need to log a second or third
time about the same error when they return.
2018-10-08 21:40:44 +02:00
Zbigniew Jędrzejewski-Szmek 2d3bfb6904 shared/bootspec: remember the full path to boot entry and use it in logging
It's much easier to understand what is going on when the full path is
logged.
2018-10-08 17:05:17 +02:00
Zbigniew Jędrzejewski-Szmek 1b20d88987 Move logic to find default sd-boot entry from systemctl to shared
In preparation for use in other places. No functional change.
2018-10-08 16:06:26 +02:00
Lennart Poettering 12580bc3ed bootspec: rename "filename" field to "id"
This follows the renaming done a few commits earlier too systemd-boot
itself.

Also, let's show the ID, since it's useful.
2018-09-27 17:31:37 +02:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Zbigniew Jędrzejewski-Szmek 58f21e63b4 Fix SPDX license tags 2018-06-14 13:05:41 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
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.
2018-06-14 10:20:20 +02:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
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.
2018-04-06 18:58:55 +02:00
Zbigniew Jędrzejewski-Szmek 790f84eb92 shared/bootspec: look at the correct variable
The result of this parsing isn't used for anything, so this didn't cause a
functional difference, but a spurious warning was emitted.
2018-03-08 12:06:14 +01:00
Zbigniew Jędrzejewski-Szmek 48af1eb6ee Merge pull request #8086 from hdante/sdboot-setmode-v2 2018-03-07 10:41:44 +01:00