+ if (pidfile) {
+ FILE *fp = fopen(pidfile, "w");
+ if (!fp) {
+ die(EXIT_FAILURE, "couldn't create pidfile `%s': %s",
+ pidfile, strerror(errno));
+ }
+ fprintf(fp, "%lu\n", (unsigned long)getpid());
+ if (fflush(fp) || ferror(fp) || fclose(fp)) {
+ die(EXIT_FAILURE, "couldn't write pidfile `%s': %s",
+ pidfile, strerror(errno));
+ }
+ }