Re: [HACKERS] New pg_ctl has retrogressed in error messages

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] New pg_ctl has retrogressed in error messages
Date: 2004-06-01 00:46:17
Message-ID: 13381.1086050777@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> I also changed all the pid variables to use pid_t.

Good, but ...

> ! fscanf(pidf, "%u", &pid);

this code will fail rather horribly if sizeof(pid_t) != sizeof(int).
Even more to the point, I believe a standalone backend will put
the negative of its PID into the file, and the revised code will fail
to parse that at all.

I think the safest code would be like

long tmp;

fscanf(pidf, "%ld", &tmp);
if (tmp < 0)
{
tmp = -tmp;
// do anything else needed for backend case
}
pid = (pid_t) tmp;

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Claudio Natoli 2004-06-01 00:55:19 Re: Can't detect time zone
Previous Message Tom Lane 2004-06-01 00:33:55 Re: CVS tip problems

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Dunstan 2004-06-01 01:07:07 Re: [HACKERS] New pg_ctl has retrogressed in error messages
Previous Message Tom Lane 2004-06-01 00:33:55 Re: CVS tip problems