jail: remove duplicate check for hook file permissions
[project/procd.git] / state.c
diff --git a/state.c b/state.c
index e117ea302f9301fea4e483b23c08676890f0ced4..fb81248fd7e7bc7b588a82a5e667424af188cbab 100644 (file)
--- 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:
@@ -138,9 +140,20 @@ static void state_enter(void)
                // try to reopen incase the wdt was not available before coldplug
                watchdog_init(0);
                set_stdio("console");
-               LOG("- ubus -\n");
+               p = getpwnam("ubus");
+               if (p) {
+                       int ret;
+                       LOG("- ubus -\n");
+                       mkdir(p->pw_dir, 0755);
+                       ret = chown(p->pw_dir, p->pw_uid, p->pw_gid);
+                       if (ret)
+                               LOG("- ubus - failed to chown(%s)\n", p->pw_dir);
+               } else {
+                       LOG("- ubus (running as root!) -\n");
+               }
+
                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: