launcher: drop privileges before entering main-loop
We need to connect to the bus as root, pinning our credentials. However,
we don't need to be root at run-time, so drop privileges before entering
the mainloop.
This is a follow-up to
#include "util/audit.h"
#include "util/error.h"
#include "util/log.h"
+#include "util/misc.h"
typedef struct Manager Manager;
typedef struct Service Service;
@@ -1478,6 +1479,12 @@ static int manager_run(Manager *manager) {
if (r < 0)
return error_origin(r);
+ if (manager->uid != (uint32_t)-1) {
+ r = util_drop_permissions(manager->uid, manager->gid);
+ if (r)
+ return error_fold(r);
+ }
+
r = sd_event_loop(manager->event);
if (r < 0)
return error_origin(r);
