
 Hi,

 I tried compile some program with latest CVS libpq:

 gcc -O2 -O2 -g -pipe -march=i386 -mcpu=i686 -I/usr/include/httpd
 -Wall -I/usr/lib/postgresql/include -DLIBAPMOM_FUNCALL=1 -Wall
 -Wmissing-prototypes -Wmissing-declarations `xml2-config --cflags`
 `Wand-config --cppflags` -o jsn-importer main.o file.o db.o md5.o
 -L/usr/lib/postgresql/lib -lpq `xml2-config --libs` -lMagick -lWand
 
 /usr/lib/postgresql/lib/libpq.so: undefined reference to `get_home_path'
 
 collect2: ld returned 1 exit status
 make: *** [jsn-importer] Error 1
 

 It looks like port/path.c (libpgport) isn't compiled in PostgreSQL client libs,
 but the get_home_path() is used there. 

    Karel

-- 
 Karel Zak  <zakkr@zf.jcu.cz>
 http://home.zf.jcu.cz/~zakkr/

Wed, 18 Aug 2004 15:42:05 +0200
Karel Zak <zakkr@zf.jcu.cz>
8.0 libpq: missing get_home_path()
Karel Zak <zakkr@zf.jcu.cz> writes:
>  I tried compile some program with latest CVS libpq:

>  gcc -O2 -O2 -g -pipe -march=i386 -mcpu=i686 -I/usr/include/httpd
>  -Wall -I/usr/lib/postgresql/include -DLIBAPMOM_FUNCALL=1 -Wall
>  -Wmissing-prototypes -Wmissing-declarations `xml2-config --cflags`
>  `Wand-config --cppflags` -o jsn-importer main.o file.o db.o md5.o
>  -L/usr/lib/postgresql/lib -lpq `xml2-config --libs` -lMagick -lWand
 
>  /usr/lib/postgresql/lib/libpq.so: undefined reference to `get_home_path'

There's another problem here, which is that pulling port/path.c into
libpq to fix this will pollute application namespace with a whole bunch
of global symbols that don't use a PQ or pq prefix.

			regards, tom lane

Wed, 18 Aug 2004 13:02:55 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: 8.0 libpq: missing get_home_path() 
Tom Lane wrote:
> Karel Zak <zakkr@zf.jcu.cz> writes:
> >  I tried compile some program with latest CVS libpq:
> 
> >  gcc -O2 -O2 -g -pipe -march=i386 -mcpu=i686 -I/usr/include/httpd
> >  -Wall -I/usr/lib/postgresql/include -DLIBAPMOM_FUNCALL=1 -Wall
> >  -Wmissing-prototypes -Wmissing-declarations `xml2-config --cflags`
> >  `Wand-config --cppflags` -o jsn-importer main.o file.o db.o md5.o
> >  -L/usr/lib/postgresql/lib -lpq `xml2-config --libs` -lMagick -lWand
>  
> >  /usr/lib/postgresql/lib/libpq.so: undefined reference to `get_home_path'
> 
> There's another problem here, which is that pulling port/path.c into
> libpq to fix this will pollute application namespace with a whole bunch
> of global symbols that don't use a PQ or pq prefix.

Yea, I am seeing that now too.  My guess is that I am going to have to
go with a macro for get_home_path like I did for is_absolute_path.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Wed, 18 Aug 2004 13:08:35 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: 8.0 libpq: missing get_home_path()
Bruce Momjian wrote:
> Tom Lane wrote:
> > Karel Zak <zakkr@zf.jcu.cz> writes:
> > >  I tried compile some program with latest CVS libpq:
> > 
> > >  gcc -O2 -O2 -g -pipe -march=i386 -mcpu=i686 -I/usr/include/httpd
> > >  -Wall -I/usr/lib/postgresql/include -DLIBAPMOM_FUNCALL=1 -Wall
> > >  -Wmissing-prototypes -Wmissing-declarations `xml2-config --cflags`
> > >  `Wand-config --cppflags` -o jsn-importer main.o file.o db.o md5.o
> > >  -L/usr/lib/postgresql/lib -lpq `xml2-config --libs` -lMagick -lWand
> >  
> > >  /usr/lib/postgresql/lib/libpq.so: undefined reference to `get_home_path'
> > 
> > There's another problem here, which is that pulling port/path.c into
> > libpq to fix this will pollute application namespace with a whole bunch
> > of global symbols that don't use a PQ or pq prefix.
> 
> Yea, I am seeing that now too.  My guess is that I am going to have to
> go with a macro for get_home_path like I did for is_absolute_path.

I need to call canonicalize_path() in the macro.  That kills the macro
idea.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Wed, 18 Aug 2004 13:17:44 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: 8.0 libpq: missing get_home_path()
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> I need to call canonicalize_path() in the macro.

There is only one use of get_home_path in libpq.  Lose it and do
a direct getenv(HOMEDIR).  You do not really need to do a
canonicalize_path there; it'd be sufficient to insert the appropriate
directory separator ('/' or '\') when forming pgpassfile just below.

			regards, tom lane

Wed, 18 Aug 2004 13:27:10 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: 8.0 libpq: missing get_home_path() 
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I need to call canonicalize_path() in the macro.
> 
> There is only one use of get_home_path in libpq.  Lose it and do
> a direct getenv(HOMEDIR).  You do not really need to do a
> canonicalize_path there; it'd be sufficient to insert the appropriate
> directory separator ('/' or '\') when forming pgpassfile just below.

OK, sounds like a plan. I will add a comment about its purpose.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Wed, 18 Aug 2004 14:35:20 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: 8.0 libpq: missing get_home_path()
OK, patch attached and applied.  I also updated the docs.

---------------------------------------------------------------------------

Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I need to call canonicalize_path() in the macro.
> 
> There is only one use of get_home_path in libpq.  Lose it and do
> a direct getenv(HOMEDIR).  You do not really need to do a
> canonicalize_path there; it'd be sufficient to insert the appropriate
> directory separator ('/' or '\') when forming pgpassfile just below.
> 
> 			regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.160
diff -c -c -r1.160 libpq.sgml
*** doc/src/sgml/libpq.sgml	17 Aug 2004 16:54:46 -0000	1.160
--- doc/src/sgml/libpq.sgml	18 Aug 2004 23:54:05 -0000
***************
*** 136,142 ****
        likely to fail if <application>libpq</application> is passed a host name
        that is not the name of the machine at <literal>hostaddr</>.)  Also,
        <literal>host</> rather than <literal>hostaddr</> is used to identify
!       the connection in <filename>$HOME/.pgpass</>.
       </para>
       <para>
        Without either a host name or host address,
--- 136,143 ----
        likely to fail if <application>libpq</application> is passed a host name
        that is not the name of the machine at <literal>hostaddr</>.)  Also,
        <literal>host</> rather than <literal>hostaddr</> is used to identify
!       the connection in <filename>$HOME/.pgpass</> (or 
!       <filename>%USERPROFILE%/.pgpass</> on Win32).
       </para>
       <para>
        Without either a host name or host address,
Index: src/interfaces/libpq/fe-connect.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.281
diff -c -c -r1.281 fe-connect.c
*** src/interfaces/libpq/fe-connect.c	18 Aug 2004 02:59:11 -0000	1.281
--- src/interfaces/libpq/fe-connect.c	18 Aug 2004 23:54:19 -0000
***************
*** 3093,3099 ****
  {
  	FILE	   *fp;
  	char	   *pgpassfile;
! 	char	   home[MAXPGPATH];
  	struct stat stat_buf;
  
  #define LINELEN NAMEDATALEN*5
--- 3093,3099 ----
  {
  	FILE	   *fp;
  	char	   *pgpassfile;
! 	char	   *home;
  	struct stat stat_buf;
  
  #define LINELEN NAMEDATALEN*5
***************
*** 3111,3120 ****
  	if (port == NULL)
  		port = DEF_PGPORT_STR;
  
! 	/* Look for it in the home dir */
! 	if (!get_home_path(home))
  		return NULL;
! 
  	pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
  	if (!pgpassfile)
  	{
--- 3111,3123 ----
  	if (port == NULL)
  		port = DEF_PGPORT_STR;
  
! 	/*
! 	 *	Look for it in the home dir.
! 	 *	We don't use get_home_path() so we don't pull path.c into our library.
! 	 */
! 	if (!(home = getenv(HOMEDIR)))
  		return NULL;
! 	
  	pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
  	if (!pgpassfile)
  	{
***************
*** 3122,3128 ****
--- 3125,3135 ----
  		return NULL;
  	}
  
+ #ifndef WIN32
  	sprintf(pgpassfile, "%s/%s", home, PGPASSFILE);
+ #else
+ 	sprintf(pgpassfile, "%s\\%s", home, PGPASSFILE);
+ #endif
  
  	/* If password file cannot be opened, ignore it. */
  	if (stat(pgpassfile, &stat_buf) == -1)
Wed, 18 Aug 2004 20:01:19 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: [HACKERS] 8.0 libpq: missing get_home_path()
Bruce Momjian wrote:

> OK, patch attached and applied.  I also updated the docs.

Just a note for the docs:

"%USERPROFILE%/.pgpass" shall be not "%USERPROFILE%\.pgpass" ?


Regards
Gaetano Mendola

Thu, 19 Aug 2004 12:10:24 +0200
Gaetano Mendola <mendola@bigfoot.com>
Re: [HACKERS] 8.0 libpq: missing get_home_path()