Commit Graph

55 Commits

Author SHA1 Message Date
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
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)
2018-03-22 20:21:42 +01:00
Lennart Poettering 846ab104ca efivars: if OsIndicationsSupported does not exist, assume that reboot-to-firmware is not available
It's not advertised and hence not available.

Fixes: #7424
2017-11-24 12:00:09 +01:00
Lennart Poettering e22c567fea efivars: minor coding style improvements 2017-11-24 12:00:09 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Lennart Poettering e1e26566ec efivars: don't crash when somebody wants to remove an efi variable
This corrects b3c908b4a2 by allowing a
NULL value again for variable deletion.

Fixes: #6753
2017-09-08 17:34:11 +02:00
Thomas Hindoe Paaboel Andersen b3c908b4a2 shared: assert the source for memcpy 2017-04-28 23:56:44 +02:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen a8fbdf5424 shared: include what we use
The next step of a general cleanup of our includes. This one mostly
adds missing includes but there are a few removals as well.
2015-12-06 13:49:33 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 15a5e95075 util-lib: split out printf() helpers to stdio-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering a09561746f util-lib: introduce dirent-util.[ch] for directory entry calls
Also, move a couple of more path-related functions to path-util.c.
2015-10-27 13:25:56 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 75f86906c5 basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This
simplifies things quite a bit, and makes virtualization detection more
similar to architecture detection.
2015-09-07 13:42:47 +02:00
Lennart Poettering 6b62bbbc7b logind: some firmware implementations remove OsIndications if it is unset
We shouldn't fall over that, and just assume it is 0 in this case.

Fixes #499.
2015-07-11 17:32:25 -03:00
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +02:00
Tom Gundersen b28ce7c6db shared: efivars - fix compile on non-EFI systems
systemctl and logind were unconditionally using functions that were not compiled
on non-EFI systems. Add stubs returning -EOPNOTSUPP to fix compile again.
2015-04-10 19:55:49 +02:00
Tom Gundersen 9df49b3358 shared: efivars - is_efi_*() returns bool instead of int
There was a bug where is_efi_*() could return a negative error value, which would be treated as 'true',
just make this a bool in the helper library to avoid the problem.
2015-04-10 19:55:49 +02:00
Jan Janssen 5bdf22430e logind,systemctl: add reboot to EFI firmware support 2015-04-07 18:51:45 +02:00
Zbigniew Jędrzejewski-Szmek ad7bcf526d efivars: itialize variable
Introduced a few commits ago.
2015-03-09 22:10:54 -04:00
Zbigniew Jędrzejewski-Szmek 7432b24b83 efivars: use greedy_realloc 2015-03-09 16:45:28 -04:00
Zbigniew Jędrzejewski-Szmek 0797f2329c efivars: use more _cleanup_
Also rename r to buf, since r is customarily reserved for the return value.
2015-03-09 16:45:27 -04:00
Zbigniew Jędrzejewski-Szmek 0aa3b7830f efivars: do binary and before converting to bool
I'm pretty sure that this is what was meant here.
2015-03-09 16:45:27 -04:00
Zbigniew Jędrzejewski-Szmek a8436474fa efivars: rename last remaining err to r 2015-03-09 16:45:27 -04:00
Zbigniew Jędrzejewski-Szmek b7749eb517 efivars: modernization
Fix return value if unlink fails.
2015-03-09 16:45:27 -04:00
Lennart Poettering 885fdebc13 tree-wide: use _packed_ macro instead of raw gcc __attribute__ 2015-03-09 18:02:22 +01:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Kay Sievers 0974a682d1 bootctl: add sd-boot support 2015-02-17 14:36:59 +01:00
Lennart Poettering 7e8185ef94 fix a couple of more lazy "return -1"
Fix should strictly follow the rule to return negative errno-style
error codes from functions, hence let's fix more "return -1"-style
lazinesses.
2014-08-11 18:35:54 +02:00
Lennart Poettering 73b80ec2d9 gpt-auto-generator: automatically find the root disk of the system
When run in an initrd and no root= argument is set (or is set to
root=gpt-auto) we will automatically look for the root partition on the
same disk the EFI ESP is located on.

Since we look for swap, /home and /srv on the disk the root partition is
located on, we hence have a fully discoverable chain:

    Firmware discovers the EFI ESP partition → the initrd discovers the
    root partition → the host OS discovers swap, /home, and /srv.

Note that this requires an EFI boot loader that sets the
LoaderDevicePartUUID EFI variable, such as Gummiboot.
2014-03-07 04:31:26 +01:00
Lennart Poettering 39883f622f make gcc shut up
If -flto is used then gcc will generate a lot more warnings than before,
among them a number of use-without-initialization warnings. Most of them
without are false positives, but let's make them go away, because it
doesn't really matter.
2014-02-19 17:53:50 +01:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Zbigniew Jędrzejewski-Szmek 7ff7394d9e Never call qsort on potentially NULL arrays
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-10-13 17:56:54 -04:00
Lennart Poettering 62678deda2 efi: never call qsort on potentially NULL arrays 2013-10-02 19:45:12 +02:00
Kay Sievers c51d84dc09 support acpi firmware performance data (FPDT)
Prefer firmware-provided performance data over loader-exported ones; if
ACPI data is available, always use it, otherwise try to read the loader
data.

The firmware-provided variables start at the time the first EFI image
is executed and end when the operating system exits the boot services;
the (loader) time calculated in systemd-analyze increases.
2013-09-24 15:43:41 +02:00
Zbigniew Jędrzejewski-Szmek 5483a18693 efivars: un-leak a few strings 2013-04-04 22:46:19 -04:00
Zbigniew Jędrzejewski-Szmek 742af54adc efivars: fix return code
Was returning 1 on read error.
2013-03-21 22:39:24 -04:00
Kay Sievers bc6f2e7c62 bootctl: print secure boot flags 2013-03-10 22:48:27 +01:00
Kay Sievers 02a6fc3ea6 efi: compare by substraction 2013-02-17 19:54:29 +01:00
Lennart Poettering b872e9a059 build-sys: make EFI support build-time optional 2013-02-13 23:08:25 +01:00
Lennart Poettering 9db11a99be efi: efi_get_boot_options() should already sort the entries, the random order in the efivars fs is probably not useful
This also introduces a new FOREACH_DIRENT macro and makes use of it.
2013-02-13 22:02:40 +01:00
Lennart Poettering 61cc634bc2 efi: use efi_get_variable_string() instead of efi_get_variable() where we can 2013-02-13 21:24:10 +01:00
Kay Sievers 4d34c4951a efi: unify BootXXXX reading 2013-02-13 17:35:20 +01:00
Lennart Poettering 726c6b6b3d efi: add missing #include 2013-02-13 00:18:29 +01:00
Lennart Poettering 9cde64ff26 efi: various cleanups 2013-02-13 00:12:58 +01:00
Kay Sievers 7b4d7cc082 bootctl: add boot loader and firmware interface tool 2013-02-11 19:35:52 +01:00
Lennart Poettering ff47c895c8 efi: fix returned length of efi_get_variable() 2013-02-11 06:21:20 +01:00