summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/mako/csd-daemon.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/mako/csd-daemon.c b/tools/mako/csd-daemon.c
index 61d4f33..bf11b4c 100644
--- a/tools/mako/csd-daemon.c
+++ b/tools/mako/csd-daemon.c
@@ -367,7 +367,7 @@ out:
int main(int argc, char **argv)
{
char command[COMMAND_MAX];
- int fd, done = 0, ret = 0;
+ int child, fd, done = 0, ret = 0;
unsigned int i;
if (argc > 1) {
@@ -375,12 +375,30 @@ int main(int argc, char **argv)
return -1;
}
+ /* Make our socket readable by only us and the parent */
+ umask(0077);
+
if (init_lib() < 0)
return -1;
if (init_daemon() < 0)
return -1;
+ /* Basic setup was successful, so clients try to connect. Daemonize before
+ * making any actual library init, else nothing will work. */
+ if ((child = fork()) < 0) {
+ ERR("Could not daemonize");
+ return -1;
+ }
+
+ if (child > 0) {
+ /* This is the parent, exit */
+ return 0;
+ }
+
+ /* Child process, don't need to double-fork since in most cases we're not
+ * actually being run from a terminal. */
+
if ((ret = acdb_loader_init_ACDB()) < 0) {
ERR("Could not initialise acdb loader\n");
return ret;
@@ -431,8 +449,12 @@ next:
close(state.sockfd);
out:
+ /* Clearly deinitialisation is for the weak - this breaks the radio
+ * firmware until reboot! */
+#if 0
csd_client_deinit();
acdb_loader_deallocate_ACDB();
+#endif
return ret;
}