summaryrefslogtreecommitdiff
path: root/state.c
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2020-10-19 13:43:23 +0100
committerDaniel Golle <daniel@makrotopia.org>2020-10-19 15:48:30 +0100
commit31214674545c3703c1171a02a1949a5d3162bdee (patch)
tree5cc8b6c7d279ecec872ada1a9d730dc0059a33b3 /state.c
parent5ade5673d9a0c9cc1e178f71bd4a20e8c392ec6f (diff)
downloadprocd-31214674545c3703c1171a02a1949a5d3162bdee.tar.gz
early: run ubusd non-root as user ubus, group ubus
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'state.c')
-rw-r--r--state.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/state.c b/state.c
index e117ea3..6ca1d5e 100644
--- a/state.c
+++ b/state.c
@@ -13,6 +13,7 @@
*/
#include <fcntl.h>
+#include <pwd.h>
#include <sys/reboot.h>
#include <stdio.h>
#include <stdlib.h>
@@ -125,6 +126,7 @@ static void perform_halt()
static void state_enter(void)
{
char ubus_cmd[] = "/sbin/ubusd";
+ struct passwd *p;
switch (state) {
case STATE_EARLY:
@@ -139,8 +141,13 @@ static void state_enter(void)
watchdog_init(0);
set_stdio("console");
LOG("- ubus -\n");
+ p = getpwnam("ubus");
+ if (p) {
+ mkdir(p->pw_dir, 0755);
+ chown(p->pw_dir, p->pw_uid, p->pw_gid);
+ }
procd_connect_ubus();
- service_start_early("ubus", ubus_cmd);
+ service_start_early("ubus", ubus_cmd, p?"ubus":NULL, p?"ubus":NULL);
break;
case STATE_INIT: