From cc6182e8540a348c664bcbb4af85701ddc36e5a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 18 May 2017 20:48:09 -0400 Subject: [PATCH] sd-login: always return two arrays of same length from sd_seat_get_sessions sd_seat_get_sessions returns two arrays, that in principle should always match: the session names and corresponding uids. The second array could be shorter only if parsing or uid conversion fails. But in that case there is no way to tell *which* uid is wrong, so they are *all* useless. It's better to simplify things and just return an error if parsing fails. --- man/sd_seat_get_active.xml | 5 +++-- src/libsystemd/sd-login/sd-login.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/man/sd_seat_get_active.xml b/man/sd_seat_get_active.xml index c5e6dda..3dd461f 100644 --- a/man/sd_seat_get_active.xml +++ b/man/sd_seat_get_active.xml @@ -105,8 +105,9 @@ one (NULL terminated) with the session identifiers of the sessions and one with the user identifiers of the Unix users the sessions belong to. An additional parameter may - be used to return the number of entries in the latter array. The - two arrays and the latter parameter may be passed as + be used to return the number of entries in the latter array. This + value is the same the return value, if the latter is nonnegative. + The two arrays and the last parameter may be passed as NULL in case these values need not to be determined. The arrays and the strings referenced by them need to be freed with the libc diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index cdbdc37..ed15efa 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -723,7 +723,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui r = parse_uid(k, b + i); if (r < 0) - continue; + return r; i++; } -- 2.7.4