Skip site navigation (1) Skip section navigation (2)

Re: Reporting hba lines

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reporting hba lines
Date: 2012-06-29 14:39:53
Message-ID: 23650.1340980793@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Magnus Hagander <magnus(at)hagander(dot)net> writes:
> Turned out to be a bit more work than I thought, since the current
> parser reads pg_hba byte by byte, and not line by line. So I had to
> change that. See attached, seems reasonable?

A couple of comments:

* In some places you have "if ((c = *(*lineptr)++) != '\0')" and in other
places just "if ((c = *(*lineptr)++))".  This should be consistent (and
personally I prefer the first way).

* I'm not sure that this conversion is right:

! 	if (c != EOF)
! 		ungetc(c, fp);
---
! 	if (c != '\0')
! 		(*lineptr)--;

In the file case, it's impossible to push back EOF, and unnecessary
since another getc will produce EOF again anyway.  In the string case,
though, I think you might need to decrement the lineptr unconditionally,
else next call will run off the end of the string no?

* This bit seems a bit ugly, and not Windows-aware either:

! 						/* We don't store the trailing newline */
! 						if (rawline[strlen(rawline)-1] == '\n')
! 							rawline[strlen(rawline)-1] = '\0';
!

It might be better to strip trailing \n and \r from the line immediately
upon read, rather than here.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Kohei KaiGaiDate: 2012-06-29 14:44:32
Subject: Re: [v9.3] Extra Daemons (Re: elegant and effective way for running jobs inside a database)
Previous:From: Boszormenyi ZoltanDate: 2012-06-29 14:28:34
Subject: Re: [v9.3] Extra Daemons (Re: elegant and effective way for running jobs inside a database)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group