id128: allow combining --app with show

This effectively exposes sd_id128_get_app_specific() on the commandline.

Fixes https://github.com/systemd/systemd/issues/27514.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-09-02 14:17:29 +03:00
parent aea3f594db
commit b37e8184a5
4 changed files with 57 additions and 13 deletions
+11 -3
View File
@@ -68,8 +68,16 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) {
}
static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first) {
sd_id128_t u;
int r;
assert(table);
if (sd_id128_is_null(arg_app))
u = uuid;
else
assert_se(sd_id128_get_app_specific(uuid, arg_app, &u) == 0);
if (arg_mode == ID128_PRINT_PRETTY) {
_cleanup_free_ char *id = NULL;
@@ -79,7 +87,7 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
ascii_strupper(id);
r = id128_pretty_print_sample(id, uuid);
r = id128_pretty_print_sample(id, u);
if (r < 0)
return r;
if (!first)
@@ -87,7 +95,7 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
return 0;
} else if (arg_value)
return id128_pretty_print(uuid, arg_mode);
return id128_pretty_print(u, arg_mode);
else {
if (!*table) {
@@ -100,7 +108,7 @@ static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first
return table_add_many(*table,
TABLE_STRING, name,
arg_mode == ID128_PRINT_ID128 ? TABLE_ID128 : TABLE_UUID,
uuid);
u);
}
}
+1
View File
@@ -180,6 +180,7 @@ TEST(id128) {
assert_se(lseek(fd, 0, SEEK_SET) == 0);
assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN);
/* build/systemd-id128 -a f03daaeb1c334b43a732172944bf772e show 51df0b4bc3b04c9780e299b98ca373b8 */
assert_se(sd_id128_get_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0);
assert_se(sd_id128_equal(id, SD_ID128_MAKE(1d,ee,59,54,e7,5c,4d,6f,b9,6c,c6,c0,4c,a1,8a,86)));