various: treat BUS_ERROR_NO_SUCH_UNIT the same as SD_BUS_ERROR_SERVICE_UNKNOWN
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Aug 2020 16:48:03 +0000 (18:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 26 Aug 2020 12:35:32 +0000 (14:35 +0200)
commit9bb3e64d715684865a1eb3c1ded60cf36d0d1cf2
tree3d221739c80132ab6039bfb96808f45c19a2f5ea
parent6d802dd5968a8265c4d0e0e4974135cbcb9c9f14
various: treat BUS_ERROR_NO_SUCH_UNIT the same as SD_BUS_ERROR_SERVICE_UNKNOWN

We return BUS_ERROR_NO_SUCH_UNIT a.k.a. org.freedesktop.systemd1.NoSuchUnit
in various places. In #16813:
Aug 22 06:14:48 core sudo[2769199]: pam_systemd_home(sudo:account): Failed to query user record: Unit dbus-org.freedesktop.home1.service not found.
Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.home1.service': Unit dbus-org.freedesktop.home1.service not found.
Aug 22 06:14:48 core dbus-daemon[5311]: [system] Activating via systemd: service name='org.freedesktop.home1' unit='dbus-org.freedesktop.home1.service' requested by ':1.6564' (uid=0 pid=2769199 comm="sudo su ")

This particular error comes from bus_unit_validate_load_state() in pid1:
  case UNIT_NOT_FOUND:
       return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not found.", u->id);

It seems possible that we should return a different error, but it doesn't really
matter: if we change pid1 to return a different error, we still need to handle
BUS_ERROR_NO_SUCH_UNIT as in this patch to handle pid1 with current code.

(cherry picked from commit 73d3ac8e2440cda3b7f2310f329f0798de6c041c)
src/home/pam_systemd_home.c
src/shared/bus-polkit.c
src/sleep/sleep.c