From e8c63956a5a8d0c40ac2194c545edccb727cff12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 16 May 2018 13:55:12 +0200 Subject: [PATCH] sd-id128: return -ENOMEDIUM on null id We currently return -ENOMEDIUM when /etc/machine-id is empty, and -EINVAL when it is all zeros. But -EINVAL is also used for invalid args. The distinction between empty and all-zero is not very important, let's use the same return code. Also document -ENOENT and -ENOMEDIUM since they can be a bit surprising. --- man/sd_id128_get_machine.xml | 8 +++++--- src/libelogind/sd-id128/sd-id128.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/man/sd_id128_get_machine.xml b/man/sd_id128_get_machine.xml index 2694c186b..f3e151760 100644 --- a/man/sd_id128_get_machine.xml +++ b/man/sd_id128_get_machine.xml @@ -116,9 +116,11 @@ Return Value - The two calls return 0 on success (in which case - ret is filled in), or a negative - errno-style error code. + Those calls return 0 on success (in which case ret is filled in), + or a negative errno-style error code. In particular, sd_id128_get_machine() + and sd_id128_get_machine_app_specific() return -ENOENT + if /etc/machine-id is missing, and -ENOMEDIUM if is + empty or all zeros. diff --git a/src/libelogind/sd-id128/sd-id128.c b/src/libelogind/sd-id128/sd-id128.c index af2ff8353..80548fdfc 100644 --- a/src/libelogind/sd-id128/sd-id128.c +++ b/src/libelogind/sd-id128/sd-id128.c @@ -98,7 +98,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) { return r; if (sd_id128_is_null(saved_machine_id)) - return -EINVAL; + return -ENOMEDIUM; } *ret = saved_machine_id; -- 2.30.2