diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-08-21 15:38:04 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-10-02 15:13:17 +0200 |
commit | ff7dad484c512b873b86849068a6c0527c575a2c (patch) | |
tree | 27b8e95d4cfc5b068ff29bd1969554814e1f400d /src/shared/id128-print.c | |
parent | docs: add a simple, auto-generated index.md (diff) | |
download | systemd-ff7dad484c512b873b86849068a6c0527c575a2c.tar.xz systemd-ff7dad484c512b873b86849068a6c0527c575a2c.zip |
journalctl: move generate_new_id128() to shared
Diffstat (limited to 'src/shared/id128-print.c')
-rw-r--r-- | src/shared/id128-print.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/shared/id128-print.c b/src/shared/id128-print.c new file mode 100644 index 0000000000..212080fbcc --- /dev/null +++ b/src/shared/id128-print.c @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include <stdio.h> + +#include "sd-id128.h" + +#include "id128-print.h" +#include "log.h" + +int id128_generate_new(void) { + sd_id128_t id; + int r; + unsigned i; + + r = sd_id128_randomize(&id); + if (r < 0) + return log_error_errno(r, "Failed to generate ID: %m"); + + printf("As string:\n" + SD_ID128_FORMAT_STR "\n\n" + "As UUID:\n" + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n\n" + "As man:sd-id128(3) macro:\n" + "#define MESSAGE_XYZ SD_ID128_MAKE(", + SD_ID128_FORMAT_VAL(id), + SD_ID128_FORMAT_VAL(id)); + for (i = 0; i < 16; i++) + printf("%02x%s", id.bytes[i], i != 15 ? "," : ""); + fputs(")\n\n", stdout); + + printf("As Python constant:\n" + ">>> import uuid\n" + ">>> MESSAGE_XYZ = uuid.UUID('" SD_ID128_FORMAT_STR "')\n", + SD_ID128_FORMAT_VAL(id)); + + return 0; +} |