Compare commits

...

8 Commits

Author SHA1 Message Date
Дамјан Георгиевски c4b843473a bootctl: add @current/@oneshot/@default targets to set-default/set-oneshot
Using `bootctl set-default @current` will set the default loader entry
to the currently booted entry as read from the `LoaderEntrySelected` EFI
variable.

Also `bootctl set-oneshot @current` will set the oneshot loader entry to
the current booted entry.

Correspondingly `@default` and `@oneshot` can be used to read from the
LoaderEntryDefault and LoaderEntryOneshot EFI variables.
2020-10-20 15:02:58 +02:00
Lennart Poettering 558e5654a5
Merge pull request #17401 from mrc0mmand/sempahore-fixups
semaphore: try to use different keyservers
2020-10-20 15:01:11 +02:00
Lennart Poettering 08d3365677 update TODO 2020-10-20 14:46:55 +02:00
Frantisek Sumsal 9ac47d9261 semaphore: temporarily explicitly use the US image mirror
The UK one contains an incorrectly signed index file, causing the CI to
fail.
2020-10-20 12:39:25 +02:00
Frantisek Sumsal 493c965657 semaphore: try to use different keyservers
Recently the Semaphore CI started to fail pretty much constantly due to
GPG key verification fails. After a quick search this is a pretty common
issue with the Ubuntu keyserver in the last month. To make this,
hopefully, a bit more stable, let's use a few different keyservers in
case some of them fail.
2020-10-20 11:36:40 +02:00
Yu Watanabe fc9e3b8129 udevadm: also support alias .device units to specify devices
Previously, .device units generated by SYSTEMD_ALIAS= udev properties
are not supported to specify devices for e.g. 'udevadm info'.

Before:
```
$ udevadm info sys-subsystem-net-devices-enp0s31f6.device
Unknown device "sys-subsystem-net-devices-enp0s31f6.device": No such device
```

After:
```
$ ./udevadm info sys-subsystem-net-devices-enp0s31f6.device
P: /devices/pci0000:00/0000:00:1f.6/net/enp0s31f6
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:1f.6/net/enp0s31f6
E: INTERFACE=enp0s31f6
E: IFINDEX=2
E: SUBSYSTEM=net
E: USEC_INITIALIZED=25317523
E: ID_NET_NAMING_SCHEME=v245
(snip)
```
2020-10-20 10:09:01 +02:00
Kai-Chuan Hsieh a5fe8447bf Add ACCEL_LOCATION property for Dell clamshell models 2020-10-20 09:13:55 +02:00
Lennart Poettering 67bd5620f6 util: make size macros unsigned
By making them unsigned comparing them with other sizes is less likely
to trigger compiler warnings regarding signed/unsigned comparisons.
After all sizes (i.e. size_t) are generally assumed to be unsigned, so
these should be too.

Prompted-by: https://github.com/systemd/systemd/pull/17345#issuecomment-709402332
2020-10-20 15:51:48 +09:00
10 changed files with 135 additions and 42 deletions

4
TODO
View File

@ -20,9 +20,9 @@ Janitorial Clean-ups:
Features:
* port selinux code from mallinfo() to mallinfo2() once added to glibc
* systemd-analyze netif that explains predictable interface (or networkctl)
* in fd_get_path() if we see (deleted) then do stat and check for st_nlink
* port selinux code from mallinfo() to mallinfo2() once added to glibc
* Add service setting to run a service within the specified VRF. i.e. do the
equivalent of "ip vrf exec".

View File

@ -276,6 +276,12 @@ sensor:modalias:acpi:*KIOX000A*:dmi:*svn*CytrixTechnology:*pn*Complex11t:*
sensor:modalias:platform:HID-SENSOR-200073:dmi:*svnDell*:pnVostro5581:*
ACCEL_LOCATION=base
sensor:modalias:platform:HID-SENSOR-200073:dmi:*svnDell*:pnLatitude9520:*:ct10:*
ACCEL_LOCATION=base
sensor:modalias:platform:HID-SENSOR-200073:dmi:*svnDell*:pnLatitude7420:*
ACCEL_LOCATION=base
# Dell Venue 8 Pro 3845
sensor:modalias:acpi:INVN6500*:dmi:*svnDellInc.*:pnVenue8Pro3845:*
ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1

View File

@ -102,6 +102,17 @@
<listitem><para>Sets the default boot loader entry. Takes a single boot loader entry ID string as
argument. The <option>set-oneshot</option> command will set the default entry only for the next boot,
the <option>set-default</option> will set it persistently for all future boots.</para></listitem>
<listitem><para>Optionally, the boot loader entry ID may be specified as one of: <option>@default</option>,
<option>@oneshot</option> or <option>@current</option>, which correspond to the current default boot loader
entry for all future boots, the current default boot loader entry for the next boot, and the currently booted
boot loader entry. These special IDs are resolved to the current values of the EFI variables
<varname>LoaderEntryDefault</varname>, <varname>LoaderEntryOneShot</varname> and <varname>LoaderEntrySelected</varname>,
see <ulink url="https://systemd.io/BOOT_LOADER_SPECIFICATION">Boot Loader Specification</ulink> for details.
These special IDs are primarily useful as a quick way to persistently make the currently booted boot loader
entry the default choice, or to upgrade the default boot loader entry for the next boot to the default boot
loader entry for all future boots, but may be used for other operations too.
</para></listitem>
</varlistentry>
</variablelist>

View File

@ -16,11 +16,13 @@ PHASES=(${@:-SETUP RUN})
UBUNTU_RELEASE="$(lsb_release -cs)"
create_container() {
# create autopkgtest LXC image; this sometimes fails with "Unable to fetch
# GPG key from keyserver", so retry a few times
for retry in {1..5}; do
sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH --keyserver hkp://keyserver.ubuntu.com:80 && break
sleep $((retry*retry))
# Create autopkgtest LXC image; this sometimes fails with "Unable to fetch
# GPG key from keyserver", so retry a few times with different keyservers.
for keyserver in "" "keys.gnupg.net" "keys.openpgp.org" "keyserver.ubuntu.com"; do
for retry in {1..5}; do
sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH --server us.images.linuxcontainers.org ${keyserver:+--keyserver "$keyserver"} && break 2
sleep $((retry*retry))
done
done
# unconfine the container, otherwise some tests fail

View File

@ -72,11 +72,14 @@ typedef enum {
FORMAT_BYTES_TRAILING_B = 1 << 2,
} FormatBytesFlag;
#define FORMAT_BYTES_MAX 16
#define FORMAT_BYTES_MAX 16U
char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag);
static inline char *format_bytes(char *buf, size_t l, uint64_t t) {
return format_bytes_full(buf, l, t, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | FORMAT_BYTES_TRAILING_B);
}
static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) {
if (t == CGROUP_LIMIT_MAX) {
(void) snprintf(buf, l, "%s", "infinity");

View File

@ -63,10 +63,10 @@ typedef enum TimestampStyle {
/* We assume a maximum timezone length of 6. TZNAME_MAX is not defined on Linux, but glibc internally initializes this
* to 6. Let's rely on that. */
#define FORMAT_TIMESTAMP_MAX (3+1+10+1+8+1+6+1+6+1)
#define FORMAT_TIMESTAMP_WIDTH 28 /* when outputting, assume this width */
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
#define FORMAT_TIMESPAN_MAX 64
#define FORMAT_TIMESTAMP_MAX (3U+1U+10U+1U+8U+1U+6U+1U+6U+1U)
#define FORMAT_TIMESTAMP_WIDTH 28U /* when outputting, assume this width */
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256U
#define FORMAT_TIMESPAN_MAX 64U
#define TIME_T_MAX (time_t)((UINTMAX_C(1) << ((sizeof(time_t) << 3) - 1)) - 1)

View File

@ -1661,6 +1661,31 @@ static int verb_is_installed(int argc, char *argv[], void *userdata) {
return EXIT_SUCCESS;
}
static int parse_loader_entry_target_arg(const char *arg1, char16_t **ret_target, size_t *ret_target_size) {
int r;
if (streq(arg1, "@current")) {
r = efi_get_variable(EFI_VENDOR_LOADER, "LoaderEntrySelected", NULL, (void *) ret_target, ret_target_size);
if (r < 0)
return log_error_errno(r, "Failed to get EFI variable 'LoaderEntrySelected': %m");
} else if (streq(arg1, "@oneshot")) {
r = efi_get_variable(EFI_VENDOR_LOADER, "LoaderEntryOneShot", NULL, (void *) ret_target, ret_target_size);
if (r < 0)
return log_error_errno(r, "Failed to get EFI variable 'LoaderEntryOneShot': %m");
} else if (streq(arg1, "@default")) {
r = efi_get_variable(EFI_VENDOR_LOADER, "LoaderEntryDefault", NULL, (void *) ret_target, ret_target_size);
if (r < 0)
return log_error_errno(r, "Failed to get EFI variable 'LoaderEntryDefault': %m");
} else {
char16_t *encoded = NULL;
encoded = utf8_to_utf16(arg1, strlen(arg1));
if (!encoded)
return log_oom();
*ret_target = encoded;
*ret_target_size = char16_strlen(encoded) * 2 + 2;
}
return 0;
}
static int verb_set_default(int argc, char *argv[], void *userdata) {
const char *name;
int r;
@ -1693,17 +1718,17 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
if (isempty(argv[1])) {
r = efi_set_variable(EFI_VENDOR_LOADER, name, NULL, 0);
if (r < 0 && r != -ENOENT)
return log_error_errno(r, "Failed to remove EFI variale: %m");
return log_error_errno(r, "Failed to remove EFI variable '%s': %m", name);
} else {
_cleanup_free_ char16_t *encoded = NULL;
_cleanup_free_ char16_t *target = NULL;
size_t target_size = 0;
encoded = utf8_to_utf16(argv[1], strlen(argv[1]));
if (!encoded)
return log_oom();
r = efi_set_variable(EFI_VENDOR_LOADER, name, encoded, char16_strlen(encoded) * 2 + 2);
r = parse_loader_entry_target_arg(argv[1], &target, &target_size);
if (r < 0)
return log_error_errno(r, "Failed to update EFI variable: %m");
return r;
r = efi_set_variable(EFI_VENDOR_LOADER, name, target, target_size);
if (r < 0)
return log_error_errno(r, "Failed to update EFI variable '%s': %m", name);
}
return 0;

View File

@ -586,7 +586,7 @@ static void display(Hashmap *a) {
Group **array;
signed path_columns;
unsigned rows, n = 0, j, maxtcpu = 0, maxtpath = 3; /* 3 for ellipsize() to work properly */
char buffer[MAX3(21, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
char buffer[MAX3(21U, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
assert(a);

View File

@ -347,7 +347,7 @@ static int output_timestamp_monotonic(FILE *f, sd_journal *j, const char *monoto
}
static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, OutputFlags flags, const char *realtime) {
char buf[MAX(FORMAT_TIMESTAMP_MAX, 64)];
char buf[MAX(FORMAT_TIMESTAMP_MAX, 64U)];
struct tm *(*gettime_r)(const time_t *, struct tm *);
struct tm tm;
uint64_t x;

View File

@ -3,11 +3,73 @@
#include <errno.h>
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "device-private.h"
#include "path-util.h"
#include "udevadm-util.h"
#include "unit-name.h"
static int find_device_from_path(const char *path, sd_device **ret) {
if (path_startswith(path, "/sys/"))
return sd_device_new_from_syspath(ret, path);
if (path_startswith(path, "/dev/")) {
struct stat st;
if (stat(path, &st) < 0)
return -errno;
return device_new_from_stat_rdev(ret, &st);
}
return -EINVAL;
}
static int find_device_from_unit(const char *unit_name, sd_device **ret) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_free_ char *unit_path = NULL, *syspath = NULL;
int r;
if (!unit_name_is_valid(unit_name, UNIT_NAME_PLAIN))
return -EINVAL;
if (unit_name_to_type(unit_name) != UNIT_DEVICE)
return -EINVAL;
r = bus_connect_system_systemd(&bus);
if (r < 0) {
_cleanup_free_ char *path = NULL;
log_debug_errno(r, "Failed to open connection to systemd, using unit name as syspath: %m");
r = unit_name_to_path(unit_name, &path);
if (r < 0)
return log_debug_errno(r, "Failed to convert \"%s\" to a device path: %m", unit_name);
return find_device_from_path(path, ret);
}
unit_path = unit_dbus_path_from_name(unit_name);
if (!unit_path)
return -ENOMEM;
r = sd_bus_get_property_string(
bus,
"org.freedesktop.systemd1",
unit_path,
"org.freedesktop.systemd1.Device",
"SysFSPath",
&error,
&syspath);
if (r < 0)
return log_debug_errno(r, "Failed to get SysFSPath= dbus property for %s: %s",
unit_name, bus_error_message(&error, r));
return sd_device_new_from_syspath(ret, syspath);
}
int find_device(const char *id, const char *prefix, sd_device **ret) {
_cleanup_free_ char *path = NULL;
int r;
@ -24,26 +86,10 @@ int find_device(const char *id, const char *prefix, sd_device **ret) {
} else {
/* In cases where the argument is generic (no prefix specified),
* check if the argument looks like a device unit name. */
if (unit_name_is_valid(id, UNIT_NAME_PLAIN) &&
unit_name_to_type(id) == UNIT_DEVICE) {
r = unit_name_to_path(id, &path);
if (r < 0)
return log_debug_errno(r, "Failed to convert \"%s\" to a device path: %m", id);
id = path;
}
r = find_device_from_unit(id, ret);
if (r >= 0)
return r;
}
if (path_startswith(id, "/sys/"))
return sd_device_new_from_syspath(ret, id);
if (path_startswith(id, "/dev/")) {
struct stat st;
if (stat(id, &st) < 0)
return -errno;
return device_new_from_stat_rdev(ret, &st);
}
return -EINVAL;
return find_device_from_path(id, ret);
}