]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-login: modernize return parameter handling
authorLennart Poettering <lennart@poettering.net>
Wed, 4 Jun 2025 09:38:40 +0000 (11:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 4 Jun 2025 15:58:42 +0000 (17:58 +0200)
Let's rename the return parameters as "ret_xyz" systematically in
sd-login.

Also, let's make the return parameters systematically optional, like we
typically do these days. So far some where optional, other's weren't.
Let's clean this up.

src/basic/cgroup-util.c
src/basic/fs-util.c
src/libsystemd/sd-login/sd-login.c
src/systemd/sd-login.h

index f3ce17424486de6eb122eb6a07d12fe92970adf0..97c05e18f94967305f54041b5be8e123db19cb5d 100644 (file)
@@ -915,7 +915,6 @@ int cg_pid_get_path_shifted(pid_t pid, const char *root, char **ret_cgroup) {
 
 int cg_path_decode_unit(const char *cgroup, char **ret_unit) {
         assert(cgroup);
-        assert(ret_unit);
 
         size_t n = strcspn(cgroup, "/");
         if (n < 3)
@@ -927,7 +926,10 @@ int cg_path_decode_unit(const char *cgroup, char **ret_unit) {
         if (!unit_name_is_valid(c, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
                 return -ENXIO;
 
-        return strdup_to(ret_unit, c);
+        if (ret_unit)
+                return strdup_to(ret_unit, c);
+
+        return 0;
 }
 
 static bool valid_slice_name(const char *p, size_t n) {
@@ -976,7 +978,6 @@ int cg_path_get_unit(const char *path, char **ret) {
         int r;
 
         assert(path);
-        assert(ret);
 
         e = skip_slices(path);
 
@@ -988,7 +989,8 @@ int cg_path_get_unit(const char *path, char **ret) {
         if (endswith(unit, ".slice"))
                 return -ENXIO;
 
-        *ret = TAKE_PTR(unit);
+        if (ret)
+                *ret = TAKE_PTR(unit);
         return 0;
 }
 
@@ -1157,7 +1159,6 @@ int cg_path_get_user_unit(const char *path, char **ret) {
         const char *t;
 
         assert(path);
-        assert(ret);
 
         t = skip_user_prefix(path);
         if (!t)
@@ -1172,8 +1173,6 @@ int cg_pid_get_user_unit(pid_t pid, char **ret_unit) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
 
-        assert(ret_unit);
-
         r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
         if (r < 0)
                 return r;
@@ -1198,8 +1197,6 @@ int cg_pid_get_machine_name(pid_t pid, char **ret_machine) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
 
-        assert(ret_machine);
-
         r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
         if (r < 0)
                 return r;
@@ -1332,7 +1329,6 @@ int cg_path_get_slice(const char *p, char **ret_slice) {
         const char *e = NULL;
 
         assert(p);
-        assert(ret_slice);
 
         /* Finds the right-most slice unit from the beginning, but stops before we come to
          * the first non-slice unit. */
@@ -1353,15 +1349,16 @@ int cg_path_get_slice(const char *p, char **ret_slice) {
         if (e)
                 return cg_path_decode_unit(e, ret_slice);
 
-        return strdup_to(ret_slice, SPECIAL_ROOT_SLICE);
+        if (ret_slice)
+                return strdup_to(ret_slice, SPECIAL_ROOT_SLICE);
+
+        return 0;
 }
 
 int cg_pid_get_slice(pid_t pid, char **ret_slice) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
 
-        assert(ret_slice);
-
         r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
         if (r < 0)
                 return r;
@@ -1372,7 +1369,6 @@ int cg_pid_get_slice(pid_t pid, char **ret_slice) {
 int cg_path_get_user_slice(const char *p, char **ret_slice) {
         const char *t;
         assert(p);
-        assert(ret_slice);
 
         t = skip_user_prefix(p);
         if (!t)
@@ -1387,8 +1383,6 @@ int cg_pid_get_user_slice(pid_t pid, char **ret_slice) {
         _cleanup_free_ char *cgroup = NULL;
         int r;
 
-        assert(ret_slice);
-
         r = cg_pid_get_path_shifted(pid, NULL, &cgroup);
         if (r < 0)
                 return r;
index a845a1e70b2bd4b4fbb0d071496e74d80836a5e1..04f7290cc2c00655926061fc5d5fdde805635029 100644 (file)
@@ -535,7 +535,7 @@ int mkfifoat_atomic(int atfd, const char *path, mode_t mode) {
         return 0;
 }
 
-int get_files_in_directory(const char *path, char ***list) {
+int get_files_in_directory(const char *path, char ***ret_list) {
         _cleanup_strv_free_ char **l = NULL;
         _cleanup_closedir_ DIR *d = NULL;
         size_t n = 0;
@@ -554,7 +554,7 @@ int get_files_in_directory(const char *path, char ***list) {
                 if (!dirent_is_file(de))
                         continue;
 
-                if (list) {
+                if (ret_list) {
                         /* one extra slot is needed for the terminating NULL */
                         if (!GREEDY_REALLOC(l, n + 2))
                                 return -ENOMEM;
@@ -568,8 +568,8 @@ int get_files_in_directory(const char *path, char ***list) {
                         n++;
         }
 
-        if (list)
-                *list = TAKE_PTR(l);
+        if (ret_list)
+                *ret_list = TAKE_PTR(l);
 
         return n;
 }
index f49713597a878ea42217a2a6d40922ae68ebee48..93ceedeb89c2ad48230bca532f561498799a7298 100644 (file)
  *    requested metadata on object is missing → -ENODATA
  */
 
-_public_ int sd_pid_get_session(pid_t pid, char **session) {
+_public_ int sd_pid_get_session(pid_t pid, char **ret_session) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(session, -EINVAL);
 
-        r = cg_pid_get_session(pid, session);
+        r = cg_pid_get_session(pid, ret_session);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
+_public_ int sd_pid_get_unit(pid_t pid, char **ret_unit) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(unit, -EINVAL);
 
-        r = cg_pid_get_unit(pid, unit);
+        r = cg_pid_get_unit(pid, ret_unit);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_user_unit(pid_t pid, char **unit) {
+_public_ int sd_pid_get_user_unit(pid_t pid, char **ret_unit) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(unit, -EINVAL);
 
-        r = cg_pid_get_user_unit(pid, unit);
+        r = cg_pid_get_user_unit(pid, ret_unit);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_machine_name(pid_t pid, char **name) {
+_public_ int sd_pid_get_machine_name(pid_t pid, char **ret_name) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(name, -EINVAL);
 
-        r = cg_pid_get_machine_name(pid, name);
+        r = cg_pid_get_machine_name(pid, ret_name);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_slice(pid_t pid, char **slice) {
+_public_ int sd_pid_get_slice(pid_t pid, char **ret_slice) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(slice, -EINVAL);
 
-        r = cg_pid_get_slice(pid, slice);
+        r = cg_pid_get_slice(pid, ret_slice);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_user_slice(pid_t pid, char **slice) {
+_public_ int sd_pid_get_user_slice(pid_t pid, char **ret_slice) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(slice, -EINVAL);
 
-        r = cg_pid_get_user_slice(pid, slice);
+        r = cg_pid_get_user_slice(pid, ret_slice);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
+_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *ret_uid) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(uid, -EINVAL);
 
-        r = cg_pid_get_owner_uid(pid, uid);
+        r = cg_pid_get_owner_uid(pid, ret_uid);
         return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
 }
 
-_public_ int sd_pid_get_cgroup(pid_t pid, char **cgroup) {
-        char *c;
+_public_ int sd_pid_get_cgroup(pid_t pid, char **ret_cgroup) {
         int r;
 
         assert_return(pid >= 0, -EINVAL);
-        assert_return(cgroup, -EINVAL);
 
+        _cleanup_free_ char *c = NULL;
         r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &c);
         if (r < 0)
                 return r;
 
-        /* The internal APIs return the empty string for the root
-         * cgroup, let's return the "/" in the public APIs instead, as
-         * that's easier and less ambiguous for people to grok. */
-        if (isempty(c)) {
-                r = free_and_strdup(&c, "/");
-                if (r < 0)
-                        return r;
+        if (ret_cgroup) {
+                /* The internal APIs return the empty string for the root cgroup, let's return the "/" in the
+                 * public APIs instead, as that's easier and less ambiguous for people to grok. */
+                if (isempty(c)) {
+                        r = free_and_strdup(&c, "/");
+                        if (r < 0)
+                                return r;
+                }
 
+                *ret_cgroup = TAKE_PTR(c);
         }
 
-        *cgroup = c;
         return 0;
 }
 
@@ -137,7 +130,6 @@ _public_ int sd_pidfd_get_session(int pidfd, char **ret_session) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_session, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -151,8 +143,8 @@ _public_ int sd_pidfd_get_session(int pidfd, char **ret_session) {
         if (r < 0)
                 return r;
 
-        *ret_session = TAKE_PTR(session);
-
+        if (ret_session)
+                *ret_session = TAKE_PTR(session);
         return 0;
 }
 
@@ -162,7 +154,6 @@ _public_ int sd_pidfd_get_unit(int pidfd, char **ret_unit) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_unit, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -176,8 +167,8 @@ _public_ int sd_pidfd_get_unit(int pidfd, char **ret_unit) {
         if (r < 0)
                 return r;
 
-        *ret_unit = TAKE_PTR(unit);
-
+        if (ret_unit)
+                *ret_unit = TAKE_PTR(unit);
         return 0;
 }
 
@@ -187,7 +178,6 @@ _public_ int sd_pidfd_get_user_unit(int pidfd, char **ret_unit) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_unit, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -201,8 +191,8 @@ _public_ int sd_pidfd_get_user_unit(int pidfd, char **ret_unit) {
         if (r < 0)
                 return r;
 
-        *ret_unit = TAKE_PTR(unit);
-
+        if (ret_unit)
+                *ret_unit = TAKE_PTR(unit);
         return 0;
 }
 
@@ -212,7 +202,6 @@ _public_ int sd_pidfd_get_machine_name(int pidfd, char **ret_name) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_name, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -226,8 +215,8 @@ _public_ int sd_pidfd_get_machine_name(int pidfd, char **ret_name) {
         if (r < 0)
                 return r;
 
-        *ret_name = TAKE_PTR(name);
-
+        if (ret_name)
+                *ret_name = TAKE_PTR(name);
         return 0;
 }
 
@@ -237,7 +226,6 @@ _public_ int sd_pidfd_get_slice(int pidfd, char **ret_slice) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_slice, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -251,8 +239,8 @@ _public_ int sd_pidfd_get_slice(int pidfd, char **ret_slice) {
         if (r < 0)
                 return r;
 
-        *ret_slice = TAKE_PTR(slice);
-
+        if (ret_slice)
+                *ret_slice = TAKE_PTR(slice);
         return 0;
 }
 
@@ -262,7 +250,6 @@ _public_ int sd_pidfd_get_user_slice(int pidfd, char **ret_slice) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_slice, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -276,8 +263,8 @@ _public_ int sd_pidfd_get_user_slice(int pidfd, char **ret_slice) {
         if (r < 0)
                 return r;
 
-        *ret_slice = TAKE_PTR(slice);
-
+        if (ret_slice)
+                *ret_slice = TAKE_PTR(slice);
         return 0;
 }
 
@@ -287,7 +274,6 @@ _public_ int sd_pidfd_get_owner_uid(int pidfd, uid_t *ret_uid) {
         int r;
 
         assert_return(pidfd >= 0, -EINVAL);
-        assert_return(ret_uid, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -301,8 +287,8 @@ _public_ int sd_pidfd_get_owner_uid(int pidfd, uid_t *ret_uid) {
         if (r < 0)
                 return r;
 
-        *ret_uid = uid;
-
+        if (ret_uid)
+                *ret_uid = uid;
         return 0;
 }
 
@@ -312,7 +298,6 @@ _public_ int sd_pidfd_get_cgroup(int pidfd, char **ret_cgroup) {
         int r;
 
         assert_return(pidfd >= 0, -EBADF);
-        assert_return(ret_cgroup, -EINVAL);
 
         r = pidfd_get_pid(pidfd, &pid);
         if (r < 0)
@@ -326,145 +311,135 @@ _public_ int sd_pidfd_get_cgroup(int pidfd, char **ret_cgroup) {
         if (r < 0)
                 return r;
 
-        *ret_cgroup = TAKE_PTR(cgroup);
-
+        if (ret_cgroup)
+                *ret_cgroup = TAKE_PTR(cgroup);
         return 0;
 }
 
-_public_ int sd_peer_get_session(int fd, char **ret) {
+_public_ int sd_peer_get_session(int fd, char **ret_session) {
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(ret, -EINVAL);
 
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         r = getpeerpidref(fd, &pidref);
         if (r < 0)
                 return r;
 
-        return cg_pidref_get_session(&pidref, ret);
+        return cg_pidref_get_session(&pidref, ret_session);
 }
 
-_public_ int sd_peer_get_owner_uid(int fd, uid_t *ret) {
+_public_ int sd_peer_get_owner_uid(int fd, uid_t *ret_uid) {
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(ret, -EINVAL);
 
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         r = getpeerpidref(fd, &pidref);
         if (r < 0)
                 return r;
 
-        return cg_pidref_get_owner_uid(&pidref, ret);
+        return cg_pidref_get_owner_uid(&pidref, ret_uid);
 }
 
-_public_ int sd_peer_get_unit(int fd, char **ret) {
+_public_ int sd_peer_get_unit(int fd, char **ret_unit) {
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(ret, -EINVAL);
 
         _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
         r = getpeerpidref(fd, &pidref);
         if (r < 0)
                 return r;
 
-        return cg_pidref_get_unit(&pidref, ret);
+        return cg_pidref_get_unit(&pidref, ret_unit);
 }
 
-_public_ int sd_peer_get_user_unit(int fd, char **unit) {
+_public_ int sd_peer_get_user_unit(int fd, char **ret_unit) {
         struct ucred ucred;
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(unit, -EINVAL);
 
         r = getpeercred(fd, &ucred);
         if (r < 0)
                 return r;
 
-        return cg_pid_get_user_unit(ucred.pid, unit);
+        return cg_pid_get_user_unit(ucred.pid, ret_unit);
 }
 
-_public_ int sd_peer_get_machine_name(int fd, char **machine) {
+_public_ int sd_peer_get_machine_name(int fd, char **ret_machine) {
         struct ucred ucred;
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(machine, -EINVAL);
 
         r = getpeercred(fd, &ucred);
         if (r < 0)
                 return r;
 
-        return cg_pid_get_machine_name(ucred.pid, machine);
+        return cg_pid_get_machine_name(ucred.pid, ret_machine);
 }
 
-_public_ int sd_peer_get_slice(int fd, char **slice) {
+_public_ int sd_peer_get_slice(int fd, char **ret_slice) {
         struct ucred ucred;
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(slice, -EINVAL);
 
         r = getpeercred(fd, &ucred);
         if (r < 0)
                 return r;
 
-        return cg_pid_get_slice(ucred.pid, slice);
+        return cg_pid_get_slice(ucred.pid, ret_slice);
 }
 
-_public_ int sd_peer_get_user_slice(int fd, char **slice) {
+_public_ int sd_peer_get_user_slice(int fd, char **ret_slice) {
         struct ucred ucred;
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(slice, -EINVAL);
 
         r = getpeercred(fd, &ucred);
         if (r < 0)
                 return r;
 
-        return cg_pid_get_user_slice(ucred.pid, slice);
+        return cg_pid_get_user_slice(ucred.pid, ret_slice);
 }
 
-_public_ int sd_peer_get_cgroup(int fd, char **cgroup) {
+_public_ int sd_peer_get_cgroup(int fd, char **ret_cgroup) {
         struct ucred ucred;
         int r;
 
         assert_return(fd >= 0, -EBADF);
-        assert_return(cgroup, -EINVAL);
 
         r = getpeercred(fd, &ucred);
         if (r < 0)
                 return r;
 
-        return sd_pid_get_cgroup(ucred.pid, cgroup);
+        return sd_pid_get_cgroup(ucred.pid, ret_cgroup);
 }
 
-static int file_of_uid(uid_t uid, char **p) {
+static int file_of_uid(uid_t uid, char **ret) {
 
         assert_return(uid_is_valid(uid), -EINVAL);
-        assert(p);
+        assert(ret);
 
-        if (asprintf(p, "/run/systemd/users/" UID_FMT, uid) < 0)
+        if (asprintf(ret, "/run/systemd/users/" UID_FMT, uid) < 0)
                 return -ENOMEM;
 
         return 0;
 }
 
-_public_ int sd_uid_get_state(uid_t uid, char**state) {
+_public_ int sd_uid_get_state(uid_t uid, char **ret_state) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
-        assert_return(state, -EINVAL);
-
         r = file_of_uid(uid, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "STATE", &s);
+        r = parse_env_file(/* f= */ NULL, p, "STATE", &s);
         if (r == -ENOENT)
                 r = free_and_strdup(&s, "offline");
         if (r < 0)
@@ -472,21 +447,20 @@ _public_ int sd_uid_get_state(uid_t uid, char**state) {
         if (isempty(s))
                 return -EIO;
 
-        *state = TAKE_PTR(s);
+        if (ret_state)
+                *ret_state = TAKE_PTR(s);
         return 0;
 }
 
-_public_ int sd_uid_get_display(uid_t uid, char **session) {
+_public_ int sd_uid_get_display(uid_t uid, char **ret_session) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
-        assert_return(session, -EINVAL);
-
         r = file_of_uid(uid, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "DISPLAY", &s);
+        r = parse_env_file(/* f= */ NULL, p, "DISPLAY", &s);
         if (r == -ENOENT)
                 return -ENODATA;
         if (r < 0)
@@ -494,23 +468,20 @@ _public_ int sd_uid_get_display(uid_t uid, char **session) {
         if (isempty(s))
                 return -ENODATA;
 
-        *session = TAKE_PTR(s);
-
+        if (ret_session)
+                *ret_session = TAKE_PTR(s);
         return 0;
 }
 
-_public_ int sd_uid_get_login_time(uid_t uid, uint64_t *usec) {
+_public_ int sd_uid_get_login_time(uid_t uid, uint64_t *ret_usec) {
         _cleanup_free_ char *p = NULL, *s = NULL, *rt = NULL;
-        usec_t t;
         int r;
 
-        assert_return(usec, -EINVAL);
-
         r = file_of_uid(uid, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "STATE", &s, "REALTIME", &rt);
+        r = parse_env_file(/* f= */ NULL, p, "STATE", &s, "REALTIME", &rt);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -521,19 +492,14 @@ _public_ int sd_uid_get_login_time(uid_t uid, uint64_t *usec) {
         if (!STR_IN_SET(s, "active", "online"))
                 return -ENXIO;
 
-        r = safe_atou64(rt, &t);
-        if (r < 0)
-                return r;
-
-        *usec = t;
-        return 0;
+        return safe_atou64(rt, ret_usec);
 }
 
-static int file_of_seat(const char *seat, char **_p) {
+static int file_of_seat(const char *seat, char **ret) {
         char *p;
         int r;
 
-        assert(_p);
+        assert(ret);
 
         if (seat) {
                 if (!filename_is_valid(seat))
@@ -552,7 +518,7 @@ static int file_of_seat(const char *seat, char **_p) {
         if (!p)
                 return -ENOMEM;
 
-        *_p = TAKE_PTR(p);
+        *ret = TAKE_PTR(p);
         return 0;
 }
 
@@ -566,7 +532,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, filename,
+        r = parse_env_file(/* f= */ NULL, filename,
                            require_active ? "ACTIVE_UID" : "UIDS",
                            &content);
         if (r == -ENOENT)
@@ -579,9 +545,8 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
         return string_contains_word(content, NULL, FORMAT_UID(uid));
 }
 
-static int uid_get_array(uid_t uid, const char *variable, char ***array) {
+static int uid_get_array(uid_t uid, const char *variable, char ***ret_array) {
         _cleanup_free_ char *p = NULL, *s = NULL;
-        char **a;
         int r;
 
         assert(variable);
@@ -590,53 +555,51 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) {
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, variable, &s);
+        r = parse_env_file(/* f= */ NULL, p, variable, &s);
         if (r == -ENOENT || (r >= 0 && isempty(s))) {
-                if (array)
-                        *array = NULL;
+                if (ret_array)
+                        *ret_array = NULL;
                 return 0;
         }
         if (r < 0)
                 return r;
 
-        a = strv_split(s, NULL);
+        _cleanup_strv_free_ char **a = strv_split(s, NULL);
         if (!a)
                 return -ENOMEM;
 
         strv_uniq(a);
         r = (int) strv_length(a);
 
-        if (array)
-                *array = a;
-        else
-                strv_free(a);
+        if (ret_array)
+                *ret_array = TAKE_PTR(a);
 
         return r;
 }
 
-_public_ int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions) {
+_public_ int sd_uid_get_sessions(uid_t uid, int require_active, char ***ret_sessions) {
         return uid_get_array(
                         uid,
                         require_active == 0 ? "ONLINE_SESSIONS" :
                         require_active > 0  ? "ACTIVE_SESSIONS" :
                                               "SESSIONS",
-                        sessions);
+                        ret_sessions);
 }
 
-_public_ int sd_uid_get_seats(uid_t uid, int require_active, char ***seats) {
+_public_ int sd_uid_get_seats(uid_t uid, int require_active, char ***ret_seats) {
         return uid_get_array(
                         uid,
                         require_active == 0 ? "ONLINE_SEATS" :
                         require_active > 0  ? "ACTIVE_SEATS" :
                                               "SEATS",
-                        seats);
+                        ret_seats);
 }
 
-static int file_of_session(const char *session, char **_p) {
+static int file_of_session(const char *session, char **ret) {
         char *p;
         int r;
 
-        assert(_p);
+        assert(ret);
 
         if (session) {
                 if (!session_id_valid(session))
@@ -652,11 +615,10 @@ static int file_of_session(const char *session, char **_p) {
 
                 p = path_join("/run/systemd/sessions", buf);
         }
-
         if (!p)
                 return -ENOMEM;
 
-        *_p = p;
+        *ret = p;
         return 0;
 }
 
@@ -668,7 +630,7 @@ _public_ int sd_session_is_active(const char *session) {
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "ACTIVE", &s);
+        r = parse_env_file(/* f= */ NULL, p, "ACTIVE", &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -687,7 +649,7 @@ _public_ int sd_session_is_remote(const char *session) {
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "REMOTE", &s);
+        r = parse_env_file(/* f= */ NULL, p, "REMOTE", &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -698,17 +660,15 @@ _public_ int sd_session_is_remote(const char *session) {
         return parse_boolean(s);
 }
 
-_public_ int sd_session_get_state(const char *session, char **state) {
+_public_ int sd_session_get_state(const char *session, char **ret_state) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
-        assert_return(state, -EINVAL);
-
         r = file_of_session(session, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "STATE", &s);
+        r = parse_env_file(/* f= */ NULL, p, "STATE", &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -716,22 +676,20 @@ _public_ int sd_session_get_state(const char *session, char **state) {
         if (isempty(s))
                 return -EIO;
 
-        *state = TAKE_PTR(s);
-
+        if (ret_state)
+                *ret_state = TAKE_PTR(s);
         return 0;
 }
 
-_public_ int sd_session_get_uid(const char *session, uid_t *uid) {
+_public_ int sd_session_get_uid(const char *session, uid_t *ret_uid) {
         int r;
         _cleanup_free_ char *p = NULL, *s = NULL;
 
-        assert_return(uid, -EINVAL);
-
         r = file_of_session(session, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "UID", &s);
+        r = parse_env_file(/* f= */ NULL, p, "UID", &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -739,21 +697,20 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
         if (isempty(s))
                 return -EIO;
 
-        return parse_uid(s, uid);
+        return parse_uid(s, ret_uid);
 }
 
-static int session_get_string(const char *session, const char *field, char **value) {
+static int session_get_string(const char *session, const char *field, char **ret_value) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
-        assert_return(value, -EINVAL);
         assert(field);
 
         r = file_of_session(session, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, field, &s);
+        r = parse_env_file(/* f= */ NULL, p, field, &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -761,30 +718,28 @@ static int session_get_string(const char *session, const char *field, char **val
         if (isempty(s))
                 return -ENODATA;
 
-        *value = TAKE_PTR(s);
+        if (ret_value)
+                *ret_value = TAKE_PTR(s);
         return 0;
 }
 
-_public_ int sd_session_get_username(const char *session, char **username) {
-        return session_get_string(session, "USER", username);
+_public_ int sd_session_get_username(const char *session, char **ret_username) {
+        return session_get_string(session, "USER", ret_username);
 }
 
-_public_ int sd_session_get_seat(const char *session, char **seat) {
-        return session_get_string(session, "SEAT", seat);
+_public_ int sd_session_get_seat(const char *session, char **ret_seat) {
+        return session_get_string(session, "SEAT", ret_seat);
 }
 
-_public_ int sd_session_get_start_time(const char *session, uint64_t *usec) {
+_public_ int sd_session_get_start_time(const char *session, uint64_t *ret_usec) {
         _cleanup_free_ char *p = NULL, *s = NULL;
-        usec_t t;
         int r;
 
-        assert_return(usec, -EINVAL);
-
         r = file_of_session(session, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p, "REALTIME", &s);
+        r = parse_env_file(/* f= */ NULL, p, "REALTIME", &s);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
@@ -792,95 +747,72 @@ _public_ int sd_session_get_start_time(const char *session, uint64_t *usec) {
         if (isempty(s))
                 return -EIO;
 
-        r = safe_atou64(s, &t);
-        if (r < 0)
-                return r;
-
-        *usec = t;
-        return 0;
+        return safe_atou64(s, ret_usec);
 }
 
-_public_ int sd_session_get_tty(const char *session, char **tty) {
-        return session_get_string(session, "TTY", tty);
+_public_ int sd_session_get_tty(const char *session, char **ret_tty) {
+        return session_get_string(session, "TTY", ret_tty);
 }
 
-_public_ int sd_session_get_vt(const char *session, unsigned *vtnr) {
+_public_ int sd_session_get_vt(const char *session, unsigned *ret_vtnr) {
         _cleanup_free_ char *vtnr_string = NULL;
-        unsigned u;
         int r;
 
-        assert_return(vtnr, -EINVAL);
-
         r = session_get_string(session, "VTNR", &vtnr_string);
         if (r < 0)
                 return r;
 
-        r = safe_atou(vtnr_string, &u);
-        if (r < 0)
-                return r;
-
-        *vtnr = u;
-        return 0;
+        return safe_atou(vtnr_string, ret_vtnr);
 }
 
-_public_ int sd_session_get_service(const char *session, char **service) {
-        return session_get_string(session, "SERVICE", service);
+_public_ int sd_session_get_service(const char *session, char **ret_service) {
+        return session_get_string(session, "SERVICE", ret_service);
 }
 
-_public_ int sd_session_get_type(const char *session, char **type) {
-        return session_get_string(session, "TYPE", type);
+_public_ int sd_session_get_type(const char *session, char **ret_type) {
+        return session_get_string(session, "TYPE", ret_type);
 }
 
-_public_ int sd_session_get_class(const char *session, char **class) {
-        return session_get_string(session, "CLASS", class);
+_public_ int sd_session_get_class(const char *session, char **ret_class) {
+        return session_get_string(session, "CLASS", ret_class);
 }
 
-_public_ int sd_session_get_desktop(const char *session, char **desktop) {
-        return session_get_string(session, "DESKTOP", desktop);
+_public_ int sd_session_get_desktop(const char *session, char **ret_desktop) {
+        return session_get_string(session, "DESKTOP", ret_desktop);
 }
 
-_public_ int sd_session_get_display(const char *session, char **display) {
-        return session_get_string(session, "DISPLAY", display);
+_public_ int sd_session_get_display(const char *session, char **ret_display) {
+        return session_get_string(session, "DISPLAY", ret_display);
 }
 
-_public_ int sd_session_get_remote_user(const char *session, char **remote_user) {
-        return session_get_string(session, "REMOTE_USER", remote_user);
+_public_ int sd_session_get_remote_user(const char *session, char **ret_remote_user) {
+        return session_get_string(session, "REMOTE_USER", ret_remote_user);
 }
 
-_public_ int sd_session_get_remote_host(const char *session, char **remote_host) {
-        return session_get_string(session, "REMOTE_HOST", remote_host);
+_public_ int sd_session_get_remote_host(const char *session, char **ret_remote_host) {
+        return session_get_string(session, "REMOTE_HOST", ret_remote_host);
 }
 
-_public_ int sd_session_get_leader(const char *session, pid_t *leader) {
+_public_ int sd_session_get_leader(const char *session, pid_t *ret_leader) {
         _cleanup_free_ char *leader_string = NULL;
-        pid_t pid;
         int r;
 
-        assert_return(leader, -EINVAL);
-
         r = session_get_string(session, "LEADER", &leader_string);
         if (r < 0)
                 return r;
 
-        r = parse_pid(leader_string, &pid);
-        if (r < 0)
-                return r;
-
-        *leader = pid;
-        return 0;
+        return parse_pid(leader_string, ret_leader);
 }
 
 _public_ int sd_seat_get_active(const char *seat, char **ret_session, uid_t *ret_uid) {
         _cleanup_free_ char *p = NULL, *s = NULL, *t = NULL;
         int r;
 
-        assert_return(ret_session || ret_uid, -EINVAL);
-
         r = file_of_seat(seat, &p);
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p,
+        r = parse_env_file(/* f= */ NULL, p,
                            "ACTIVE", &s,
                            "ACTIVE_UID", &t);
         if (r == -ENOENT)
@@ -922,7 +854,7 @@ _public_ int sd_seat_get_sessions(
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, fname,
+        r = parse_env_file(/* f= */ NULL, fname,
                            "SESSIONS", &session_line,
                            "UIDS", &uid_line);
         if (r == -ENOENT)
@@ -982,7 +914,7 @@ static int seat_get_can(const char *seat, const char *variable) {
         if (r < 0)
                 return r;
 
-        r = parse_env_file(NULL, p,
+        r = parse_env_file(/* f= */ NULL, p,
                            variable, &s);
         if (r == -ENOENT)
                 return -ENXIO;
@@ -1006,31 +938,31 @@ _public_ int sd_seat_can_graphical(const char *seat) {
         return seat_get_can(seat, "CAN_GRAPHICAL");
 }
 
-_public_ int sd_get_seats(char ***seats) {
+_public_ int sd_get_seats(char ***ret_seats) {
         int r;
 
-        r = get_files_in_directory("/run/systemd/seats/", seats);
+        r = get_files_in_directory("/run/systemd/seats/", ret_seats);
         if (r == -ENOENT) {
-                if (seats)
-                        *seats = NULL;
+                if (ret_seats)
+                        *ret_seats = NULL;
                 return 0;
         }
         return r;
 }
 
-_public_ int sd_get_sessions(char ***sessions) {
+_public_ int sd_get_sessions(char ***ret_sessions) {
         int r;
 
-        r = get_files_in_directory("/run/systemd/sessions/", sessions);
+        r = get_files_in_directory("/run/systemd/sessions/", ret_sessions);
         if (r == -ENOENT) {
-                if (sessions)
-                        *sessions = NULL;
+                if (ret_sessions)
+                        *ret_sessions = NULL;
                 return 0;
         }
         return r;
 }
 
-_public_ int sd_get_uids(uid_t **users) {
+_public_ int sd_get_uids(uid_t **ret_users) {
         _cleanup_closedir_ DIR *d = NULL;
         _cleanup_free_ uid_t *l = NULL;
         size_t n = 0;
@@ -1038,8 +970,8 @@ _public_ int sd_get_uids(uid_t **users) {
         d = opendir("/run/systemd/users/");
         if (!d) {
                 if (errno == ENOENT) {
-                        if (users)
-                                *users = NULL;
+                     if (ret_users)
+                                *ret_users = NULL;
                         return 0;
                 }
                 return -errno;
@@ -1054,7 +986,7 @@ _public_ int sd_get_uids(uid_t **users) {
                 if (parse_uid(de->d_name, &uid) < 0)
                         continue;
 
-                if (users) {
+                if (ret_users) {
                         if (!GREEDY_REALLOC(l, n + 1))
                                 return -ENOMEM;
 
@@ -1067,21 +999,21 @@ _public_ int sd_get_uids(uid_t **users) {
         if (n > INT_MAX)
                 return -EOVERFLOW;
 
-        if (users)
-                *users = TAKE_PTR(l);
+        if (ret_users)
+                *ret_users = TAKE_PTR(l);
 
         return (int) n;
 }
 
-_public_ int sd_get_machine_names(char ***machines) {
+_public_ int sd_get_machine_names(char ***ret_machines) {
         _cleanup_strv_free_ char **l = NULL;
         char **a, **b;
         int r;
 
         r = get_files_in_directory("/run/systemd/machines/", &l);
         if (r == -ENOENT) {
-                if (machines)
-                        *machines = NULL;
+                if (ret_machines)
+                        *ret_machines = NULL;
                 return 0;
         }
         if (r < 0)
@@ -1104,20 +1036,17 @@ _public_ int sd_get_machine_names(char ***machines) {
                 *b = NULL;
         }
 
-        if (machines)
-                *machines = TAKE_PTR(l);
+        if (ret_machines)
+                *ret_machines = TAKE_PTR(l);
 
         return r;
 }
 
-_public_ int sd_machine_get_class(const char *machine, char **class) {
+_public_ int sd_machine_get_class(const char *machine, char **ret_class) {
         _cleanup_free_ char *c = NULL;
-        const char *p;
         int r;
 
-        assert_return(class, -EINVAL);
-
-        if (streq(machine, ".host")) {
+        if (streq_ptr(machine, ".host")) {
                 c = strdup("host");
                 if (!c)
                         return -ENOMEM;
@@ -1125,8 +1054,11 @@ _public_ int sd_machine_get_class(const char *machine, char **class) {
                 if (!hostname_is_valid(machine, 0))
                         return -EINVAL;
 
-                p = strjoina("/run/systemd/machines/", machine);
-                r = parse_env_file(NULL, p, "CLASS", &c);
+                _cleanup_free_ char *p = path_join("/run/systemd/machines/", machine);
+                if (!p)
+                        return -ENOMEM;
+
+                r = parse_env_file(/* f= */ NULL, p, "CLASS", &c);
                 if (r == -ENOENT)
                         return -ENXIO;
                 if (r < 0)
@@ -1135,25 +1067,30 @@ _public_ int sd_machine_get_class(const char *machine, char **class) {
                         return -EIO;
         }
 
-        *class = TAKE_PTR(c);
+        if (ret_class)
+                *ret_class = TAKE_PTR(c);
+
         return 0;
 }
 
 _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices) {
-        _cleanup_free_ char *netif_line = NULL;
-        const char *p;
+        _cleanup_free_ char *netif_line = NULL, *p = NULL;
         int r;
 
         assert_return(hostname_is_valid(machine, 0), -EINVAL);
 
-        p = strjoina("/run/systemd/machines/", machine);
-        r = parse_env_file(NULL, p, "NETIF", &netif_line);
+        p = path_join("/run/systemd/machines/", machine);
+        if (!p)
+                return -ENOMEM;
+
+        r = parse_env_file(/* f= */ NULL, p, "NETIF", &netif_line);
         if (r == -ENOENT)
                 return -ENXIO;
         if (r < 0)
                 return r;
         if (!netif_line) {
-                *ret_ifindices = NULL;
+                if (ret_ifindices)
+                        *ret_ifindices = NULL;
                 return 0;
         }
 
@@ -1196,12 +1133,12 @@ static sd_login_monitor* FD_TO_MONITOR(int fd) {
         return (sd_login_monitor*) (unsigned long) (fd + 1);
 }
 
-_public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
+_public_ int sd_login_monitor_new(const char *category, sd_login_monitor **ret) {
         _cleanup_close_ int fd = -EBADF;
         bool good = false;
         int k;
 
-        assert_return(m, -EINVAL);
+        assert_return(ret, -EINVAL);
 
         fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
         if (fd < 0)
@@ -1242,7 +1179,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
         if (!good)
                 return -EINVAL;
 
-        *m = FD_TO_MONITOR(TAKE_FD(fd));
+        *ret = FD_TO_MONITOR(TAKE_FD(fd));
         return 0;
 }
 
@@ -1283,14 +1220,14 @@ _public_ int sd_login_monitor_get_events(sd_login_monitor *m) {
         return POLLIN;
 }
 
-_public_ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec) {
+_public_ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *ret_timeout_usec) {
 
         assert_return(m, -EINVAL);
-        assert_return(timeout_usec, -EINVAL);
+        assert_return(ret_timeout_usec, -EINVAL);
 
         /* For now we will only return UINT64_MAX, since we don't
          * need any timeout. However, let's have this API to keep our
          * options open should we later on need it. */
-        *timeout_usec = UINT64_MAX;
+        *ret_timeout_usec = UINT64_MAX;
         return 0;
 }
index dbf69c2106abd49f389b7fcb3ee56e311d49bd86..1a730c6d0940edd0d67c9150dfaef366ac7b5b68 100644 (file)
@@ -45,90 +45,90 @@ _SD_BEGIN_DECLARATIONS;
  * not attached to a session, but only attached to a user. This will
  * return an error for system processes and 'shared' processes of a
  * user. */
-int sd_pid_get_session(pid_t pid, char **session);
+int sd_pid_get_session(pid_t pid, char **ret_session);
 
 /* Get UID of the owner of the session of the PID (or in case the
  * process is a 'shared' user process, the UID of that user is
  * returned). This will not return the UID of the process, but rather
  * the UID of the owner of the cgroup that the process is in. This will
  * return an error for system processes. */
-int sd_pid_get_owner_uid(pid_t pid, uid_t *uid);
+int sd_pid_get_owner_uid(pid_t pid, uid_t *ret_uid);
 
 /* Get systemd non-slice unit (i.e. service) name from PID, for system
  * services. This will return an error for non-service processes. */
-int sd_pid_get_unit(pid_t pid, char **unit);
+int sd_pid_get_unit(pid_t pid, char **ret_unit);
 
 /* Get systemd non-slice unit (i.e. service) name from PID, for user
  * services. This will return an error for non-user-service
  * processes. */
-int sd_pid_get_user_unit(pid_t pid, char **unit);
+int sd_pid_get_user_unit(pid_t pid, char **ret_unit);
 
 /* Get slice name from PID. */
-int sd_pid_get_slice(pid_t pid, char **slice);
+int sd_pid_get_slice(pid_t pid, char **ret_slice);
 
 /* Get user slice name from PID. */
-int sd_pid_get_user_slice(pid_t pid, char **slice);
+int sd_pid_get_user_slice(pid_t pid, char **ret_slice);
 
 /* Get machine name from PID, for processes assigned to a VM or
  * container. This will return an error for non-machine processes. */
-int sd_pid_get_machine_name(pid_t pid, char **machine);
+int sd_pid_get_machine_name(pid_t pid, char **ret_machine);
 
 /* Get the control group from a PID, relative to the root of the
  * hierarchy. */
-int sd_pid_get_cgroup(pid_t pid, char **cgroup);
+int sd_pid_get_cgroup(pid_t pid, char **ret_cgroup);
 
 /* Equivalent to the corresponding sd_pid_get* functions, but take a
  * PIDFD instead of a PID, to ensure there can be no possible PID
  * recycle issues before/after the calls. */
-int sd_pidfd_get_session(int pidfd, char **session);
-int sd_pidfd_get_owner_uid(int pidfd, uid_t *uid);
-int sd_pidfd_get_unit(int pidfd, char **unit);
-int sd_pidfd_get_user_unit(int pidfd, char **unit);
-int sd_pidfd_get_slice(int pidfd, char **slice);
-int sd_pidfd_get_user_slice(int pidfd, char **slice);
-int sd_pidfd_get_machine_name(int pidfd, char **machine);
-int sd_pidfd_get_cgroup(int pidfd, char **cgroup);
+int sd_pidfd_get_session(int pidfd, char **ret_session);
+int sd_pidfd_get_owner_uid(int pidfd, uid_t *ret_uid);
+int sd_pidfd_get_unit(int pidfd, char **ret_unit);
+int sd_pidfd_get_user_unit(int pidfd, char **ret_unit);
+int sd_pidfd_get_slice(int pidfd, char **ret_slice);
+int sd_pidfd_get_user_slice(int pidfd, char **ret_slice);
+int sd_pidfd_get_machine_name(int pidfd, char **ret_machine);
+int sd_pidfd_get_cgroup(int pidfd, char **ret_cgroup);
 
 /* Similar to sd_pid_get_session(), but retrieves data about the peer
  * of a connected AF_UNIX socket */
-int sd_peer_get_session(int fd, char **session);
+int sd_peer_get_session(int fd, char **ret_session);
 
 /* Similar to sd_pid_get_owner_uid(), but retrieves data about the peer of
  * a connected AF_UNIX socket */
-int sd_peer_get_owner_uid(int fd, uid_t *uid);
+int sd_peer_get_owner_uid(int fd, uid_t *ret_uid);
 
 /* Similar to sd_pid_get_unit(), but retrieves data about the peer of
  * a connected AF_UNIX socket */
-int sd_peer_get_unit(int fd, char **unit);
+int sd_peer_get_unit(int fd, char **ret_unit);
 
 /* Similar to sd_pid_get_user_unit(), but retrieves data about the peer of
  * a connected AF_UNIX socket */
-int sd_peer_get_user_unit(int fd, char **unit);
+int sd_peer_get_user_unit(int fd, char **ret_unit);
 
 /* Similar to sd_pid_get_slice(), but retrieves data about the peer of
  * a connected AF_UNIX socket */
-int sd_peer_get_slice(int fd, char **slice);
+int sd_peer_get_slice(int fd, char **ret_slice);
 
 /* Similar to sd_pid_get_user_slice(), but retrieves data about the peer of
  * a connected AF_UNIX socket */
-int sd_peer_get_user_slice(int fd, char **slice);
+int sd_peer_get_user_slice(int fd, char **ret_slice);
 
 /* Similar to sd_pid_get_machine_name(), but retrieves data about the
  * peer of a connected AF_UNIX socket */
-int sd_peer_get_machine_name(int fd, char **machine);
+int sd_peer_get_machine_name(int fd, char **ret_machine);
 
 /* Similar to sd_pid_get_cgroup(), but retrieves data about the peer
  * of a connected AF_UNIX socket. */
-int sd_peer_get_cgroup(int fd, char **cgroup);
+int sd_peer_get_cgroup(int fd, char **ret_cgroup);
 
 /* Get state from UID. Possible states: offline, lingering, online, active, closing */
-int sd_uid_get_state(uid_t uid, char **state);
+int sd_uid_get_state(uid_t uid, char **ret_state);
 
 /* Return primary session of user, if there is any */
-int sd_uid_get_display(uid_t uid, char **session);
+int sd_uid_get_display(uid_t uid, char **ret_display);
 
 /* Determine the login time of user */
-int sd_uid_get_login_time(uid_t uid, uint64_t *usec);
+int sd_uid_get_login_time(uid_t uid, uint64_t *ret_usec);
 
 /* Return 1 if UID has session on seat. If require_active is true, this will
  * look for active sessions only. */
@@ -137,12 +137,12 @@ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat);
 /* Return sessions of user. If require_active is true, this will look for
  * active sessions only. Returns the number of sessions.
  * If sessions is NULL, this will just return the number of sessions. */
-int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions);
+int sd_uid_get_sessions(uid_t uid, int require_active, char ***ret_sessions);
 
 /* Return seats of user is on. If require_active is true, this will look for
  * active seats only. Returns the number of seats.
  * If seats is NULL, this will just return the number of seats. */
-int sd_uid_get_seats(uid_t uid, int require_active, char ***seats);
+int sd_uid_get_seats(uid_t uid, int require_active, char ***ret_seats);
 
 /* Return 1 if the session is active. */
 int sd_session_is_active(const char *session);
@@ -152,49 +152,49 @@ int sd_session_is_remote(const char *session);
 
 /* Get state from session. Possible states: online, active, closing.
  * This function is a more generic version of sd_session_is_active(). */
-int sd_session_get_state(const char *session, char **state);
+int sd_session_get_state(const char *session, char **ret_state);
 
 /* Determine user ID of session */
-int sd_session_get_uid(const char *session, uid_t *uid);
+int sd_session_get_uid(const char *session, uid_t *ret_uid);
 
 /* Determine username of session */
-int sd_session_get_username(const char *session, char **username);
+int sd_session_get_username(const char *session, char **ret_username);
 
 /* Determine seat of session */
-int sd_session_get_seat(const char *session, char **seat);
+int sd_session_get_seat(const char *session, char **ret_seat);
 
 /* Determine the start time of session */
-int sd_session_get_start_time(const char *session, uint64_t *usec);
+int sd_session_get_start_time(const char *session, uint64_t *ret_usec);
 
 /* Determine the (PAM) service name this session was registered by. */
-int sd_session_get_service(const char *session, char **service);
+int sd_session_get_service(const char *session, char **ret_service);
 
 /* Determine the type of this session, i.e. one of "tty", "x11", "wayland", "mir", "web", or "unspecified". */
-int sd_session_get_type(const char *session, char **type);
+int sd_session_get_type(const char *session, char **ret_type);
 
 /* Determine the class of this session, i.e. one of "user", "greeter" or "lock-screen". */
-int sd_session_get_class(const char *session, char **clazz);
+int sd_session_get_class(const char *session, char **ret_clazz);
 
 /* Determine the desktop brand of this session, i.e. something like "GNOME", "KDE" or "systemd-console". */
-int sd_session_get_desktop(const char *session, char **desktop);
+int sd_session_get_desktop(const char *session, char **ret_desktop);
 
 /* Determine the X11 display of this session. */
-int sd_session_get_display(const char *session, char **display);
+int sd_session_get_display(const char *session, char **ret_display);
 
 /* Determine the leader process of this session. */
-int sd_session_get_leader(const char *session, pid_t *leader);
+int sd_session_get_leader(const char *session, pid_t *ret_leader);
 
 /* Determine the remote host of this session. */
-int sd_session_get_remote_host(const char *session, char **remote_host);
+int sd_session_get_remote_host(const char *session, char **ret_remote_host);
 
 /* Determine the remote user of this session (if provided by PAM). */
-int sd_session_get_remote_user(const char *session, char **remote_user);
+int sd_session_get_remote_user(const char *session, char **tre_remote_user);
 
 /* Determine the TTY of this session. */
-int sd_session_get_tty(const char *session, char **display);
+int sd_session_get_tty(const char *session, char **ret_tty);
 
 /* Determine the VT number of this session. */
-int sd_session_get_vt(const char *session, unsigned *vtnr);
+int sd_session_get_vt(const char *session, unsigned *ret_vtnr);
 
 /* Return active session and user of seat */
 int sd_seat_get_active(const char *seat, char **ret_session, uid_t *ret_uid);
@@ -217,25 +217,25 @@ int sd_seat_can_tty(const char *seat);
 int sd_seat_can_graphical(const char *seat);
 
 /* Return the class of machine */
-int sd_machine_get_class(const char *machine, char **clazz);
+int sd_machine_get_class(const char *machine, char **ret_clazz);
 
 /* Return the list if host-side network interface indices of a machine */
 int sd_machine_get_ifindices(const char *machine, int **ret_ifindices);
 
 /* Get all seats, store in *seats. Returns the number of seats. If
  * seats is NULL, this only returns the number of seats. */
-int sd_get_seats(char ***seats);
+int sd_get_seats(char ***ret_seats);
 
 /* Get all sessions, store in *sessions. Returns the number of
  * sessions. If sessions is NULL, this only returns the number of sessions. */
-int sd_get_sessions(char ***sessions);
+int sd_get_sessions(char ***ret_sessions);
 
 /* Get all logged in users, store in *users. Returns the number of
  * users. If users is NULL, this only returns the number of users. */
-int sd_get_uids(uid_t **users);
+int sd_get_uids(uid_t **ret_users);
 
 /* Get all running virtual machines/containers */
-int sd_get_machine_names(char ***machines);
+int sd_get_machine_names(char ***ret_machines);
 
 /* Monitor object */
 typedef struct sd_login_monitor sd_login_monitor;
@@ -243,7 +243,7 @@ typedef struct sd_login_monitor sd_login_monitor;
 /* Create a new monitor. Category must be NULL, "seat", "session",
  * "uid", or "machine" to get monitor events for the specific category
  * (or all). */
-int sd_login_monitor_new(const char *category, sd_login_monitor** ret);
+int sd_login_monitor_new(const char *category, sd_login_monitor **ret);
 
 /* Destroys the passed monitor. Returns NULL. */
 sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m);
@@ -258,7 +258,7 @@ int sd_login_monitor_get_fd(sd_login_monitor *m);
 int sd_login_monitor_get_events(sd_login_monitor *m);
 
 /* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
-int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec);
+int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *ret_timeout_usec);
 
 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_login_monitor, sd_login_monitor_unref);