- return main_loop(srs, argv[optind], port_enc, port_dec);
+ if (pidfile) {
+ f = fopen(pidfile, "w");
+ if (!f) {
+ syslog(LOG_CRIT, "unable to write pidfile %s", pidfile);
+ }
+ fprintf(f, "%d\n", getpid());
+ fflush(f);
+ }
+ if (daemon_detach() < 0) {
+ syslog(LOG_CRIT, "unable to fork");
+ return EXIT_FAILURE;
+ }
+ if (f) {
+ rewind(f);
+ ftruncate(fileno(f), 0);
+ fprintf(f, "%d\n", getpid());
+ fclose(f);
+ f = NULL;
+ }
+ res = main_loop(srs, argv[optind], port_enc, port_dec);
+ if (pidfile) {
+ unlink(pidfile);
+ }
+ return res;