Re: Re: UUNET socket-file-location patch - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Re: UUNET socket-file-location patch
Date
Msg-id 200011220137.UAA18253@candle.pha.pa.us
Whole thread Raw
In response to Re: Re: UUNET socket-file-location patch  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> Peter Eisentraut <peter_e@gmx.net> writes:
> >>>> Should the parameter determine the directory or the full file name?  I'd
> >>>> go for the former, but it's not a strong case.
> >>
> >> Directory was what I had in mind too, but I'm not sure what Bruce
> >> actually did ...
>
> > I did whatever the patch did.  I believe it is the full path.  I believe
> > it is used here:
>
> > #define UNIXSOCK_PATH(sun,port,defpath) \
> >         ((defpath && defpath[0] != '\0') ? (strncpy((sun).sun_path,
> > defpath, sizeof((sun).sun_path)),
> > (sun).sun_path[sizeof((sun).sun_path)-1] = '\0') :
> > sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)))
>
> Hmm.  I think it would make more sense to make the parameter be just
> the directory, not the full path including filename --- for one thing,
> doing it like that renders the port-number parameter useless.  Why not
>
> #define UNIXSOCK_PATH(sun,port,defpath) \
>     snprintf((sun).sun_path, sizeof((sun).sun_path), "%s/.s.PGSQL.%d", \
>              (((defpath) && *(defpath) != '\0') ? (defpath) : "/tmp"), \
>              (port))
>
>             regards, tom lane
>

OK, here is the diff to make the socket file option specify just a
directory, not a full path.  Documentation changes were also made.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
? Makefile.custom
? GNUmakefile
? Makefile.global
? log
? crtags
? backend/postgres
? backend/catalog/global.description
? backend/catalog/global.bki
? backend/catalog/template1.bki
? backend/catalog/template1.description
? backend/port/Makefile
? bin/initdb/initdb
? bin/initlocation/initlocation
? bin/ipcclean/ipcclean
? bin/pg_config/pg_config
? bin/pg_ctl/pg_ctl
? bin/pg_dump/pg_dump
? bin/pg_dump/pg_restore
? bin/pg_dump/pg_dumpall
? bin/pg_id/pg_id
? bin/pg_passwd/pg_passwd
? bin/pgaccess/pgaccess
? bin/pgtclsh/Makefile.tkdefs
? bin/pgtclsh/Makefile.tcldefs
? bin/pgtclsh/pgtclsh
? bin/pgtclsh/pgtksh
? bin/psql/psql
? bin/scripts/createlang
? include/config.h
? include/stamp-h
? interfaces/ecpg/lib/libecpg.so.3.2.0
? interfaces/ecpg/preproc/ecpg
? interfaces/libpgeasy/libpgeasy.so.2.1
? interfaces/libpgtcl/libpgtcl.so.2.1
? interfaces/libpq/libpq.so.2.1
? interfaces/perl5/blib
? interfaces/perl5/Makefile
? interfaces/perl5/pm_to_blib
? interfaces/perl5/Pg.c
? interfaces/perl5/Pg.bs
? pl/plperl/blib
? pl/plperl/Makefile
? pl/plperl/pm_to_blib
? pl/plperl/SPI.c
? pl/plperl/plperl.bs
? pl/plpgsql/src/libplpgsql.so.1.0
? pl/tcl/Makefile.tcldefs
Index: include/libpq/pqcomm.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/libpq/pqcomm.h,v
retrieving revision 1.45
diff -c -r1.45 pqcomm.h
*** include/libpq/pqcomm.h    2000/11/15 18:36:06    1.45
--- include/libpq/pqcomm.h    2000/11/22 01:33:54
***************
*** 51,66 ****
  /* Configure the UNIX socket address for the well known port. */

  #if defined(SUN_LEN)
- #define UNIXSOCK_PATH(sun,port,defpath) \
-         ((defpath && defpath[0] != '\0') ? (strncpy((sun).sun_path, defpath, sizeof((sun).sun_path)),
(sun).sun_path[sizeof((sun).sun_path)-1]= '\0') : sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port))) 
  #define UNIXSOCK_LEN(sun) \
          (SUN_LEN(&(sun)))
  #else
- #define UNIXSOCK_PATH(sun,port,defpath) \
-         ((defpath && defpath[0] != '\0') ? (strncpy((sun).sun_path, defpath, sizeof((sun).sun_path)),
(sun).sun_path[sizeof((sun).sun_path)-1]= '\0') : sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port))) 
  #define UNIXSOCK_LEN(sun) \
          (strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
  #endif

  /*
   *        We do this because sun_len is in BSD's struct, while others don't.
--- 51,65 ----
  /* Configure the UNIX socket address for the well known port. */

  #if defined(SUN_LEN)
  #define UNIXSOCK_LEN(sun) \
          (SUN_LEN(&(sun)))
  #else
  #define UNIXSOCK_LEN(sun) \
          (strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
  #endif
+
+ #define UNIXSOCK_PATH(sun,port,defpath) \
+         (snprintf((sun).sun_path, UNIXSOCK_LEN(sun), "%s/.s.PGSQL.%d", (defpath && *(defpath) != '\0') ? (defpath) :
"/tmp",(port))) 

  /*
   *        We do this because sun_len is in BSD's struct, while others don't.

pgsql-hackers by date:

Previous
From: Don Baccus
Date:
Subject: RE: Crash during WAL recovery?
Next
From: Philip Warner
Date:
Subject: Re: Assert Failure with current CVS