+ if (control_block.background)
+ {
+ switch (fork())
+ {
+ case 0:
+ break;
+ case -1:
+ return 1;
+ default:
+ _exit(0);
+ }
+
+ if (setsid() < 0)
+ return 1;
+
+ close(0);
+ close(1);
+ close(2);
+ open("/dev/null",O_RDWR);
+ dup(0); dup(0);
+ }
+ if (!pListener && *control_block.default_listen)
+ add_listener(control_block.default_listen,
+ control_block.default_proto);
+
+ if (!pListener)
+ return 1;
+
+ if (*control_block.pid_fname)
+ {
+ FILE *f = fopen(control_block.pid_fname, "w");
+ if (!f)
+ {
+ yaz_log(LOG_FATAL|LOG_ERRNO, "Couldn't create %s",
+ control_block.pid_fname);
+ exit(0);
+ }
+ fprintf(f, "%ld", (long) getpid());
+ fclose(f);
+ }
+