sensor:modalias:i2c:bmc150_accel:dmi:bvnINSYDECorp.:*:svnInsyde:pnBayTrail:*:rvn105B:rn0E57:*
ACCEL_MOUNT_MATRIX=1, 0, 0; 0, -1, 0; 0, 0, 1
+#########################################
+# Predia
+#########################################
+
+# Predia Basic tablet, most DMI strings are generic, match on BIOS version
+sensor:modalias:acpi:BOSC0200*:dmi:bvnINSYDECorp.:bvrMx.WT107.KUBNGEA*svnInsyde:pnCherryTrail:*
+ ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1
+
#########################################
# Prowise
#########################################
<interfacename>org.freedesktop.hostname1.set-hostname</interfacename>. For
<function>SetStaticHostname()</function> and <function>SetPrettyHostname()</function> it is
<interfacename>org.freedesktop.hostname1.set-static-hostname</interfacename>. For
- <function>SetIconName()</function> and <function>SetChassis()</function> it is
+ <function>SetIconName()</function>, <function>SetChassis()</function>, <function>SetDeployment()</function>
+ and <function>SetLocation()</function> it is
<interfacename>org.freedesktop.hostname1.set-machine-info</interfacename>.</para>
</refsect2>
</refsect1>
<filename>hybrid-sleep.target</filename>,
<filename>suspend-then-hibernate.target</filename>,
<filename>initrd.target</filename>,
- <filename>initrd-cryptsetup.target</filename>,
<filename>initrd-fs.target</filename>,
<filename>initrd-root-device.target</filename>,
<filename>initrd-root-fs.target</filename>,
<varlistentry>
<term><filename>cryptsetup.target</filename></term>
<listitem>
- <para>A target that pulls in setup services for local encrypted block devices.
- See <filename>remote-cryptsetup.target</filename> below for the equivalent target for remote
- volumes, and <filename>initrd-cryptsetup.target</filename> below for the equivalent target in the
- initrd.</para>
+ <para>A target that pulls in setup services for all
+ encrypted block devices.</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry>
<term><filename>initrd.target</filename></term>
<listitem>
- <para>This is the default target in the initrd, similar to <filename>default.target</filename>
+ <para>This is the default target in the initramfs, similar to <filename>default.target</filename>
in the main system. It is used to mount the real root and transition to it. See
<citerefentry><refentrytitle>bootup</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
more discussion.</para>
</listitem>
</varlistentry>
- <varlistentry>
- <term><filename>initrd-cryptsetup.target</filename></term>
- <listitem>
- <para>A target that pulls in setup services for all encrypted block devices. See
- <filename>cryptsetup.target</filename> and <filename>remote-cryptsetup.target</filename> for the
- equivalent targets in the real root.</para>
- </listitem>
- </varlistentry>
<varlistentry>
<term><filename>initrd-fs.target</filename></term>
<listitem>
<para>Similar to <filename>cryptsetup.target</filename>, but for encrypted
devices which are accessed over the network. It is used for
<citerefentry><refentrytitle>crypttab</refentrytitle><manvolnum>8</manvolnum></citerefentry>
- entries marked with <option>_netdev</option>.
- See <filename>cryptsetup.target</filename> for the equivalent target for local volumes, and
- <filename>initrd-cryptsetup.target</filename> for the equivalent target in the initrd.</para>
+ entries marked with <option>_netdev</option>.</para>
</listitem>
</varlistentry>
<varlistentry>
includes = include_directories('src/basic',
'src/boot',
+ 'src/core',
'src/home',
- 'src/shared',
- 'src/systemd',
'src/journal',
'src/journal-remote',
- 'src/nspawn',
- 'src/resolve',
- 'src/timesync',
- 'src/time-wait-sync',
- 'src/login',
- 'src/udev',
- 'src/libudev',
- 'src/core',
- 'src/shutdown',
- 'src/xdg-autostart-generator',
+ 'src/libsystemd-network',
'src/libsystemd/sd-bus',
'src/libsystemd/sd-device',
'src/libsystemd/sd-event',
'src/libsystemd/sd-netlink',
'src/libsystemd/sd-network',
'src/libsystemd/sd-resolve',
- 'src/libsystemd-network',
+ 'src/libudev',
+ 'src/login',
+ 'src/nspawn',
+ 'src/resolve',
+ 'src/shared',
+ 'src/shutdown',
+ 'src/systemd',
+ 'src/time-wait-sync',
+ 'src/timesync',
+ 'src/udev',
+ 'src/xdg-autostart-generator',
'.')
add_project_arguments('-include', 'config.h', language : 'c')
+/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */
//-----------------------------------------------------------------------------
// MurmurHash2 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
+/* SPDX-License-Identifier: LicenseRef-murmurhash2-public-domain */
//-----------------------------------------------------------------------------
// MurmurHash2 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
+/* SPDX-License-Identifier: LGPL-2.1+ */
/* gunicode.c - Unicode manipulation functions
*
* Copyright (C) 1999, 2000 Tom Tromey
-#pragma once
-
+/* SPDX-License-Identifier: LGPL-2.1+ */
/* gunicode.h - Unicode manipulation functions
*
* Copyright (C) 1999, 2000 Tom Tromey
* Copyright © 2000, 2005 Red Hat, Inc.
*/
+#pragma once
#include <stdbool.h>
#include <stdint.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <unistd.h>
#include "memory-util.h"
+/* SPDX-License-Identifier: CC0-1.0 */
+
/*
SipHash reference C implementation
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with
- this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+ this software. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
(Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd)
(Refactored by Tom Gundersen to split up in several functions and follow systemd
+/* SPDX-License-Identifier: CC0-1.0 */
+
#pragma once
#include <inttypes.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include "sort-util.h"
#include "alloc-util.h"
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
#include "alloc-util.h"
+/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */
/* This is copied from util-linux, which in turn copied in the version from Gary S. Brown */
/*
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LicenseRef-crc32-no-restriction */
#pragma once
#include <efi.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <efi.h>
#include <efilib.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
/* Stolen from glibc and converted to UEFI style. In glibc it comes with the following copyright blurb: */
/* Functions to compute SHA256 message digest of files or memory blocks.
}
}
- const char *target;
- if (in_initrd())
- target = "initrd-cryptsetup.target";
- else if (netdev)
- target = "remote-cryptsetup.target";
- else
- target = "cryptsetup.target";
-
if (!nofail)
- fprintf(f, "Before=%s\n", target);
+ fprintf(f,
+ "Before=%s\n",
+ netdev ? "remote-cryptsetup.target" : "cryptsetup.target");
if (password && !keydev) {
r = print_dependencies(f, password);
return log_error_errno(r, "Failed to write unit file %s: %m", n);
if (!noauto) {
- r = generator_add_symlink(arg_dest, target,
+ r = generator_add_symlink(arg_dest,
+ netdev ? "remote-cryptsetup.target" : "cryptsetup.target",
nofail ? "wants" : "requires", n);
if (r < 0)
return r;
/* SPDX-License-Identifier: LGPL-2.1+ */
-#if HAVE_QRENCODE
-#include <qrencode.h>
-#include "qrcode-util.h"
-#endif
-
-#include "dlfcn-util.h"
#include "errno-util.h"
#include "homectl-recovery-key.h"
#include "libcrypt-util.h"
#include "locale-util.h"
#include "memory-util.h"
#include "modhex.h"
+#include "qrcode-util.h"
#include "random-util.h"
#include "strv.h"
#include "terminal-util.h"
return 0;
}
-static int print_qr_code(const char *secret) {
-#if HAVE_QRENCODE
- QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
- void (*sym_QRcode_free)(QRcode *qrcode);
- _cleanup_(dlclosep) void *dl = NULL;
- QRcode* qr;
- int r;
-
- /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
- * codes */
- if (!is_locale_utf8() || !colors_enabled())
- return -EOPNOTSUPP;
-
- dl = dlopen("libqrencode.so.4", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "QRCODE support is not installed: %s", dlerror());
-
- r = dlsym_many_and_warn(
- dl,
- LOG_DEBUG,
- &sym_QRcode_encodeString, "QRcode_encodeString",
- &sym_QRcode_free, "QRcode_free",
- NULL);
- if (r < 0)
- return r;
-
- qr = sym_QRcode_encodeString(secret, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
- if (!qr)
- return -ENOMEM;
-
- fprintf(stderr, "\nYou may optionally scan the recovery key off screen:\n\n");
-
- write_qrcode(stderr, qr);
-
- fputc('\n', stderr);
-
- sym_QRcode_free(qr);
-#endif
- return 0;
-}
-
int identity_add_recovery_key(JsonVariant **v) {
_cleanup_(erase_and_freep) char *password = NULL, *hashed = NULL;
int r;
"whenever authentication is requested.\n", stderr);
fflush(stderr);
- print_qr_code(password);
+ (void) print_qrcode(stderr, "You may optionally scan the recovery key off screen", password);
return 0;
}
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <openssl/pem.h>
#include "fd-util.h"
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
#include <inttypes.h>
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include <errno.h>
-#include <qrencode.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "alloc-util.h"
-#include "dlfcn-util.h"
-#include "fd-util.h"
-#include "fileio.h"
-#include "journal-qrcode.h"
-#include "locale-util.h"
-#include "macro.h"
-#include "qrcode-util.h"
-#include "terminal-util.h"
-
-int print_qr_code(
- FILE *output,
- const char *prefix_text,
- const void *seed,
- size_t seed_size,
- uint64_t start,
- uint64_t interval,
- const char *hn,
- sd_id128_t machine) {
-
- QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
- void (*sym_QRcode_free)(QRcode *qrcode);
- _cleanup_(dlclosep) void *dl = NULL;
- _cleanup_free_ char *url = NULL;
- _cleanup_fclose_ FILE *f = NULL;
- size_t url_size = 0;
- QRcode* qr;
- int r;
-
- assert(seed);
- assert(seed_size > 0);
-
- /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
- * codes */
- if (!is_locale_utf8() || !colors_enabled())
- return -EOPNOTSUPP;
-
- dl = dlopen("libqrencode.so.4", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "QRCODE support is not installed: %s", dlerror());
-
- r = dlsym_many_and_warn(
- dl,
- LOG_DEBUG,
- &sym_QRcode_encodeString, "QRcode_encodeString",
- &sym_QRcode_free, "QRcode_free",
- NULL);
- if (r < 0)
- return r;
-
- f = open_memstream_unlocked(&url, &url_size);
- if (!f)
- return -ENOMEM;
-
- fputs("fss://", f);
-
- for (size_t i = 0; i < seed_size; i++) {
- if (i > 0 && i % 3 == 0)
- fputc('-', f);
- fprintf(f, "%02x", ((uint8_t*) seed)[i]);
- }
-
- fprintf(f, "/%"PRIx64"-%"PRIx64"?machine=" SD_ID128_FORMAT_STR,
- start,
- interval,
- SD_ID128_FORMAT_VAL(machine));
-
- if (hn)
- fprintf(f, ";hostname=%s", hn);
-
- r = fflush_and_check(f);
- if (r < 0)
- return r;
-
- f = safe_fclose(f);
-
- qr = sym_QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
- if (!qr)
- return -ENOMEM;
-
- if (prefix_text)
- fputs(prefix_text, output);
-
- write_qrcode(output, qr);
-
- sym_QRcode_free(qr);
- return 0;
-}
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-#include <inttypes.h>
-#include <stdio.h>
-
-#include "sd-id128.h"
-
-int print_qr_code(FILE *f, const char *prefix_text, const void *seed, size_t seed_size, uint64_t start, uint64_t interval, const char *hn, sd_id128_t machine);
#include "io-util.h"
#include "journal-def.h"
#include "journal-internal.h"
-#include "journal-qrcode.h"
#include "journal-util.h"
#include "journal-vacuum.h"
#include "journal-verify.h"
#include "path-util.h"
#include "pcre2-dlopen.h"
#include "pretty-print.h"
+#include "qrcode-util.h"
#include "random-util.h"
#include "rlimit-util.h"
#include "set.h"
return 0;
}
+#if HAVE_GCRYPT
+static int format_journal_url(
+ const void *seed,
+ size_t seed_size,
+ uint64_t start,
+ uint64_t interval,
+ const char *hn,
+ sd_id128_t machine,
+ bool full,
+ char **ret_url) {
+ _cleanup_free_ char *url = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ size_t url_size = 0;
+ int r;
+
+ assert(seed);
+ assert(seed_size > 0);
+
+ f = open_memstream_unlocked(&url, &url_size);
+ if (!f)
+ return -ENOMEM;
+
+ if (full)
+ fputs("fss://", f);
+
+ for (size_t i = 0; i < seed_size; i++) {
+ if (i > 0 && i % 3 == 0)
+ fputc('-', f);
+ fprintf(f, "%02x", ((uint8_t*) seed)[i]);
+ }
+
+ fprintf(f, "/%"PRIx64"-%"PRIx64, start, interval);
+
+ if (full) {
+ fprintf(f, "?machine=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(machine));
+ if (hn)
+ fprintf(f, ";hostname=%s", hn);
+ }
+
+ r = fflush_and_check(f);
+ if (r < 0)
+ return r;
+
+ f = safe_fclose(f);
+ *ret_url = TAKE_PTR(url);
+ return 0;
+}
+#endif
+
static int setup_keys(void) {
#if HAVE_GCRYPT
size_t mpk_size, seed_size, state_size;
k = mfree(k);
- _cleanup_free_ char *hn = NULL;
+ _cleanup_free_ char *hn = NULL, *key = NULL;
+
+ r = format_journal_url(seed, seed_size, n, arg_interval, hn, machine, false, &key);
+ if (r < 0)
+ return r;
if (on_tty()) {
hn = gethostname_malloc();
fflush(stderr);
}
- for (size_t i = 0; i < seed_size; i++) {
- if (i > 0 && i % 3 == 0)
- putchar('-');
- printf("%02x", ((uint8_t*) seed)[i]);
- }
- printf("/%llx-%llx\n", (unsigned long long) n, (unsigned long long) arg_interval);
+ puts(key);
if (on_tty()) {
fprintf(stderr, "%s", ansi_normal());
#if HAVE_QRENCODE
- (void) print_qr_code(stderr,
- "\nTo transfer the verification key to your phone scan the QR code below:\n",
- seed, seed_size,
- n, arg_interval,
- hn, machine);
+ _cleanup_free_ char *url = NULL;
+ r = format_journal_url(seed, seed_size, n, arg_interval, hn, machine, true, &url);
+ if (r < 0)
+ return r;
+
+ (void) print_qrcode(stderr,
+ "To transfer the verification key to your phone scan the QR code below",
+ url);
#endif
}
+/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */
/* Slightly modified by Lennart Poettering, to avoid name clashes, and
* unexport a few functions. */
+/* SPDX-License-Identifier: LicenseRef-lookup3-public-domain */
#pragma once
#include <inttypes.h>
pcre2-dlopen.h
'''.split())
-if conf.get('HAVE_QRENCODE') == 1
- journalctl_sources += files('journal-qrcode.c',
- 'journal-qrcode.h')
-endif
-
install_data('journald.conf',
install_dir : pkgsysconfdir)
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <errno.h>
#include "dhcp-lease-internal.h"
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include "sd-bus.h"
#include "bus-internal.h"
event_unmask_signal_data(e, d, sig);
}
+static void event_source_pp_prioq_reshuffle(sd_event_source *s) {
+ assert(s);
+
+ /* Reshuffles the pending + prepare prioqs. Called whenever the dispatch order changes, i.e. when
+ * they are enabled/disabled or marked pending and such. */
+
+ if (s->pending)
+ prioq_reshuffle(s->event->pending, s, &s->pending_index);
+
+ if (s->prepare)
+ prioq_reshuffle(s->event->prepare, s, &s->prepare_index);
+}
+
+static void event_source_time_prioq_reshuffle(sd_event_source *s) {
+ struct clock_data *d;
+
+ assert(s);
+ assert(EVENT_SOURCE_IS_TIME(s->type));
+
+ /* Called whenever the event source's timer ordering properties changed, i.e. time, accuracy,
+ * pending, enable state. Makes sure the two prioq's are ordered properly again. */
+ assert_se(d = event_get_clock_data(s->event, s->type));
+ prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
+ prioq_reshuffle(d->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
+}
+
static void source_disconnect(sd_event_source *s) {
sd_event *event;
} else
assert_se(prioq_remove(s->event->pending, s, &s->pending_index));
- if (EVENT_SOURCE_IS_TIME(s->type)) {
- struct clock_data *d;
-
- d = event_get_clock_data(s->event, s->type);
- assert(d);
-
- prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
- }
+ if (EVENT_SOURCE_IS_TIME(s->type))
+ event_source_time_prioq_reshuffle(s);
if (s->type == SOURCE_SIGNAL && !b) {
struct signal_data *d;
} else
s->priority = priority;
- if (s->pending)
- prioq_reshuffle(s->event->pending, s, &s->pending_index);
-
- if (s->prepare)
- prioq_reshuffle(s->event->prepare, s, &s->prepare_index);
+ event_source_pp_prioq_reshuffle(s);
if (s->type == SOURCE_EXIT)
prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
return s->enabled != SD_EVENT_OFF;
}
-_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
+static int event_source_disable(sd_event_source *s) {
int r;
- assert_return(s, -EINVAL);
- assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL);
- assert_return(!event_pid_changed(s->event), -ECHILD);
-
- /* If we are dead anyway, we are fine with turning off
- * sources, but everything else needs to fail. */
- if (s->event->state == SD_EVENT_FINISHED)
- return m == SD_EVENT_OFF ? 0 : -ESTALE;
-
- if (s->enabled == m)
- return 0;
+ assert(s);
+ assert(s->enabled != SD_EVENT_OFF);
- if (m == SD_EVENT_OFF) {
+ /* Unset the pending flag when this event source is disabled */
+ if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) {
+ r = source_set_pending(s, false);
+ if (r < 0)
+ return r;
+ }
- /* Unset the pending flag when this event source is disabled */
- if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) {
- r = source_set_pending(s, false);
- if (r < 0)
- return r;
- }
+ s->enabled = SD_EVENT_OFF;
- switch (s->type) {
+ switch (s->type) {
- case SOURCE_IO:
- source_io_unregister(s);
- s->enabled = m;
- break;
+ case SOURCE_IO:
+ source_io_unregister(s);
+ break;
- case SOURCE_TIME_REALTIME:
- case SOURCE_TIME_BOOTTIME:
- case SOURCE_TIME_MONOTONIC:
- case SOURCE_TIME_REALTIME_ALARM:
- case SOURCE_TIME_BOOTTIME_ALARM: {
- struct clock_data *d;
+ case SOURCE_TIME_REALTIME:
+ case SOURCE_TIME_BOOTTIME:
+ case SOURCE_TIME_MONOTONIC:
+ case SOURCE_TIME_REALTIME_ALARM:
+ case SOURCE_TIME_BOOTTIME_ALARM:
+ event_source_time_prioq_reshuffle(s);
+ break;
- s->enabled = m;
- d = event_get_clock_data(s->event, s->type);
- assert(d);
+ case SOURCE_SIGNAL:
+ event_gc_signal_data(s->event, &s->priority, s->signal.sig);
+ break;
- prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
- break;
- }
+ case SOURCE_CHILD:
+ assert(s->event->n_enabled_child_sources > 0);
+ s->event->n_enabled_child_sources--;
- case SOURCE_SIGNAL:
- s->enabled = m;
+ if (EVENT_SOURCE_WATCH_PIDFD(s))
+ source_child_pidfd_unregister(s);
+ else
+ event_gc_signal_data(s->event, &s->priority, SIGCHLD);
+ break;
- event_gc_signal_data(s->event, &s->priority, s->signal.sig);
- break;
+ case SOURCE_EXIT:
+ prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
+ break;
- case SOURCE_CHILD:
- s->enabled = m;
+ case SOURCE_DEFER:
+ case SOURCE_POST:
+ case SOURCE_INOTIFY:
+ break;
- assert(s->event->n_enabled_child_sources > 0);
- s->event->n_enabled_child_sources--;
+ default:
+ assert_not_reached("Wut? I shouldn't exist.");
+ }
- if (EVENT_SOURCE_WATCH_PIDFD(s))
- source_child_pidfd_unregister(s);
- else
- event_gc_signal_data(s->event, &s->priority, SIGCHLD);
+ return 0;
+}
- break;
+static int event_source_enable(sd_event_source *s, int m) {
+ int r;
- case SOURCE_EXIT:
- s->enabled = m;
- prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
- break;
+ assert(s);
+ assert(IN_SET(m, SD_EVENT_ON, SD_EVENT_ONESHOT));
+ assert(s->enabled == SD_EVENT_OFF);
- case SOURCE_DEFER:
- case SOURCE_POST:
- case SOURCE_INOTIFY:
- s->enabled = m;
- break;
+ /* Unset the pending flag when this event source is enabled */
+ if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) {
+ r = source_set_pending(s, false);
+ if (r < 0)
+ return r;
+ }
- default:
- assert_not_reached("Wut? I shouldn't exist.");
- }
+ s->enabled = m;
- } else {
+ switch (s->type) {
- /* Unset the pending flag when this event source is enabled */
- if (s->enabled == SD_EVENT_OFF && !IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) {
- r = source_set_pending(s, false);
- if (r < 0)
- return r;
+ case SOURCE_IO:
+ r = source_io_register(s, m, s->io.events);
+ if (r < 0) {
+ s->enabled = SD_EVENT_OFF;
+ return r;
}
- switch (s->type) {
-
- case SOURCE_IO:
- r = source_io_register(s, m, s->io.events);
- if (r < 0)
- return r;
+ break;
- s->enabled = m;
- break;
+ case SOURCE_TIME_REALTIME:
+ case SOURCE_TIME_BOOTTIME:
+ case SOURCE_TIME_MONOTONIC:
+ case SOURCE_TIME_REALTIME_ALARM:
+ case SOURCE_TIME_BOOTTIME_ALARM:
+ event_source_time_prioq_reshuffle(s);
+ break;
- case SOURCE_TIME_REALTIME:
- case SOURCE_TIME_BOOTTIME:
- case SOURCE_TIME_MONOTONIC:
- case SOURCE_TIME_REALTIME_ALARM:
- case SOURCE_TIME_BOOTTIME_ALARM: {
- struct clock_data *d;
+ case SOURCE_SIGNAL:
+ r = event_make_signal_data(s->event, s->signal.sig, NULL);
+ if (r < 0) {
+ s->enabled = SD_EVENT_OFF;
+ event_gc_signal_data(s->event, &s->priority, s->signal.sig);
+ return r;
+ }
- s->enabled = m;
- d = event_get_clock_data(s->event, s->type);
- assert(d);
+ break;
- prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
- break;
- }
+ case SOURCE_CHILD:
+ s->event->n_enabled_child_sources++;
- case SOURCE_SIGNAL:
+ if (EVENT_SOURCE_WATCH_PIDFD(s)) {
+ /* yes, we have pidfd */
- s->enabled = m;
+ r = source_child_pidfd_register(s, s->enabled);
+ if (r < 0) {
+ s->enabled = SD_EVENT_OFF;
+ s->event->n_enabled_child_sources--;
+ return r;
+ }
+ } else {
+ /* no pidfd, or something other to watch for than WEXITED */
- r = event_make_signal_data(s->event, s->signal.sig, NULL);
+ r = event_make_signal_data(s->event, SIGCHLD, NULL);
if (r < 0) {
s->enabled = SD_EVENT_OFF;
- event_gc_signal_data(s->event, &s->priority, s->signal.sig);
+ s->event->n_enabled_child_sources--;
+ event_gc_signal_data(s->event, &s->priority, SIGCHLD);
return r;
}
+ }
- break;
+ break;
- case SOURCE_CHILD:
+ case SOURCE_EXIT:
+ prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
+ break;
- if (s->enabled == SD_EVENT_OFF)
- s->event->n_enabled_child_sources++;
+ case SOURCE_DEFER:
+ case SOURCE_POST:
+ case SOURCE_INOTIFY:
+ break;
- s->enabled = m;
+ default:
+ assert_not_reached("Wut? I shouldn't exist.");
+ }
- if (EVENT_SOURCE_WATCH_PIDFD(s)) {
- /* yes, we have pidfd */
+ return 0;
+}
- r = source_child_pidfd_register(s, s->enabled);
- if (r < 0) {
- s->enabled = SD_EVENT_OFF;
- s->event->n_enabled_child_sources--;
- return r;
- }
- } else {
- /* no pidfd, or something other to watch for than WEXITED */
+_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
+ int r;
- r = event_make_signal_data(s->event, SIGCHLD, NULL);
- if (r < 0) {
- s->enabled = SD_EVENT_OFF;
- s->event->n_enabled_child_sources--;
- event_gc_signal_data(s->event, &s->priority, SIGCHLD);
- return r;
- }
- }
+ assert_return(s, -EINVAL);
+ assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL);
+ assert_return(!event_pid_changed(s->event), -ECHILD);
- break;
+ /* If we are dead anyway, we are fine with turning off sources, but everything else needs to fail. */
+ if (s->event->state == SD_EVENT_FINISHED)
+ return m == SD_EVENT_OFF ? 0 : -ESTALE;
- case SOURCE_EXIT:
- s->enabled = m;
- prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
- break;
+ if (s->enabled == m) /* No change? */
+ return 0;
- case SOURCE_DEFER:
- case SOURCE_POST:
- case SOURCE_INOTIFY:
+ if (m == SD_EVENT_OFF)
+ r = event_source_disable(s);
+ else {
+ if (s->enabled != SD_EVENT_OFF) {
+ /* Switching from "on" to "oneshot" or back? If that's the case, we can take a shortcut, the
+ * event source is already enabled after all. */
s->enabled = m;
- break;
-
- default:
- assert_not_reached("Wut? I shouldn't exist.");
+ return 0;
}
- }
-
- if (s->pending)
- prioq_reshuffle(s->event->pending, s, &s->pending_index);
- if (s->prepare)
- prioq_reshuffle(s->event->prepare, s, &s->prepare_index);
+ r = event_source_enable(s, m);
+ }
+ if (r < 0)
+ return r;
+ event_source_pp_prioq_reshuffle(s);
return 0;
}
}
_public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) {
- struct clock_data *d;
int r;
assert_return(s, -EINVAL);
s->time.next = usec;
- d = event_get_clock_data(s->event, s->type);
- assert(d);
-
- prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
-
+ event_source_time_prioq_reshuffle(s);
return 0;
}
}
_public_ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec) {
- struct clock_data *d;
int r;
assert_return(s, -EINVAL);
s->time.accuracy = usec;
- d = event_get_clock_data(s->event, s->type);
- assert(d);
-
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
-
+ event_source_time_prioq_reshuffle(s);
return 0;
}
if (r < 0)
return r;
- prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
- prioq_reshuffle(d->latest, s, &s->time.latest_index);
- d->needs_rearm = true;
+ event_source_time_prioq_reshuffle(s);
}
return 0;
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
typedef struct Wireguard Wireguard;
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include "bond.h"
#include "dhcp6-internal.h"
#include "dhcp6-protocol.h"
dns_cache_make_space(c, 1);
- i = new0(DnsCacheItem, 1);
+ i = new(DnsCacheItem, 1);
if (!i)
return -ENOMEM;
- i->type = DNS_CACHE_POSITIVE;
- i->key = dns_resource_key_ref(rr->key);
- i->rr = dns_resource_record_ref(rr);
- i->until = calculate_until(rr, (uint32_t) -1, timestamp, false);
- i->authenticated = authenticated;
- i->shared_owner = shared_owner;
- i->ifindex = ifindex;
- i->owner_family = owner_family;
- i->owner_address = *owner_address;
- i->prioq_idx = PRIOQ_IDX_NULL;
+ *i = (DnsCacheItem) {
+ .type = DNS_CACHE_POSITIVE,
+ .key = dns_resource_key_ref(rr->key),
+ .rr = dns_resource_record_ref(rr),
+ .until = calculate_until(rr, (uint32_t) -1, timestamp, false),
+ .authenticated = authenticated,
+ .shared_owner = shared_owner,
+ .ifindex = ifindex,
+ .owner_family = owner_family,
+ .owner_address = *owner_address,
+ .prioq_idx = PRIOQ_IDX_NULL,
+ };
r = dns_cache_link_item(c, i);
if (r < 0)
dns_cache_make_space(c, 1);
- i = new0(DnsCacheItem, 1);
+ i = new(DnsCacheItem, 1);
if (!i)
return -ENOMEM;
- i->type =
- rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
- rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE;
- i->until =
- i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
- calculate_until(soa, nsec_ttl, timestamp, true);
- i->authenticated = authenticated;
- i->owner_family = owner_family;
- i->owner_address = *owner_address;
- i->prioq_idx = PRIOQ_IDX_NULL;
- i->rcode = rcode;
+ *i = (DnsCacheItem) {
+ .type =
+ rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA :
+ rcode == DNS_RCODE_NXDOMAIN ? DNS_CACHE_NXDOMAIN : DNS_CACHE_RCODE,
+ .until =
+ i->type == DNS_CACHE_RCODE ? timestamp + CACHE_TTL_STRANGE_RCODE_USEC :
+ calculate_until(soa, nsec_ttl, timestamp, true),
+ .authenticated = authenticated,
+ .owner_family = owner_family,
+ .owner_address = *owner_address,
+ .prioq_idx = PRIOQ_IDX_NULL,
+ .rcode = rcode,
+ };
if (i->type == DNS_CACHE_NXDOMAIN) {
/* NXDOMAIN entries should apply equally to all types, so we use ANY as
if (!p)
return -ENOMEM;
- p->size = p->rindex = DNS_PACKET_HEADER_SIZE;
- p->allocated = a;
- p->max_size = max_size;
- p->protocol = protocol;
- p->opt_start = p->opt_size = (size_t) -1;
- p->n_ref = 1;
+ *p = (DnsPacket) {
+ .n_ref = 1,
+ .protocol = protocol,
+ .size = DNS_PACKET_HEADER_SIZE,
+ .rindex = DNS_PACKET_HEADER_SIZE,
+ .allocated = a,
+ .max_size = max_size,
+ .opt_start = (size_t) -1,
+ .opt_size = (size_t) -1,
+ };
*ret = p;
assert(q);
assert(s);
- c = new0(DnsQueryCandidate, 1);
+ c = new(DnsQueryCandidate, 1);
if (!c)
return -ENOMEM;
- c->query = q;
- c->scope = s;
+ *c = (DnsQueryCandidate) {
+ .query = q,
+ .scope = s,
+ };
LIST_PREPEND(candidates_by_query, q->candidates, c);
LIST_PREPEND(candidates_by_scope, s->query_candidates, c);
if (m->n_dns_queries >= QUERIES_MAX)
return -EBUSY;
- q = new0(DnsQuery, 1);
+ q = new(DnsQuery, 1);
if (!q)
return -ENOMEM;
- q->question_utf8 = dns_question_ref(question_utf8);
- q->question_idna = dns_question_ref(question_idna);
- q->ifindex = ifindex;
- q->flags = flags;
- q->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
- q->answer_protocol = _DNS_PROTOCOL_INVALID;
- q->answer_family = AF_UNSPEC;
+ *q = (DnsQuery) {
+ .question_utf8 = dns_question_ref(question_utf8),
+ .question_idna = dns_question_ref(question_idna),
+ .ifindex = ifindex,
+ .flags = flags,
+ .answer_dnssec_result = _DNSSEC_RESULT_INVALID,
+ .answer_protocol = _DNS_PROTOCOL_INVALID,
+ .answer_family = AF_UNSPEC,
+ };
/* First dump UTF8 question */
DNS_QUESTION_FOREACH(key, question_utf8)
assert(name);
- k = new0(DnsResourceKey, 1);
+ k = new(DnsResourceKey, 1);
if (!k)
return NULL;
- k->n_ref = 1;
- k->class = class;
- k->type = type;
- k->_name = name;
+ *k = (DnsResourceKey) {
+ .n_ref = 1,
+ .class = class,
+ .type = type,
+ ._name = name,
+ };
return k;
}
DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key) {
DnsResourceRecord *rr;
- rr = new0(DnsResourceRecord, 1);
+ rr = new(DnsResourceRecord, 1);
if (!rr)
return NULL;
- rr->n_ref = 1;
- rr->key = dns_resource_key_ref(key);
- rr->expiry = USEC_INFINITY;
- rr->n_skip_labels_signer = rr->n_skip_labels_source = (unsigned) -1;
+ *rr = (DnsResourceRecord) {
+ .n_ref = 1,
+ .key = dns_resource_key_ref(key),
+ .expiry = USEC_INFINITY,
+ .n_skip_labels_signer = (unsigned) -1,
+ .n_skip_labels_source = (unsigned) -1,
+ };
return rr;
}
return -E2BIG;
}
- d = new0(DnsSearchDomain, 1);
+ d = new(DnsSearchDomain, 1);
if (!d)
return -ENOMEM;
- d->n_ref = 1;
- d->manager = m;
- d->type = type;
- d->name = TAKE_PTR(normalized);
+ *d = (DnsSearchDomain) {
+ .n_ref = 1,
+ .manager = m,
+ .type = type,
+ .name = TAKE_PTR(normalized),
+ };
switch (type) {
* IP and UDP header sizes */
#define ADVERTISE_DATAGRAM_SIZE_MAX (65536U-14U-20U-8U)
+/* On the extra stubs, use a more conservative choice */
+#define ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX DNS_PACKET_UNICAST_SIZE_LARGE_MAX
+
static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type);
static void dns_stub_listener_extra_hash_func(const DnsStubListenerExtra *a, struct siphash *state) {
bool tc, /* set the Truncated bit? */
bool add_opt, /* add an OPT RR to this packet? */
bool edns0_do, /* set the EDNS0 DNSSEC OK bit? */
- bool ad) { /* set the DNSSEC authenticated data bit? */
+ bool ad, /* set the DNSSEC authenticated data bit? */
+ uint16_t max_udp_size) { /* The maximum UDP datagram size to advertise to clients */
int r;
assert(p);
if (add_opt) {
- r = dns_packet_append_opt(p, ADVERTISE_DATAGRAM_SIZE_MAX, edns0_do, /* include_rfc6975 = */ false, rcode, NULL);
+ r = dns_packet_append_opt(p, max_udp_size, edns0_do, /* include_rfc6975 = */ false, rcode, NULL);
if (r == -EMSGSIZE) /* Hit the size limit? then indicate truncation */
tc = true;
else if (r < 0)
if (r < 0)
return log_debug_errno(r, "Failed to make failure packet: %m");
- r = dns_stub_finish_reply_packet(reply, DNS_PACKET_ID(p), rcode, false, !!p->opt, DNS_PACKET_DO(p), authenticated);
+ r = dns_stub_finish_reply_packet(
+ reply,
+ DNS_PACKET_ID(p),
+ rcode,
+ /* truncated = */ false,
+ !!p->opt,
+ DNS_PACKET_DO(p),
+ authenticated,
+ l ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX);
if (r < 0)
return log_debug_errno(r, "Failed to build failure packet: %m");
truncated,
!!q->request_dns_packet->opt,
DNS_PACKET_DO(q->request_dns_packet),
- dns_query_fully_authenticated(q));
+ dns_query_fully_authenticated(q),
+ q->stub_listener_extra ? ADVERTISE_EXTRA_DATAGRAM_SIZE_MAX : ADVERTISE_DATAGRAM_SIZE_MAX);
if (r < 0) {
log_debug_errno(r, "Failed to finish reply packet: %m");
break;
if (r < 0)
return r;
- t = new0(DnsTransaction, 1);
+ t = new(DnsTransaction, 1);
if (!t)
return -ENOMEM;
- t->dns_udp_fd = -1;
- t->answer_source = _DNS_TRANSACTION_SOURCE_INVALID;
- t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
- t->answer_nsec_ttl = (uint32_t) -1;
- t->key = dns_resource_key_ref(key);
- t->current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
- t->clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
-
- t->id = pick_new_id(s->manager);
+ *t = (DnsTransaction) {
+ .dns_udp_fd = -1,
+ .answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
+ .answer_dnssec_result = _DNSSEC_RESULT_INVALID,
+ .answer_nsec_ttl = (uint32_t) -1,
+ .key = dns_resource_key_ref(key),
+ .current_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
+ .clamp_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID,
+ .id = pick_new_id(s->manager),
+ };
r = hashmap_put(s->manager->dns_transactions, UINT_TO_PTR(t->id), t);
if (r < 0) {
if (r > 0) /* Transaction got restarted... */
return;
- if (IN_SET(t->scope->protocol, DNS_PROTOCOL_DNS, DNS_PROTOCOL_LLMNR, DNS_PROTOCOL_MDNS)) {
-
- /* When dealing with protocols other than mDNS only consider responses with
- * equivalent query section to the request. For mDNS this check doesn't make
- * sense, because the section 6 of RFC6762 states that "Multicast DNS responses MUST NOT
- * contain any questions in the Question Section". */
- if (t->scope->protocol != DNS_PROTOCOL_MDNS) {
- r = dns_packet_is_reply_for(p, t->key);
- if (r < 0)
- goto fail;
- if (r == 0) {
- dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY);
- return;
- }
+ /* When dealing with protocols other than mDNS only consider responses with equivalent query section
+ * to the request. For mDNS this check doesn't make sense, because the section 6 of RFC6762 states
+ * that "Multicast DNS responses MUST NOT contain any questions in the Question Section". */
+ if (t->scope->protocol != DNS_PROTOCOL_MDNS) {
+ r = dns_packet_is_reply_for(p, t->key);
+ if (r < 0)
+ goto fail;
+ if (r == 0) {
+ dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY);
+ return;
}
+ }
- /* Install the answer as answer to the transaction */
- dns_answer_unref(t->answer);
- t->answer = dns_answer_ref(p->answer);
- t->answer_rcode = DNS_PACKET_RCODE(p);
- t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
- t->answer_authenticated = false;
+ /* Install the answer as answer to the transaction */
+ dns_answer_unref(t->answer);
+ t->answer = dns_answer_ref(p->answer);
+ t->answer_rcode = DNS_PACKET_RCODE(p);
+ t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
+ t->answer_authenticated = false;
- r = dns_transaction_fix_rcode(t);
- if (r < 0)
- goto fail;
+ r = dns_transaction_fix_rcode(t);
+ if (r < 0)
+ goto fail;
- /* Block GC while starting requests for additional DNSSEC RRs */
- t->block_gc++;
- r = dns_transaction_request_dnssec_keys(t);
- t->block_gc--;
+ /* Block GC while starting requests for additional DNSSEC RRs */
+ t->block_gc++;
+ r = dns_transaction_request_dnssec_keys(t);
+ t->block_gc--;
- /* Maybe the transaction is ready for GC'ing now? If so, free it and return. */
- if (!dns_transaction_gc(t))
- return;
+ /* Maybe the transaction is ready for GC'ing now? If so, free it and return. */
+ if (!dns_transaction_gc(t))
+ return;
- /* Requesting additional keys might have resulted in
- * this transaction to fail, since the auxiliary
- * request failed for some reason. If so, we are not
- * in pending state anymore, and we should exit
- * quickly. */
- if (t->state != DNS_TRANSACTION_PENDING)
- return;
- if (r < 0)
- goto fail;
- if (r > 0) {
- /* There are DNSSEC transactions pending now. Update the state accordingly. */
- t->state = DNS_TRANSACTION_VALIDATING;
- dns_transaction_close_connection(t);
- dns_transaction_stop_timeout(t);
- return;
- }
+ /* Requesting additional keys might have resulted in this transaction to fail, since the auxiliary
+ * request failed for some reason. If so, we are not in pending state anymore, and we should exit
+ * quickly. */
+ if (t->state != DNS_TRANSACTION_PENDING)
+ return;
+ if (r < 0)
+ goto fail;
+ if (r > 0) {
+ /* There are DNSSEC transactions pending now. Update the state accordingly. */
+ t->state = DNS_TRANSACTION_VALIDATING;
+ dns_transaction_close_connection(t);
+ dns_transaction_stop_timeout(t);
+ return;
}
dns_transaction_process_dnssec(t);
if (r < 0)
return r;
- i = new0(DnsZoneItem, 1);
+ i = new(DnsZoneItem, 1);
if (!i)
return -ENOMEM;
- i->scope = s;
- i->rr = dns_resource_record_ref(rr);
- i->probing_enabled = probe;
+ *i = (DnsZoneItem) {
+ .scope = s,
+ .rr = dns_resource_record_ref(rr),
+ .probing_enabled = probe,
+ };
r = dns_zone_link_item(z, i);
if (r < 0)
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
#include "sd-bus.h"
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
#include "list.h"
if (r < 0)
return log_oom();
- item = new0(EtcHostsItem, 1);
+ item = new(EtcHostsItem, 1);
if (!item)
return log_oom();
- item->address = address;
+ *item = (EtcHostsItem) {
+ .address = address,
+ };
r = hashmap_put(hosts->by_address, &item->address, item);
if (r < 0) {
assert(l);
assert(in_addr);
- a = new0(LinkAddress, 1);
+ a = new(LinkAddress, 1);
if (!a)
return -ENOMEM;
- a->family = family;
- a->in_addr = *in_addr;
+ *a = (LinkAddress) {
+ .family = family,
+ .in_addr = *in_addr,
+ .link = l,
+ };
- a->link = l;
LIST_PREPEND(addresses, l->addresses, a);
l->n_addresses++;
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <fcntl.h>
#include <linux/dm-ioctl.h>
#include <sys/ioctl.h>
+/* SPDX-License-Identifier: LGPL-2+ */
/*
* initreq.h Interface to talk to init through /dev/initctl.
*
+/* SPDX-License-Identifier: MIT */
+
#ifndef __LINUX_NL80211_H
#define __LINUX_NL80211_H
/*
ptyfwd.h
pwquality-util.c
pwquality-util.h
+ qrcode-util.c
+ qrcode-util.h
reboot-util.c
reboot-util.h
resize-fs.c
'''.split())
endif
-if conf.get('HAVE_QRENCODE') == 1
- shared_sources += files('''
- qrcode-util.c
- qrcode-util.h
-'''.split())
-endif
-
generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh')
ip_protocol_list_txt = custom_target(
'ip-protocol-list.txt',
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include <security/pam_ext.h>
#include <syslog.h>
#include <stdlib.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#pragma once
#include <inttypes.h>
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include "qrcode-util.h"
+
+#if HAVE_QRENCODE
+#include <qrencode.h>
+
+#include "dlfcn-util.h"
+#include "locale-util.h"
#include "terminal-util.h"
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
static void print_border(FILE *output, unsigned width) {
- unsigned x, y;
-
/* Four rows of border */
- for (y = 0; y < 4; y += 2) {
+ for (unsigned y = 0; y < 4; y += 2) {
fputs(ANSI_WHITE_ON_BLACK, output);
- for (x = 0; x < 4 + width + 4; x++)
+ for (unsigned x = 0; x < 4 + width + 4; x++)
fputs("\342\226\210", output);
fputs(ANSI_NORMAL "\n", output);
}
}
-void write_qrcode(FILE *output, QRcode *qr) {
- unsigned x, y;
-
+static void write_qrcode(FILE *output, QRcode *qr) {
assert(qr);
if (!output)
print_border(output, qr->width);
- for (y = 0; y < (unsigned) qr->width; y += 2) {
- const uint8_t *row1, *row2;
-
- row1 = qr->data + qr->width * y;
- row2 = row1 + qr->width;
+ for (unsigned y = 0; y < (unsigned) qr->width; y += 2) {
+ const uint8_t *row1 = qr->data + qr->width * y;
+ const uint8_t *row2 = row1 + qr->width;
fputs(ANSI_WHITE_ON_BLACK, output);
- for (x = 0; x < 4; x++)
+ for (unsigned x = 0; x < 4; x++)
fputs("\342\226\210", output);
- for (x = 0; x < (unsigned) qr->width; x ++) {
+ for (unsigned x = 0; x < (unsigned) qr->width; x++) {
bool a, b;
a = row1[x] & 1;
fputs("\342\226\210", output);
}
- for (x = 0; x < 4; x++)
+ for (unsigned x = 0; x < 4; x++)
fputs("\342\226\210", output);
fputs(ANSI_NORMAL "\n", output);
}
print_border(output, qr->width);
fflush(output);
}
+
+int print_qrcode(FILE *out, const char *header, const char *string) {
+ QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
+ void (*sym_QRcode_free)(QRcode *qrcode);
+ _cleanup_(dlclosep) void *dl = NULL;
+ QRcode* qr;
+ int r;
+
+ /* If this is not an UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
+ * codes */
+ if (!is_locale_utf8() || !colors_enabled())
+ return -EOPNOTSUPP;
+
+ dl = dlopen("libqrencode.so.4", RTLD_LAZY);
+ if (!dl)
+ return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+ "QRCODE support is not installed: %s", dlerror());
+
+ r = dlsym_many_and_warn(
+ dl,
+ LOG_DEBUG,
+ &sym_QRcode_encodeString, "QRcode_encodeString",
+ &sym_QRcode_free, "QRcode_free",
+ NULL);
+ if (r < 0)
+ return r;
+
+ qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 0);
+ if (!qr)
+ return -ENOMEM;
+
+ if (header)
+ fprintf(out, "\n%s:\n\n", header);
+
+ write_qrcode(out, qr);
+
+ fputc('\n', out);
+
+ sym_QRcode_free(qr);
+ return 0;
+}
+#endif
/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-#if HAVE_QRENCODE
-#include <qrencode.h>
+#pragma once
#include <stdio.h>
+#include <errno.h>
-void write_qrcode(FILE *output, QRcode *qr);
+#if HAVE_QRENCODE
+int print_qrcode(FILE *out, const char *header, const char *string);
+#else
+static inline int print_qrcode(FILE *out, const char *header, const char *string) {
+ return -EOPNOTSUPP;
+}
#endif
[['src/test/test-psi-util.c'],
[],
[]],
+
+ [['src/test/test-qrcode-util.c'],
+ [libshared],
+ [libdl]],
]
############################################################
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "locale-util.h"
+#include "main-func.h"
+#include "qrcode-util.h"
+#include "tests.h"
+
+static int run(int argc, char **argv) {
+ int r;
+
+ test_setup_logging(LOG_DEBUG);
+
+ assert_se(setenv("SYSTEMD_COLORS", "1", 1) == 0); /* Force the qrcode to be printed */
+
+ r = print_qrcode(stdout, "This should say \"TEST\"", "TEST");
+ if (r == -EOPNOTSUPP)
+ return log_tests_skipped("not supported");
+ if (r < 0)
+ return log_error_errno(r, "Failed to print QR code: %m");
+ return 0;
+}
+
+DEFINE_MAIN_FUNCTION(run);
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
#include "sd-hwdb.h"
#include "alloc-util.h"
-/*
- * systemd service to wait until kernel realtime clock is synchronized
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
+/* SPDX-License-Identifier: LGPL-2.1+ */
+/* systemd service to wait until kernel realtime clock is synchronized */
#include <errno.h>
#include <stdbool.h>
+++ /dev/null
-# SPDX-License-Identifier: LGPL-2.1+
-#
-# This file is part of systemd.
-#
-# systemd is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation; either version 2.1 of the License, or
-# (at your option) any later version.
-
-[Unit]
-Description=Initrd Encrypted Volumes
-Documentation=man:systemd.special(7)
-OnFailure=emergency.target
-OnFailureJobMode=replace-irreversibly
-AssertPathExists=/etc/initrd-release
-DefaultDependencies=no
-Conflicts=shutdown.target
'multi-user.target.wants/'],
['getty-pre.target', ''],
['graphical.target', '',
- (with_runlevels ? 'runlevel5.target default.target' : 'default.target')],
+ 'default.target' + (with_runlevels ? ' runlevel5.target' : '')],
['halt.target', ''],
['hibernate.target', 'ENABLE_HIBERNATE'],
['hybrid-sleep.target', 'ENABLE_HIBERNATE'],
['suspend-then-hibernate.target', 'ENABLE_HIBERNATE'],
['initrd-cleanup.service', 'ENABLE_INITRD'],
- ['initrd-cryptsetup.target', 'HAVE_LIBCRYPTSETUP ENABLE_INITRD',
- 'sysinit.target.wants/'],
['initrd-fs.target', 'ENABLE_INITRD'],
['initrd-parse-etc.service', 'ENABLE_INITRD'],
['initrd-root-device.target', 'ENABLE_INITRD'],
'sysinit.target.wants/'],
['proc-sys-fs-binfmt_misc.mount', 'ENABLE_BINFMT'],
['reboot.target', '',
- (with_runlevels ? 'runlevel6.target ctrl-alt-del.target' : 'ctrl-alt-del.target')],
- ['remote-cryptsetup.target', 'HAVE_LIBCRYPTSETUP'],
+ 'ctrl-alt-del.target' + (with_runlevels ? ' runlevel6.target' : '')],
+ ['remote-cryptsetup.target', 'HAVE_LIBCRYPTSETUP',
+ 'initrd-root-device.target.wants/'],
['remote-fs-pre.target', ''],
['remote-fs.target', ''],
['rescue.target', '',