[pgpool-hackers: 4417] pgpool4.2 - zero symbol in PID file

Igor Yurchenko harry.urcen at gmail.com
Tue Jan 23 20:03:30 JST 2024


Hi guys...

I've discovered that pgpool (at least version 4.2.6) for some unclear
reason writes a C-string terminal zero symbol to pid file with pid number.
It's uncommon approach and it cause raising an exception on standard python
code used for getting PID from a file:
...
with open('/var/run/pgpool.pid') as f:
    pid = int(f.readline().strip())
...
It works great for Postgresql. And I have no idea why it shouldn't work for
pgpool-II.
I've prepared a patch of the issue. Feel free to take it for your purpose
if you decide it's ok for you:

*** src/main/main.c.orig 2021-11-18 03:21:14.000000000 +0000
--- src/main/main.c 2024-01-22 10:53:02.513175737 +0000
*************** write_pid_file(void)
*** 671,677 ****
  errdetail("%m")));
  }
  snprintf(pidbuf, sizeof(pidbuf), "%d", (int) getpid());
! if (write(fd, pidbuf, strlen(pidbuf) + 1) == -1)
  {
  close(fd);
  pfree(pid_file);
--- 671,677 ----
  errdetail("%m")));
  }
  snprintf(pidbuf, sizeof(pidbuf), "%d", (int) getpid());
! if (write(fd, pidbuf, strlen(pidbuf)) == -1)
  {
  close(fd);
  pfree(pid_file);

BR
Igor Yurchenko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pgpool.net/pipermail/pgpool-hackers/attachments/20240123/75966945/attachment.htm>


More information about the pgpool-hackers mailing list