systemd-id128: a new tool to print machine/boot/invocation/app-specific ids
The raison d'etre for this program is printing machine-app-specific IDs. We provide a library function for that, but not a convenient API. We can hardly ask people to quickly hack their own C programs or call libsystemd through CFFI in python or another scripting language if they just want to print an ID. Verb 'new' was already available as 'journalctl --new-id128', but this makes it more discoverable. v2: - rename binary to systemd-id128 - make --app-specific= into a switch that applies to boot-id and machine-id
This commit is contained in:
@@ -7,14 +7,14 @@
|
||||
#include "id128-print.h"
|
||||
#include "log.h"
|
||||
|
||||
int id128_generate_new(void) {
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
int id128_pretty_print(sd_id128_t id, bool pretty) {
|
||||
unsigned i;
|
||||
|
||||
r = sd_id128_randomize(&id);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate ID: %m");
|
||||
if (!pretty) {
|
||||
printf(SD_ID128_FORMAT_STR "\n",
|
||||
SD_ID128_FORMAT_VAL(id));
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("As string:\n"
|
||||
SD_ID128_FORMAT_STR "\n\n"
|
||||
@@ -35,3 +35,14 @@ int id128_generate_new(void) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int id128_print_new(bool pretty) {
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
|
||||
r = sd_id128_randomize(&id);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate ID: %m");
|
||||
|
||||
return id128_pretty_print(id, pretty);
|
||||
}
|
||||
|
||||
@@ -2,4 +2,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
int id128_generate_new(void);
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
int id128_pretty_print(sd_id128_t id, bool pretty);
|
||||
int id128_print_new(bool pretty);
|
||||
|
||||
Reference in New Issue
Block a user