X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=main-srsd.c;h=79f9e19af9674a8950f93b0d5598328ad47faa39;hb=5583c0d0fb57a40dd1b35d9556877ed6848192ac;hp=bcf9fea0f148bd5d6608eec0f77f6ac07446c9fc;hpb=8504d5165f2257fe7d3899c219caaad8b8964705;p=apps%2Fpfixtools.git diff --git a/main-srsd.c b/main-srsd.c index bcf9fea..79f9e19 100644 --- a/main-srsd.c +++ b/main-srsd.c @@ -366,7 +366,6 @@ int main(int argc, char *argv[]) int port_dec = DEFAULT_DECODER_PORT; const char *pidfile = NULL; - FILE *f = NULL; int res; srs_t *srs; @@ -400,13 +399,9 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - 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; } if (!unsafe && drop_privileges(RUNAS_USER, RUNAS_GROUP) < 0) { @@ -419,19 +414,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - if (f) { - rewind(f); - ftruncate(fileno(f), 0); - fprintf(f, "%d\n", getpid()); - fflush(f); - } + pidfile_refresh(); res = main_loop(srs, argv[optind], port_enc, port_dec); - if (f) { - rewind(f); - ftruncate(fileno(f), 0); - fclose(f); - f = NULL; - } syslog(LOG_INFO, "Stopping..."); return res; }