summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2020-12-04 09:53:11 +0000
committerDaniel Golle <daniel@makrotopia.org>2020-12-04 10:16:07 +0000
commitd1d9ddf98d39b0bdc055060fb962335439445690 (patch)
tree998faf898ca12fdaaa8b75dc83fc014c52ce2ba3
parentad0cd117db74934385d81605514e041b1a9cdda9 (diff)
downloadubus-d1d9ddf98d39b0bdc055060fb962335439445690.tar.gz
ubusd: attempt to create socket folder
When ubus is running as root, /var/run/ubus most likely hasn't been created as well (as that's the homedir of user ubus, and if a user ubus was found, then ubus would run being that user). Blindly attempt to create the directory (which won't do any harm if it does exist and/or ubus is not running as root) to still be able to start ubus in case of user ubus not existing. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-rw-r--r--ubusd_main.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ubusd_main.c b/ubusd_main.c
index f977ff3..c3d8049 100644
--- a/ubusd_main.c
+++ b/ubusd_main.c
@@ -6,9 +6,11 @@
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/types.h>
#ifdef FreeBSD
#include <sys/param.h>
#endif
+#include <string.h>
#include <syslog.h>
#include <libubox/usock.h>
@@ -229,6 +231,19 @@ static void sighup_handler(int sig)
ubusd_acl_load();
}
+static void mkdir_sockdir()
+{
+ char *ubus_sock_dir, *tmp;
+
+ ubus_sock_dir = strdup(UBUS_UNIX_SOCKET);
+ tmp = strrchr(ubus_sock_dir, '/');
+ if (tmp) {
+ *tmp = '\0';
+ mkdir(ubus_sock_dir, 0755);
+ }
+ free(ubus_sock_dir);
+}
+
int main(int argc, char **argv)
{
const char *ubus_socket = UBUS_UNIX_SOCKET;
@@ -254,6 +269,7 @@ int main(int argc, char **argv)
}
}
+ mkdir_sockdir();
unlink(ubus_socket);
umask(0111);
server_fd.fd = usock(USOCK_UNIX | USOCK_SERVER | USOCK_NONBLOCK, ubus_socket, NULL);