logind: more specific error message for unknown users

If you try to run `loginctl user-status` on a non-logged in user to see
whether "Linger" is enabled, it doesn't work.

If you're already an expert in logind, the fact that the user is considered
unknown actually tells you the user is not lingering.  So, probably they
they do not have lingering enabled.  I think we can point towards this
without being misleading.

I also reword it because I thought it was slightly confusing to run
`loginctl user-status root` and get an error back about "User 0".  Try to
be more specific, that it is "User ID 0".
This commit is contained in:
Alan Jenkins
2017-11-14 18:15:33 +00:00
parent e4d2984bf8
commit 095b8833d6
+5 -3
View File
@@ -123,7 +123,7 @@ static int get_sender_user(Manager *m, sd_bus_message *message, sd_bus_error *er
return 0;
err_no_user:
return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "Caller does not belong to any known or logged in user");
return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "Caller does not belong to any logged in user or lingering user");
}
int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret) {
@@ -138,7 +138,7 @@ int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid,
user = hashmap_get(m->users, UID_TO_PTR(uid));
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user "UID_FMT" known or logged in", uid);
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "User ID "UID_FMT" is not logged in or lingering", uid);
*ret = user;
return 0;
@@ -454,7 +454,9 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu
if (r < 0)
return r;
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID "PID_FMT" does not belong to any known or logged in user", pid);
return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID,
"PID "PID_FMT" does not belong to any logged in user or lingering user",
pid);
}
p = user_bus_path(user);