- * Go daemon (unless we specified at compile time that we didn't want this)
- * @param serve the first server of our configuration. If its port is zero,
- * then do not daemonize, because we're doing inetd then. This parameter
- * is only used to create a PID file of the form
- * /var/run/nbd-server.<port>.pid; it's not modified in any way.
- **/
-#if !defined(NODAEMON) && !defined(NOFORK)
-void daemonize(SERVER* serve) {
- FILE*pidf;
-
- if(serve && !(serve->port)) {
- return;
- }
- if(daemon(0,0)<0) {
- err("daemon");
- }
- if(!*pidftemplate) {
- if(serve) {
- strncpy(pidftemplate, "/var/run/server.%d.pid", 255);
- } else {
- strncpy(pidftemplate, "/var/run/server.pid", 255);
- }
- }
- snprintf(pidfname, 255, pidftemplate, serve ? serve->port : 0);
- pidf=fopen(pidfname, "w");
- if(pidf) {
- fprintf(pidf,"%d\n", (int)getpid());
- fclose(pidf);
- } else {
- perror("fopen");
- fprintf(stderr, "Not fatal; continuing");
- }
-}
-#else
-#define daemonize(serve)
-#endif /* !defined(NODAEMON) && !defined(NOFORK) */
-
-/*
- * Everything beyond this point (in the file) is run in non-daemon mode.
- * The stuff above daemonize() isn't.
- */
-
-void serve_err(SERVER* serve, const char* msg) G_GNUC_NORETURN {
- g_message("Export of %s on port %d failed:", serve->exportname,
- serve->port);
- err(msg);
-}
-
-/**