Overwrite PID file if it exists

This commit is contained in:
ritt 2020-04-01 11:55:02 +02:00
parent dd35f04ec8
commit 80633bac29

View File

@ -29714,14 +29714,9 @@ void server_loop(void) {
/* check if file exists */ /* check if file exists */
if (stat(pidfile, &finfo) >= 0) { if (stat(pidfile, &finfo) >= 0) {
eprintf("File \"%s\" exists, using \"%s.%d\" instead.\n", pidfile, pidfile, elog_tcp_port); /* if it exists remove it */
sprintf(pidfile + strlen(pidfile), ".%d", elog_tcp_port); eprintf("File \"%s\" exists, overwriting it.\n", pidfile);
remove(pidfile);
/* check again for the new name */
if (stat(pidfile, &finfo) >= 0) {
/* never overwrite a file */
eprintf("Refuse to overwrite existing file \"%s\".\n", pidfile);
}
} }
fd = open(pidfile, O_CREAT | O_RDWR, 0644); fd = open(pidfile, O_CREAT | O_RDWR, 0644);