1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

Merge pull request #20490 from poettering/id128-format-compound-literal

compound literal love for sd_id128_to_string()
This commit is contained in:
Lennart Poettering 2021-08-20 13:33:51 +02:00 committed by GitHub
commit fbe3d9591f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 160 additions and 204 deletions

View File

@ -61,7 +61,7 @@ manpages = [
['org.freedesktop.resolve1', '5', [], 'ENABLE_RESOLVE'],
['org.freedesktop.systemd1', '5', [], ''],
['org.freedesktop.timedate1', '5', [], 'ENABLE_TIMEDATED'],
['os-release', '5', ['initrd-release'], ''],
['os-release', '5', ['extension-release', 'initrd-release'], ''],
['pam_systemd', '8', [], 'HAVE_PAM'],
['pam_systemd_home', '8', [], 'ENABLE_PAM_HOME'],
['portablectl', '1', [], 'ENABLE_PORTABLED'],
@ -633,7 +633,10 @@ manpages = [
'sd_id128_get_machine_app_specific'],
''],
['sd_id128_randomize', '3', [], ''],
['sd_id128_to_string', '3', ['sd_id128_from_string'], ''],
['sd_id128_to_string',
'3',
['SD_ID128_STRING_MAX', 'SD_ID128_TO_STRING', 'sd_id128_from_string'],
''],
['sd_is_fifo',
'3',
['sd_is_mq',

View File

@ -90,7 +90,10 @@
<programlisting>#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)</programlisting>
<para><constant>SD_ID128_NULL</constant> may be used to refer to the 128-bit ID consisting of only
<constant>NUL</constant> bytes.</para>
<constant>NUL</constant> bytes (i.e. all bits off).</para>
<para><constant>SD_ID128_ALLF</constant> may be used to refer to the 128-bit ID consisting of only
<constant>0xFF</constant> bytes (i.e. all bits on).</para>
<para><function>SD_ID128_MAKE_STR()</function> is similar to <function>SD_ID128_MAKE()</function>, but creates a
<type>const char*</type> expression that can be conveniently used in message formats and such:</para>

View File

@ -35,12 +35,11 @@
<refsect1>
<title>Description</title>
<para><function>sd_id128_randomize()</function> generates a new
randomized 128-bit ID and returns it in
<parameter>ret</parameter>. Every invocation returns a new
randomly generated ID. This uses the
<filename>/dev/urandom</filename> kernel random number
generator.</para>
<para><function>sd_id128_randomize()</function> generates a new randomized 128-bit ID and returns it in
<parameter>ret</parameter>. Every invocation returns a new randomly generated ID. This uses the
<citerefentry
project='man-pages'><refentrytitle>getrandom</refentrytitle><manvolnum>2</manvolnum></citerefentry>
kernel random number generator.</para>
<para>Note that <function>sd_id128_randomize()</function> always returns a UUID Variant 1 Version 4
compatible ID. It is hence guaranteed that this function will never return the ID consisting of all zero
@ -72,7 +71,8 @@
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry>,
<citerefentry project='man-pages'><refentrytitle>getrandom</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
<citerefentry project='man-pages'><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>

View File

@ -17,7 +17,9 @@
<refnamediv>
<refname>sd_id128_to_string</refname>
<refname>SD_ID128_TO_STRING</refname>
<refname>sd_id128_from_string</refname>
<refname>SD_ID128_STRING_MAX</refname>
<refpurpose>Format or parse 128-bit IDs as strings</refpurpose>
</refnamediv>
@ -25,9 +27,13 @@
<funcsynopsis>
<funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
<funcsynopsisinfo>#define SD_ID128_STRING_MAX 33U</funcsynopsisinfo>
<funcsynopsisinfo>#define SD_ID128_TO_STRING(id) …</funcsynopsisinfo>
<funcprototype>
<funcdef>char *<function>sd_id128_to_string</function></funcdef>
<paramdef>sd_id128_t <parameter>id</parameter>, char <parameter>s</parameter>[33]</paramdef>
<paramdef>sd_id128_t <parameter>id</parameter>, char <parameter>s</parameter>[static SD_ID128_STRING_MAX]</paramdef>
</funcprototype>
<funcprototype>
@ -41,47 +47,48 @@
<refsect1>
<title>Description</title>
<para><function>sd_id128_to_string()</function> formats a 128-bit
ID as a character string. It expects the ID and a string array
capable of storing 33 characters. The ID will be formatted as 32
lowercase hexadecimal digits and be terminated by a
<constant>NUL</constant> byte.</para>
<para><function>sd_id128_to_string()</function> formats a 128-bit ID as a character string. It expects
the ID and a string array capable of storing 33 characters
(<constant>SD_ID128_STRING_MAX</constant>). The ID will be formatted as 32 lowercase hexadecimal digits
and be terminated by a <constant>NUL</constant> byte.</para>
<para><function>sd_id128_from_string()</function> implements the reverse operation: it takes a 33 character string
with 32 hexadecimal digits (either lowercase or uppercase, terminated by <constant>NUL</constant>) and parses them
back into a 128-bit ID returned in <parameter>ret</parameter>. Alternatively, this call can also parse a
37-character string with a 128-bit ID formatted as RFC UUID. If <parameter>ret</parameter> is passed as
<constant>NULL</constant> the function will validate the passed ID string, but not actually return it in parsed
form.</para>
<para><function>SD_ID128_TO_STRING()</function> is a macro that wraps
<function>sd_id128_to_string()</function> and passes an appropriately sized buffer as second argument,
allocated as C99 compound literal. Each use will thus implicitly acquire a suitable buffer on the stack
which remains valid until the end of the current code block. This is usually the simplest way to acquire
a string representation of a 128-bit ID in a buffer that is valid in the current code block.</para>
<para><function>sd_id128_from_string()</function> implements the reverse operation: it takes a 33
character string with 32 hexadecimal digits (either lowercase or uppercase, terminated by
<constant>NUL</constant>) and parses them back into a 128-bit ID returned in
<parameter>ret</parameter>. Alternatively, this call can also parse a 37-character string with a 128-bit
ID formatted as RFC UUID. If <parameter>ret</parameter> is passed as <constant>NULL</constant> the
function will validate the passed ID string, but not actually return it in parsed form.</para>
<para>Note that when parsing 37 character UUIDs this is done strictly in Big Endian byte order,
i.e. according to <ulink url="https://tools.ietf.org/html/rfc4122">RFC4122</ulink> Variant 1
rules, even if the UUID encodes a different variant. This matches behaviour in various other Linux
userspace tools. It's probably wise to avoid UUIDs of other variant types.</para>
i.e. according to <ulink url="https://tools.ietf.org/html/rfc4122">RFC4122</ulink> Variant 1 rules, even
if the UUID encodes a different variant. This matches behaviour in various other Linux userspace
tools. It's probably wise to avoid UUIDs of other variant types.</para>
<para>For more information about the <literal>sd_id128_t</literal>
type see
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
Note that these calls operate the same way on all architectures,
i.e. the results do not depend on endianness.</para>
<para>For more information about the <literal>sd_id128_t</literal> type see
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Note that
these calls operate the same way on all architectures, i.e. the results do not depend on
endianness.</para>
<para>When formatting a 128-bit ID into a string, it is often
easier to use a format string for
<citerefentry project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
This is easily done using the
<constant>SD_ID128_FORMAT_STR</constant> and <function>SD_ID128_FORMAT_VAL()</function> macros. For
more information see
<para>When formatting a 128-bit ID into a string, it is often easier to use a format string for
<citerefentry
project='man-pages'><refentrytitle>printf</refentrytitle><manvolnum>3</manvolnum></citerefentry>. This
is easily done using the <constant>SD_ID128_FORMAT_STR</constant> and
<function>SD_ID128_FORMAT_VAL()</function> macros. For more information see
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para><function>sd_id128_to_string()</function> always succeeds
and returns a pointer to the string array passed in.
<function>sd_id128_from_string()</function> returns 0 on success, in
which case <parameter>ret</parameter> is filled in, or a negative
errno-style error code.</para>
<para><function>sd_id128_to_string()</function> always succeeds and returns a pointer to the string array
passed in. <function>sd_id128_from_string()</function> returns 0 on success, in which case
<parameter>ret</parameter> is filled in, or a negative errno-style error code.</para>
</refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />

View File

@ -918,7 +918,6 @@ static int remove_subdirs(const char *root, const char *const *subdirs) {
static int remove_machine_id_directory(const char *root) {
sd_id128_t machine_id;
char buf[SD_ID128_STRING_MAX];
int r;
assert(root);
@ -931,7 +930,7 @@ static int remove_machine_id_directory(const char *root) {
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
return rmdir_one(root, sd_id128_to_string(machine_id, buf));
return rmdir_one(root, SD_ID128_TO_STRING(machine_id));
}
static int remove_binaries(const char *esp_path) {
@ -1020,8 +1019,6 @@ static int install_loader_config(const char *esp_path) {
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_close_ int fd = -1;
sd_id128_t machine_id;
char machine_string[SD_ID128_STRING_MAX];
const char *p;
int r;
@ -1041,12 +1038,15 @@ static int install_loader_config(const char *esp_path) {
fprintf(f, "#timeout 3\n"
"#console-mode keep\n");
if (arg_make_machine_id_directory) {
sd_id128_t machine_id;
r = sd_id128_get_machine(&machine_id);
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
fprintf(f, "default %s-*\n", SD_ID128_TO_STRING(machine_id));
}
r = fflush_sync_and_check(f);
@ -1065,7 +1065,6 @@ static int install_loader_config(const char *esp_path) {
static int install_machine_id_directory(const char *root) {
sd_id128_t machine_id;
char buf[SD_ID128_STRING_MAX];
int r;
assert(root);
@ -1078,7 +1077,7 @@ static int install_machine_id_directory(const char *root) {
if (r < 0)
return log_error_errno(r, "Failed to get machine id: %m");
return mkdir_one(root, sd_id128_to_string(machine_id, buf));
return mkdir_one(root, SD_ID128_TO_STRING(machine_id));
}
static int help(int argc, char *argv[], void *userdata) {

View File

@ -339,9 +339,7 @@ static int list_bus_names(int argc, char **argv, void *userdata) {
if (r < 0)
log_debug_errno(r, "Failed to acquire credentials of service %s, ignoring: %m", k);
else {
char m[SD_ID128_STRING_MAX];
r = table_add_cell(table, NULL, TABLE_STRING, sd_id128_to_string(mid, m));
r = table_add_cell(table, NULL, TABLE_ID128, &mid);
if (r < 0)
return table_log_add_error(r);

View File

@ -738,7 +738,6 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
}
static void cgroup_xattr_apply(Unit *u) {
char ids[SD_ID128_STRING_MAX];
int r;
assert(u);
@ -749,7 +748,7 @@ static void cgroup_xattr_apply(Unit *u) {
if (!sd_id128_is_null(u->invocation_id)) {
r = cg_set_xattr(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path,
"trusted.invocation_id",
sd_id128_to_string(u->invocation_id, ids), 32,
SD_ID128_TO_STRING(u->invocation_id), 32,
0);
if (r < 0)
log_unit_debug_errno(u, r, "Failed to set invocation ID on control group %s, ignoring: %m", empty_to_root(u->cgroup_path));

View File

@ -2497,7 +2497,6 @@ static int make_tmp_prefix(const char *prefix) {
static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, char **tmp_path) {
_cleanup_free_ char *x = NULL;
_cleanup_free_ char *y = NULL;
char bid[SD_ID128_STRING_MAX];
sd_id128_t boot_id;
bool rw = true;
int r;
@ -2513,7 +2512,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, ch
if (r < 0)
return r;
x = strjoin(prefix, "/systemd-private-", sd_id128_to_string(boot_id, bid), "-", id, "-XXXXXX");
x = strjoin(prefix, "/systemd-private-", SD_ID128_TO_STRING(boot_id), "-", id, "-XXXXXX");
if (!x)
return -ENOMEM;

View File

@ -566,7 +566,6 @@ static int process_hostname(void) {
static int process_machine_id(void) {
const char *etc_machine_id;
char id[SD_ID128_STRING_MAX];
int r;
etc_machine_id = prefix_roota(arg_root, "/etc/machine-id");
@ -576,7 +575,7 @@ static int process_machine_id(void) {
if (sd_id128_is_null(arg_machine_id))
return 0;
r = write_string_file(etc_machine_id, sd_id128_to_string(arg_machine_id, id),
r = write_string_file(etc_machine_id, SD_ID128_TO_STRING(arg_machine_id),
WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_SYNC | WRITE_STRING_FILE_MKDIR_0755 |
(arg_force ? WRITE_STRING_FILE_ATOMIC : 0));
if (r < 0)

View File

@ -817,14 +817,13 @@ static int apply_identity_changes(JsonVariant **_v) {
if (arg_identity_extra_this_machine || !strv_isempty(arg_identity_filter)) {
_cleanup_(json_variant_unrefp) JsonVariant *per_machine = NULL, *mmid = NULL;
char mids[SD_ID128_STRING_MAX];
sd_id128_t mid;
r = sd_id128_get_machine(&mid);
if (r < 0)
return log_error_errno(r, "Failed to acquire machine ID: %m");
r = json_variant_new_string(&mmid, sd_id128_to_string(mid, mids));
r = json_variant_new_string(&mmid, SD_ID128_TO_STRING(mid));
if (r < 0)
return log_error_errno(r, "Failed to allocate matchMachineId object: %m");

View File

@ -2163,7 +2163,6 @@ int home_augment_status(
uint64_t disk_size = UINT64_MAX, disk_usage = UINT64_MAX, disk_free = UINT64_MAX, disk_ceiling = UINT64_MAX, disk_floor = UINT64_MAX;
_cleanup_(json_variant_unrefp) JsonVariant *j = NULL, *v = NULL, *m = NULL, *status = NULL;
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
char ids[SD_ID128_STRING_MAX];
HomeState state;
sd_id128_t id;
int r;
@ -2227,7 +2226,7 @@ int home_augment_status(
j = json_variant_ref(h->record->json);
v = json_variant_ref(json_variant_by_key(j, "status"));
m = json_variant_ref(json_variant_by_key(v, sd_id128_to_string(id, ids)));
m = json_variant_ref(json_variant_by_key(v, SD_ID128_TO_STRING(id)));
r = json_variant_filter(&m, STRV_MAKE("diskSize", "diskUsage", "diskFree", "diskCeiling", "diskFloor", "signedLocally"));
if (r < 0)
@ -2237,7 +2236,7 @@ int home_augment_status(
if (r < 0)
return r;
r = json_variant_set_field(&v, ids, m);
r = json_variant_set_field(&v, SD_ID128_TO_STRING(id), m);
if (r < 0)
return r;

View File

@ -1487,10 +1487,10 @@ static int luks_format(
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_(erase_and_freep) void *volume_key = NULL;
struct crypt_pbkdf_type good_pbkdf, minimal_pbkdf;
char suuid[ID128_UUID_STRING_MAX], **pp;
_cleanup_free_ char *text = NULL;
size_t volume_key_size;
int slot = 0, r;
char **pp;
assert(node);
assert(dm_name);
@ -1526,19 +1526,20 @@ static int luks_format(
build_good_pbkdf(&good_pbkdf, hr);
build_minimal_pbkdf(&minimal_pbkdf, hr);
r = sym_crypt_format(cd,
CRYPT_LUKS2,
user_record_luks_cipher(hr),
user_record_luks_cipher_mode(hr),
id128_to_uuid_string(uuid, suuid),
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
.label = label,
.subsystem = "systemd-home",
.sector_size = 512U,
.pbkdf = &good_pbkdf,
});
r = sym_crypt_format(
cd,
CRYPT_LUKS2,
user_record_luks_cipher(hr),
user_record_luks_cipher_mode(hr),
ID128_TO_UUID_STRING(uuid),
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
.label = label,
.subsystem = "systemd-home",
.sector_size = 512U,
.pbkdf = &good_pbkdf,
});
if (r < 0)
return log_error_errno(r, "Failed to format LUKS image: %m");
@ -1621,7 +1622,6 @@ static int make_partition_table(
_cleanup_free_ char *path = NULL, *disk_uuid_as_string = NULL;
uint64_t offset, size;
sd_id128_t disk_uuid;
char uuids[ID128_UUID_STRING_MAX];
int r;
assert(fd >= 0);
@ -1676,7 +1676,7 @@ static int make_partition_table(
if (r < 0)
return log_error_errno(r, "Failed to set partition name: %m");
r = fdisk_partition_set_uuid(p, id128_to_uuid_string(uuid, uuids));
r = fdisk_partition_set_uuid(p, ID128_TO_UUID_STRING(uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");

View File

@ -24,7 +24,6 @@ int user_record_synthesize(
gid_t gid) {
_cleanup_free_ char *hd = NULL, *un = NULL, *ip = NULL, *rr = NULL, *user_name_and_realm = NULL;
char smid[SD_ID128_STRING_MAX];
sd_id128_t mid;
int r;
@ -86,7 +85,7 @@ int user_record_synthesize(
JSON_BUILD_PAIR_CONDITION(!!rr, "realm", JSON_BUILD_STRING(realm)),
JSON_BUILD_PAIR("disposition", JSON_BUILD_STRING("regular")),
JSON_BUILD_PAIR("binding", JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(sd_id128_to_string(mid, smid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("imagePath", JSON_BUILD_STRING(image_path)),
JSON_BUILD_PAIR("homeDirectory", JSON_BUILD_STRING(hd)),
JSON_BUILD_PAIR("storage", JSON_BUILD_STRING(user_storage_to_string(storage))),
@ -109,7 +108,6 @@ int user_record_synthesize(
int group_record_synthesize(GroupRecord *g, UserRecord *h) {
_cleanup_free_ char *un = NULL, *rr = NULL, *group_name_and_realm = NULL, *description = NULL;
char smid[SD_ID128_STRING_MAX];
sd_id128_t mid;
int r;
@ -147,11 +145,11 @@ int group_record_synthesize(GroupRecord *g, UserRecord *h) {
JSON_BUILD_PAIR_CONDITION(!!rr, "realm", JSON_BUILD_STRING(rr)),
JSON_BUILD_PAIR("description", JSON_BUILD_STRING(description)),
JSON_BUILD_PAIR("binding", JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(sd_id128_to_string(mid, smid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("gid", JSON_BUILD_UNSIGNED(user_record_gid(h))))))),
JSON_BUILD_PAIR_CONDITION(h->disposition >= 0, "disposition", JSON_BUILD_STRING(user_disposition_to_string(user_record_disposition(h)))),
JSON_BUILD_PAIR("status", JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(sd_id128_to_string(mid, smid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR(SD_ID128_TO_STRING(mid), JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("service", JSON_BUILD_STRING("io.systemd.Home"))))))));
if (r < 0)
return r;
@ -284,7 +282,6 @@ int user_record_add_binding(
gid_t gid) {
_cleanup_(json_variant_unrefp) JsonVariant *new_binding_entry = NULL, *binding = NULL;
char smid[SD_ID128_STRING_MAX], partition_uuids[ID128_UUID_STRING_MAX], luks_uuids[ID128_UUID_STRING_MAX], fs_uuids[ID128_UUID_STRING_MAX];
_cleanup_free_ char *ip = NULL, *hd = NULL, *ip_auto = NULL, *lc = NULL, *lcm = NULL, *fst = NULL;
sd_id128_t mid;
int r;
@ -297,7 +294,6 @@ int user_record_add_binding(
r = sd_id128_get_machine(&mid);
if (r < 0)
return r;
sd_id128_to_string(mid, smid);
if (image_path) {
ip = strdup(image_path);
@ -336,9 +332,9 @@ int user_record_add_binding(
r = json_build(&new_binding_entry,
JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_CONDITION(!!image_path, "imagePath", JSON_BUILD_STRING(image_path)),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", JSON_BUILD_STRING(id128_to_uuid_string(partition_uuid, partition_uuids))),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", JSON_BUILD_STRING(id128_to_uuid_string(luks_uuid, luks_uuids))),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", JSON_BUILD_STRING(id128_to_uuid_string(fs_uuid, fs_uuids))),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(partition_uuid), "partitionUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(partition_uuid))),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(luks_uuid), "luksUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(luks_uuid))),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(fs_uuid), "fileSystemUuid", JSON_BUILD_STRING(ID128_TO_UUID_STRING(fs_uuid))),
JSON_BUILD_PAIR_CONDITION(!!luks_cipher, "luksCipher", JSON_BUILD_STRING(luks_cipher)),
JSON_BUILD_PAIR_CONDITION(!!luks_cipher_mode, "luksCipherMode", JSON_BUILD_STRING(luks_cipher_mode)),
JSON_BUILD_PAIR_CONDITION(luks_volume_key_size != UINT64_MAX, "luksVolumeKeySize", JSON_BUILD_UNSIGNED(luks_volume_key_size)),
@ -355,7 +351,7 @@ int user_record_add_binding(
_cleanup_(json_variant_unrefp) JsonVariant *be = NULL;
/* Merge the new entry with an old one, if that exists */
be = json_variant_ref(json_variant_by_key(binding, smid));
be = json_variant_ref(json_variant_by_key(binding, SD_ID128_TO_STRING(mid)));
if (be) {
r = json_variant_merge(&be, new_binding_entry);
if (r < 0)
@ -366,7 +362,7 @@ int user_record_add_binding(
}
}
r = json_variant_set_field(&binding, smid, new_binding_entry);
r = json_variant_set_field(&binding, SD_ID128_TO_STRING(mid), new_binding_entry);
if (r < 0)
return r;
@ -633,7 +629,6 @@ int user_record_test_recovery_key(UserRecord *h, UserRecord *secret) {
int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
_cleanup_(json_variant_unrefp) JsonVariant *new_per_machine = NULL, *midv = NULL, *midav = NULL, *ne = NULL;
_cleanup_free_ JsonVariant **array = NULL;
char smid[SD_ID128_STRING_MAX];
size_t idx = SIZE_MAX, n;
JsonVariant *per_machine;
sd_id128_t mid;
@ -651,9 +646,7 @@ int user_record_set_disk_size(UserRecord *h, uint64_t disk_size) {
if (r < 0)
return r;
sd_id128_to_string(mid, smid);
r = json_variant_new_string(&midv, smid);
r = json_variant_new_string(&midv, SD_ID128_TO_STRING(mid));
if (r < 0)
return r;
@ -1208,7 +1201,6 @@ int user_record_merge_secret(UserRecord *h, UserRecord *secret) {
int user_record_good_authentication(UserRecord *h) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
char buf[SD_ID128_STRING_MAX];
uint64_t counter, usec;
sd_id128_t mid;
int r;
@ -1235,7 +1227,7 @@ int user_record_good_authentication(UserRecord *h) {
v = json_variant_ref(h->json);
w = json_variant_ref(json_variant_by_key(v, "status"));
z = json_variant_ref(json_variant_by_key(w, sd_id128_to_string(mid, buf)));
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
r = json_variant_set_field_unsigned(&z, "goodAuthenticationCounter", counter);
if (r < 0)
@ -1245,7 +1237,7 @@ int user_record_good_authentication(UserRecord *h) {
if (r < 0)
return r;
r = json_variant_set_field(&w, buf, z);
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
if (r < 0)
return r;
@ -1265,7 +1257,6 @@ int user_record_good_authentication(UserRecord *h) {
int user_record_bad_authentication(UserRecord *h) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
char buf[SD_ID128_STRING_MAX];
uint64_t counter, usec;
sd_id128_t mid;
int r;
@ -1292,7 +1283,7 @@ int user_record_bad_authentication(UserRecord *h) {
v = json_variant_ref(h->json);
w = json_variant_ref(json_variant_by_key(v, "status"));
z = json_variant_ref(json_variant_by_key(w, sd_id128_to_string(mid, buf)));
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
r = json_variant_set_field_unsigned(&z, "badAuthenticationCounter", counter);
if (r < 0)
@ -1302,7 +1293,7 @@ int user_record_bad_authentication(UserRecord *h) {
if (r < 0)
return r;
r = json_variant_set_field(&w, buf, z);
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
if (r < 0)
return r;
@ -1323,7 +1314,6 @@ int user_record_bad_authentication(UserRecord *h) {
int user_record_ratelimit(UserRecord *h) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL, *z = NULL;
usec_t usec, new_ratelimit_begin_usec, new_ratelimit_count;
char buf[SD_ID128_STRING_MAX];
sd_id128_t mid;
int r;
@ -1355,7 +1345,7 @@ int user_record_ratelimit(UserRecord *h) {
v = json_variant_ref(h->json);
w = json_variant_ref(json_variant_by_key(v, "status"));
z = json_variant_ref(json_variant_by_key(w, sd_id128_to_string(mid, buf)));
z = json_variant_ref(json_variant_by_key(w, SD_ID128_TO_STRING(mid)));
r = json_variant_set_field_unsigned(&z, "rateLimitBeginUSec", new_ratelimit_begin_usec);
if (r < 0)
@ -1365,7 +1355,7 @@ int user_record_ratelimit(UserRecord *h) {
if (r < 0)
return r;
r = json_variant_set_field(&w, buf, z);
r = json_variant_set_field(&w, SD_ID128_TO_STRING(mid), z);
if (r < 0)
return r;

View File

@ -103,14 +103,13 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
_fallthrough_;
case ENTRY_BOOT_ID: {
sd_id128_t boot_id;
char sid[SD_ID128_STRING_MAX];
r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id);
if (r < 0)
return log_error_errno(r, "Failed to get monotonic timestamp: %m");
r = snprintf(buf + pos, size - pos,
"_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid));
"_BOOT_ID=%s\n", SD_ID128_TO_STRING(boot_id));
assert(r >= 0);
if ((size_t) r > size - pos)
/* not enough space */

View File

@ -2873,7 +2873,6 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) {
r = sd_bus_message_new_method_return(m, &reply);
else if (streq_ptr(m->member, "GetMachineId")) {
sd_id128_t id;
char sid[SD_ID128_STRING_MAX];
r = sd_id128_get_machine(&id);
if (r < 0)
@ -2883,7 +2882,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) {
if (r < 0)
return r;
r = sd_bus_message_append(reply, "s", sd_id128_to_string(id, sid));
r = sd_bus_message_append(reply, "s", SD_ID128_TO_STRING(id));
} else {
r = sd_bus_message_new_method_errorf(
m, &reply,

View File

@ -2159,7 +2159,6 @@ _public_ int sd_device_trigger_with_uuid(
sd_device_action_t action,
sd_id128_t *ret_uuid) {
char buf[ID128_UUID_STRING_MAX];
const char *s, *j;
sd_id128_t u;
int r;
@ -2178,8 +2177,7 @@ _public_ int sd_device_trigger_with_uuid(
if (r < 0)
return r;
id128_to_uuid_string(u, buf);
j = strjoina(s, " ", buf);
j = strjoina(s, " ", ID128_TO_UUID_STRING(u));
r = sd_device_set_sysattr_value(device, "uevent", j);
if (r < 0)

View File

@ -12,6 +12,8 @@
char *id128_to_uuid_string(sd_id128_t id, char s[static ID128_UUID_STRING_MAX]);
#define ID128_TO_UUID_STRING(id) id128_to_uuid_string((id), (char[ID128_UUID_STRING_MAX]) {})
bool id128_is_valid(const char *s) _pure_;
typedef enum Id128Format {

View File

@ -3273,7 +3273,6 @@ fail:
#define FORMAT_TIMESTAMP_SAFE(t) (FORMAT_TIMESTAMP(t) ?: " --- ")
void journal_file_print_header(JournalFile *f) {
char a[SD_ID128_STRING_MAX], b[SD_ID128_STRING_MAX], c[SD_ID128_STRING_MAX], d[SD_ID128_STRING_MAX];
struct stat st;
assert(f);
@ -3300,10 +3299,10 @@ void journal_file_print_header(JournalFile *f) {
"Objects: %"PRIu64"\n"
"Entry objects: %"PRIu64"\n",
f->path,
sd_id128_to_string(f->header->file_id, a),
sd_id128_to_string(f->header->machine_id, b),
sd_id128_to_string(f->header->boot_id, c),
sd_id128_to_string(f->header->seqnum_id, d),
SD_ID128_TO_STRING(f->header->file_id),
SD_ID128_TO_STRING(f->header->machine_id),
SD_ID128_TO_STRING(f->header->boot_id),
SD_ID128_TO_STRING(f->header->seqnum_id),
f->header->state == STATE_OFFLINE ? "OFFLINE" :
f->header->state == STATE_ONLINE ? "ONLINE" :
f->header->state == STATE_ARCHIVED ? "ARCHIVED" : "UNKNOWN",

View File

@ -920,7 +920,6 @@ _public_ int sd_journal_previous_skip(sd_journal *j, uint64_t skip) {
_public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) {
Object *o;
int r;
char bid[SD_ID128_STRING_MAX], sid[SD_ID128_STRING_MAX];
assert_return(j, -EINVAL);
assert_return(!journal_pid_changed(j), -ECHILD);
@ -933,13 +932,10 @@ _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) {
if (r < 0)
return r;
sd_id128_to_string(j->current_file->header->seqnum_id, sid);
sd_id128_to_string(o->entry.boot_id, bid);
if (asprintf(cursor,
"s=%s;i=%"PRIx64";b=%s;m=%"PRIx64";t=%"PRIx64";x=%"PRIx64,
sid, le64toh(o->entry.seqnum),
bid, le64toh(o->entry.monotonic),
SD_ID128_TO_STRING(j->current_file->header->seqnum_id), le64toh(o->entry.seqnum),
SD_ID128_TO_STRING(o->entry.boot_id), le64toh(o->entry.monotonic),
le64toh(o->entry.realtime),
le64toh(o->entry.xor_hash)) < 0)
return -ENOMEM;

View File

@ -127,7 +127,6 @@ static int run(int argc, char *argv[]) {
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
_cleanup_(decrypted_image_unrefp) DecryptedImage *decrypted_image = NULL;
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
char buf[SD_ID128_STRING_MAX];
sd_id128_t id;
int r;
@ -177,7 +176,7 @@ static int run(int argc, char *argv[]) {
}
if (arg_print)
puts(sd_id128_to_string(id, buf));
puts(SD_ID128_TO_STRING(id));
return 0;
}

View File

@ -281,7 +281,6 @@ static int lldp_send_packet(
}
static int link_send_lldp(Link *link) {
char machine_id_string[SD_ID128_STRING_MAX];
_cleanup_free_ char *hostname = NULL, *pretty_hostname = NULL;
_cleanup_free_ void *packet = NULL;
size_t packet_size = 0;
@ -313,7 +312,7 @@ static int link_send_lldp(Link *link) {
r = lldp_make_packet(link->network->lldp_emit,
&link->hw_addr.ether,
sd_id128_to_string(machine_id, machine_id_string),
SD_ID128_TO_STRING(machine_id),
link->ifname,
(uint16_t) ttl,
link->network ? link->network->description : NULL,

View File

@ -2550,7 +2550,6 @@ static int setup_hostname(void) {
static int setup_journal(const char *directory) {
_cleanup_free_ char *d = NULL;
char id[SD_ID128_STRING_MAX];
const char *dirname, *p, *q;
sd_id128_t this_id;
bool try;
@ -2571,7 +2570,7 @@ static int setup_journal(const char *directory) {
if (sd_id128_equal(arg_uuid, this_id)) {
log_full(try ? LOG_WARNING : LOG_ERR,
"Host and machine ids are equal (%s): refusing to link journals", sd_id128_to_string(arg_uuid, id));
"Host and machine ids are equal (%s): refusing to link journals", SD_ID128_TO_STRING(arg_uuid));
if (try)
return 0;
return -EEXIST;
@ -2587,9 +2586,7 @@ static int setup_journal(const char *directory) {
}
}
(void) sd_id128_to_string(arg_uuid, id);
p = strjoina("/var/log/journal/", id);
p = strjoina("/var/log/journal/", SD_ID128_TO_STRING(arg_uuid));
q = prefix_roota(directory, p);
if (path_is_mount_point(p, NULL, 0) > 0) {
@ -3183,7 +3180,6 @@ static int inner_child(
char **os_release_pairs) {
_cleanup_free_ char *home = NULL;
char as_uuid[ID128_UUID_STRING_MAX];
size_t n_env = 1;
char *envp[] = {
(char*) "PATH=" DEFAULT_PATH_COMPAT,
@ -3432,7 +3428,7 @@ static int inner_child(
assert(!sd_id128_is_null(arg_uuid));
if (asprintf(envp + n_env++, "container_uuid=%s", id128_to_uuid_string(arg_uuid, as_uuid)) < 0)
if (asprintf(envp + n_env++, "container_uuid=%s", ID128_TO_UUID_STRING(arg_uuid)) < 0)
return log_oom();
if (fdset_size(fds) > 0) {

View File

@ -2115,7 +2115,6 @@ static void context_bar_char_process_partition(
static int partition_hint(const Partition *p, const char *node, char **ret) {
_cleanup_free_ char *buf = NULL;
char ids[ID128_UUID_STRING_MAX];
const char *label;
sd_id128_t id;
@ -2144,7 +2143,7 @@ static int partition_hint(const Partition *p, const char *node, char **ret) {
else
id = p->type_uuid;
buf = strdup(id128_to_uuid_string(id, ids));
buf = strdup(ID128_TO_UUID_STRING(id));
done:
if (!buf)
@ -2544,7 +2543,6 @@ static int partition_encrypt(
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_(erase_and_freep) void *volume_key = NULL;
_cleanup_free_ char *dm_name = NULL, *vol = NULL;
char suuid[ID128_UUID_STRING_MAX];
size_t volume_key_size = 256 / 8;
sd_id128_t uuid;
int r;
@ -2591,7 +2589,7 @@ static int partition_encrypt(
CRYPT_LUKS2,
"aes",
"xts-plain64",
id128_to_uuid_string(uuid, suuid),
ID128_TO_UUID_STRING(uuid),
volume_key,
volume_key_size,
&(struct crypt_params_luks2) {
@ -3340,11 +3338,9 @@ static int context_mangle_partitions(Context *context) {
}
if (!sd_id128_equal(p->new_uuid, p->current_uuid)) {
char buf[ID128_UUID_STRING_MAX];
assert(!sd_id128_is_null(p->new_uuid));
r = fdisk_partition_set_uuid(p->current_partition, id128_to_uuid_string(p->new_uuid, buf));
r = fdisk_partition_set_uuid(p->current_partition, ID128_TO_UUID_STRING(p->new_uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");
@ -3371,7 +3367,6 @@ static int context_mangle_partitions(Context *context) {
} else {
_cleanup_(fdisk_unref_partitionp) struct fdisk_partition *q = NULL;
_cleanup_(fdisk_unref_parttypep) struct fdisk_parttype *t = NULL;
char ids[ID128_UUID_STRING_MAX];
assert(!p->new_partition);
assert(p->offset % 512 == 0);
@ -3383,7 +3378,7 @@ static int context_mangle_partitions(Context *context) {
if (!t)
return log_oom();
r = fdisk_parttype_set_typestr(t, id128_to_uuid_string(p->type_uuid, ids));
r = fdisk_parttype_set_typestr(t, ID128_TO_UUID_STRING(p->type_uuid));
if (r < 0)
return log_error_errno(r, "Failed to initialize partition type: %m");
@ -3411,7 +3406,7 @@ static int context_mangle_partitions(Context *context) {
if (r < 0)
return log_error_errno(r, "Failed to set partition number: %m");
r = fdisk_partition_set_uuid(q, id128_to_uuid_string(p->new_uuid, ids));
r = fdisk_partition_set_uuid(q, ID128_TO_UUID_STRING(p->new_uuid));
if (r < 0)
return log_error_errno(r, "Failed to set partition UUID: %m");

View File

@ -2551,15 +2551,11 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
case TABLE_IN6_ADDR:
return json_variant_new_array_bytes(ret, &d->address, FAMILY_ADDRESS_SIZE(AF_INET6));
case TABLE_ID128: {
char buf[SD_ID128_STRING_MAX];
return json_variant_new_string(ret, sd_id128_to_string(d->id128, buf));
}
case TABLE_ID128:
return json_variant_new_string(ret, SD_ID128_TO_STRING(d->id128));
case TABLE_UUID: {
char buf[ID128_UUID_STRING_MAX];
return json_variant_new_string(ret, id128_to_uuid_string(d->id128, buf));
}
case TABLE_UUID:
return json_variant_new_string(ret, ID128_TO_UUID_STRING(d->id128));
case TABLE_UID:
if (!uid_is_valid(d->uid))

View File

@ -59,7 +59,6 @@ static int dispatch_binding(const char *name, JsonVariant *variant, JsonDispatch
{},
};
char smid[SD_ID128_STRING_MAX];
JsonVariant *m;
sd_id128_t mid;
int r;
@ -74,7 +73,7 @@ static int dispatch_binding(const char *name, JsonVariant *variant, JsonDispatch
if (r < 0)
return json_log(variant, flags, r, "Failed to determine machine ID: %m");
m = json_variant_by_key(variant, sd_id128_to_string(mid, smid));
m = json_variant_by_key(variant, SD_ID128_TO_STRING(mid));
if (!m)
return 0;
@ -146,7 +145,6 @@ static int dispatch_status(const char *name, JsonVariant *variant, JsonDispatchF
{},
};
char smid[SD_ID128_STRING_MAX];
JsonVariant *m;
sd_id128_t mid;
int r;
@ -161,7 +159,7 @@ static int dispatch_status(const char *name, JsonVariant *variant, JsonDispatchF
if (r < 0)
return json_log(variant, flags, r, "Failed to determine machine ID: %m");
m = json_variant_by_key(variant, sd_id128_to_string(mid, smid));
m = json_variant_by_key(variant, SD_ID128_TO_STRING(mid));
if (!m)
return 0;

View File

@ -447,9 +447,7 @@ int json_variant_new_hex(JsonVariant **ret, const void *p, size_t n) {
}
int json_variant_new_id128(JsonVariant **ret, sd_id128_t id) {
char s[SD_ID128_STRING_MAX];
return json_variant_new_string(ret, sd_id128_to_string(id, s));
return json_variant_new_string(ret, SD_ID128_TO_STRING(id));
}
static void json_variant_set(JsonVariant *a, JsonVariant *b) {

View File

@ -752,13 +752,12 @@ static int output_export(
const Set *output_fields,
const size_t highlight[2]) {
sd_id128_t boot_id;
char sid[SD_ID128_STRING_MAX];
int r;
usec_t realtime, monotonic;
_cleanup_free_ char *cursor = NULL;
usec_t realtime, monotonic;
sd_id128_t boot_id;
const void *data;
size_t length;
int r;
assert(j);
@ -784,7 +783,7 @@ static int output_export(
cursor,
realtime,
monotonic,
sd_id128_to_string(boot_id, sid));
SD_ID128_TO_STRING(boot_id));
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
size_t fieldlen;

View File

@ -65,31 +65,27 @@ int make_filesystem(
if (r < 0)
return r;
if (r == 0) {
char suuid[ID128_UUID_STRING_MAX];
/* Child */
id128_to_uuid_string(uuid, suuid);
if (streq(fstype, "ext4"))
(void) execlp(mkfs, mkfs,
"-L", label,
"-U", suuid,
"-I", "256",
"-O", "has_journal",
"-m", "0",
"-E", discard ? "lazy_itable_init=1,discard" : "lazy_itable_init=1,nodiscard",
node, NULL);
"-L", label,
"-U", ID128_TO_UUID_STRING(uuid),
"-I", "256",
"-O", "has_journal",
"-m", "0",
"-E", discard ? "lazy_itable_init=1,discard" : "lazy_itable_init=1,nodiscard",
node, NULL);
else if (streq(fstype, "btrfs")) {
if (discard)
(void) execlp(mkfs, mkfs, "-L", label, "-U", suuid, node, NULL);
(void) execlp(mkfs, mkfs, "-L", label, "-U", ID128_TO_UUID_STRING(uuid), node, NULL);
else
(void) execlp(mkfs, mkfs, "-L", label, "-U", suuid, "--nodiscard", node, NULL);
(void) execlp(mkfs, mkfs, "-L", label, "-U", ID128_TO_UUID_STRING(uuid), "--nodiscard", node, NULL);
} else if (streq(fstype, "xfs")) {
const char *j;
j = strjoina("uuid=", suuid);
j = strjoina("uuid=", ID128_TO_UUID_STRING(uuid));
if (discard)
(void) execlp(mkfs, mkfs, "-L", label, "-m", j, "-m", "reflink=1", node, NULL);
else
@ -118,9 +114,9 @@ int make_filesystem(
} else if (streq(fstype, "swap")) {
(void) execlp(mkfs, mkfs,
"-L", label,
"-U", suuid,
node, NULL);
"-L", label,
"-U", ID128_TO_UUID_STRING(uuid),
node, NULL);
} else
/* Generic fallback for all other file systems */

View File

@ -1127,7 +1127,6 @@ static int dispatch_binding(const char *name, JsonVariant *variant, JsonDispatch
{},
};
char smid[SD_ID128_STRING_MAX];
JsonVariant *m;
sd_id128_t mid;
int r;
@ -1142,7 +1141,7 @@ static int dispatch_binding(const char *name, JsonVariant *variant, JsonDispatch
if (r < 0)
return json_log(variant, flags, r, "Failed to determine machine ID: %m");
m = json_variant_by_key(variant, sd_id128_to_string(mid, smid));
m = json_variant_by_key(variant, SD_ID128_TO_STRING(mid));
if (!m)
return 0;
@ -1368,7 +1367,6 @@ static int dispatch_status(const char *name, JsonVariant *variant, JsonDispatchF
{},
};
char smid[SD_ID128_STRING_MAX];
JsonVariant *m;
sd_id128_t mid;
int r;
@ -1383,7 +1381,7 @@ static int dispatch_status(const char *name, JsonVariant *variant, JsonDispatchF
if (r < 0)
return json_log(variant, flags, r, "Failed to determine machine ID: %m");
m = json_variant_by_key(variant, sd_id128_to_string(mid, smid));
m = json_variant_by_key(variant, SD_ID128_TO_STRING(mid));
if (!m)
return 0;

View File

@ -34,11 +34,13 @@ union sd_id128 {
uint64_t qwords[2];
};
#define SD_ID128_STRING_MAX 33
#define SD_ID128_STRING_MAX 33U
char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]);
int sd_id128_from_string(const char *s, sd_id128_t *ret);
#define SD_ID128_TO_STRING(id) sd_id128_to_string((id), (char[SD_ID128_STRING_MAX]) {})
int sd_id128_randomize(sd_id128_t *ret);
int sd_id128_get_machine(sd_id128_t *ret);

View File

@ -237,16 +237,12 @@ static void test_condition_test_ac_power(void) {
static void test_condition_test_host(void) {
_cleanup_free_ char *hostname = NULL;
char sid[SD_ID128_STRING_MAX];
Condition *condition;
sd_id128_t id;
int r;
r = sd_id128_get_machine(&id);
assert_se(r >= 0);
assert_se(sd_id128_to_string(id, sid));
assert_se(sd_id128_get_machine(&id) >= 0);
condition = condition_new(CONDITION_HOST, sid, false, false);
condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, false);
assert_se(condition);
assert_se(condition_test(condition, environ) > 0);
condition_free(condition);
@ -256,7 +252,7 @@ static void test_condition_test_host(void) {
assert_se(condition_test(condition, environ) == 0);
condition_free(condition);
condition = condition_new(CONDITION_HOST, sid, false, true);
condition = condition_new(CONDITION_HOST, SD_ID128_TO_STRING(id), false, true);
assert_se(condition);
assert_se(condition_test(condition, environ) == 0);
condition_free(condition);

View File

@ -200,9 +200,8 @@ static void test_protect_kernel_logs(void) {
}
int main(int argc, char *argv[]) {
sd_id128_t bid;
char boot_id[SD_ID128_STRING_MAX];
_cleanup_free_ char *x = NULL, *y = NULL, *z = NULL, *zz = NULL;
sd_id128_t bid;
test_setup_logging(LOG_INFO);
@ -214,16 +213,15 @@ int main(int argc, char *argv[]) {
}
assert_se(sd_id128_get_boot(&bid) >= 0);
sd_id128_to_string(bid, boot_id);
x = strjoin("/tmp/systemd-private-", boot_id, "-abcd.service-");
y = strjoin("/var/tmp/systemd-private-", boot_id, "-abcd.service-");
x = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
y = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-abcd.service-");
assert_se(x && y);
test_tmpdir("abcd.service", x, y);
z = strjoin("/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
zz = strjoin("/var/tmp/systemd-private-", boot_id, "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
z = strjoin("/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
zz = strjoin("/var/tmp/systemd-private-", SD_ID128_TO_STRING(bid), "-sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device-");
assert_se(z && zz);

View File

@ -37,7 +37,6 @@ typedef struct LookupParameters {
static int add_nss_service(JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *status = NULL, *z = NULL;
char buf[SD_ID128_STRING_MAX];
sd_id128_t mid;
int r;
@ -54,7 +53,7 @@ static int add_nss_service(JsonVariant **v) {
return r;
status = json_variant_ref(json_variant_by_key(*v, "status"));
z = json_variant_ref(json_variant_by_key(status, sd_id128_to_string(mid, buf)));
z = json_variant_ref(json_variant_by_key(status, SD_ID128_TO_STRING(mid)));
if (json_variant_by_key(z, "service"))
return 0;
@ -63,7 +62,7 @@ static int add_nss_service(JsonVariant **v) {
if (r < 0)
return r;
r = json_variant_set_field(&status, buf, z);
r = json_variant_set_field(&status, SD_ID128_TO_STRING(mid), z);
if (r < 0)
return r;

View File

@ -194,7 +194,6 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
static int determine_devices(void) {
_cleanup_free_ void *m = NULL;
sd_id128_t root_uuid, verity_uuid;
char ids[ID128_UUID_STRING_MAX];
size_t l;
int r;
@ -217,7 +216,7 @@ static int determine_devices(void) {
if (!arg_data_what) {
memcpy(&root_uuid, m, sizeof(root_uuid));
arg_data_what = path_join("/dev/disk/by-partuuid", id128_to_uuid_string(root_uuid, ids));
arg_data_what = path_join("/dev/disk/by-partuuid", ID128_TO_UUID_STRING(root_uuid));
if (!arg_data_what)
return log_oom();
}
@ -225,7 +224,7 @@ static int determine_devices(void) {
if (!arg_hash_what) {
memcpy(&verity_uuid, (uint8_t*) m + l - sizeof(verity_uuid), sizeof(verity_uuid));
arg_hash_what = path_join("/dev/disk/by-partuuid", id128_to_uuid_string(verity_uuid, ids));
arg_hash_what = path_join("/dev/disk/by-partuuid", ID128_TO_UUID_STRING(verity_uuid));
if (!arg_hash_what)
return log_oom();
}