summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorArun Raghavan <arun.raghavan@collabora.co.uk>2013-08-21 00:20:51 +0530
committerArun Raghavan <arun.raghavan@collabora.co.uk>2013-08-21 00:20:51 +0530
commitfe6aaf3e82305127ad1528ada1f48f87b7643b33 (patch)
tree59ebebb4bc7d784b5a08266f74115836bc438c21 /tools
parent9dc9edc72518df5805dd4b16dd0e2cdb29ec6f7b (diff)
mako: Make csd-daemon actually daemonize
Diffstat (limited to 'tools')
-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;
}