- 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 (pidfile_open(pidfile) < 0) {
+ syslog(LOG_CRIT, "unable to write pidfile %s", pidfile);
+ return EXIT_FAILURE;