[Service]
#If necessary, Put Environment variable settings in a file like below
#ExecStartPre=/bin/bash -c "/bin/echo 'SDB_TRACE=all SDBD_LOG_PATH=/tmp' >> /tmp/.sdbdlog.conf"
-Type=simple
+Type=forking
PIDFile=/tmp/.sdbd.pid
RemainAfterExit=yes
ExecStart=/usr/sbin/sdbd
[Service]
User=sdk
Group=sdk
-Type=simple
+Type=forking
#location of SDBD log file
#If necessary, Put Environment variable settings in a file like below
#ExecStartPre=/bin/bash -c "/bin/echo 'SDB_TRACE=all SDBD_LOG_PATH=/tmp' >> /tmp/.sdbdlog.conf"
#DefaultDependencies=false
[Service]
-Type=simple
+Type=forking
#location of SDBD log file
#Environment=SDBD_LOG_PATH=/tmp
#If necessary, Put Environment variable settings in a file like below
sdb_close(fd);
}
+int daemonize(void) {
+
+ // set file creation mask to 0
+ umask(0);
+
+ switch (fork()) {
+ case -1:
+ return -1;
+ case 0:
+ break;
+ default:
+ _exit(0);
+ }
+#ifdef SDB_PIDPATH
+ char* tmppath = NULL;
+ tmppath = realpath(SDB_PIDPATH, NULL);
+ if (tmppath == NULL && errno == ENOENT) {
+ FILE *f = fopen(SDB_PIDPATH, "w");
+
+ if (f != NULL) {
+ fprintf(f, "%d\n", getpid());
+ fclose(f);
+ }
+ } else {
+ D("sdbd: %s file is existed. It might not work properly.\n", SDB_PIDPATH);
+ free(tmppath);
+ }
+#endif
+ if (setsid() == -1)
+ return -1;
+
+ if (chdir("/") < 0)
+ D("sdbd: unable to change working directory to /\n");
+
+ return 0;
+}
+
/* Constructs a local name of form tcp:port.
* target_str points to the target string, it's content will be overwritten.
* target_size is the capacity of the target string.
return EXIT_FAILURE;
}
+ if (daemonize() < 0)
+ fatal("daemonize() failed: errno:%d", errno);
+
D("Handling main()\n");
//sdbd will never die on emulator!