Re: [PATCHES] pstrndup()

2004-03-22 Thread Bruce Momjian
Karel Zak wrote:
 On Sun, Mar 21, 2004 at 11:45:18PM -0500, Tom Lane wrote:
  Bruce Momjian [EMAIL PROTECTED] writes:
   Karel, do you plan to use pstrndup for some purpose?  I assume so.
 
  I   thinkPostgreSQL   should   supports   basicoperation   with
  allocation/strings if  it's open for  users' C functions and  we expect
  our own memory system usage.
 
  I am not familiar with strndup.  If the spec is like strncpy, I would
  vote against including it ... strncpy is so broken that we had to invent
  our own variant ...
 
  POSIX strncpy()  is different,  a result from  strncpy needn't  be zero
  terminated. You're right it's horrible function.
  
  The result of  strndup() is always zero terminated. It's  more safe and
  strndup() is  binary safe because  it doesn't check something  in input
  string. The pstrndup() is based on PostgreSQL memory managment.

Can you find places to use this function our backend?  Seems that should
be part of the patch.

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

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] listening addresses

2004-03-22 Thread Andrew Dunstan
Tom Lane wrote:

Please revise, and update the docs too.

 

Second attempt attached. The fatal message now reads no configured 
listening socket available, but I am not wedded to the wording. I also 
was not sure how to mark up * in the docs.

cheers

andrew
Index: doc/src/sgml/runtime.sgml
===
RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/runtime.sgml,v
retrieving revision 1.251
diff -c -r1.251 runtime.sgml
*** doc/src/sgml/runtime.sgml   15 Mar 2004 17:57:51 -  1.251
--- doc/src/sgml/runtime.sgml   22 Mar 2004 17:26:36 -
***
*** 571,588 
  
   variablelist
   
-  varlistentry id=guc-tcpip-socket xreflabel=tcpip_socket
-   termvarnametcpip_socket/varname (typeboolean/type)/term
-   listitem
-para
- If this is true, then the server will accept TCP/IP 
connections.indextermprimaryTCP/IP//
- Otherwise only local Unix domain socket connections are
- accepted. It is off by default. This option can only be set at
- server start.
-/para
-   /listitem
-  /varlistentry
-   
   varlistentry id=guc-max-connections xreflabel=max_connections
termvarnamemax_connections/varname (typeinteger/type)/term
listitem
--- 571,576 
***
*** 702,717 
/listitem
   /varlistentry
  
!  varlistentry id=guc-virtual-host xreflabel=virtual_host
!   termvarnamevirtual_host/varname (typestring/type)/term
listitem
 para
! Specifies the IP address(es) on which the server is
! to listen for connections from client applications.  If specified,
! it takes the form of a space-separated list of host names and/or
! numeric IP addresses.  If the list is empty, the server listens
! on all available addresses (including
! systemitem class=systemnamelocalhost/).
 /para
/listitem
   /varlistentry
--- 690,707 
/listitem
   /varlistentry
  
!  varlistentry id=guc-listen-addresses xreflabel=listen_addresses
!   termvarnamelisten_addresses/varname (typestring/type)/term
listitem
 para
!Specifies the IP address(es) on which the server is
!to listen for connections from client applications.  
!The default is systemitem class=systemnamelocalhost/.
!The item takes the form of a space-separated list of host names and/or
!numeric IP addresses.  The special entry * corresponds to all
!available IP interfaces.
!If the list is empty, the server  does not 
!listen on any IP interface at all.
 /para
/listitem
   /varlistentry
***
*** 3009,3019 
 /row
 row
  entryoption-h replaceablex/replaceable/option/entry
! entryliteralvirtual_host = replaceablex/replaceable//entry
 /row
 row
  entryoption-i/option/entry
! entryliteraltcpip_socket = on//entry
 /row
 row
  entryoption-k replaceablex/replaceable/option/entry
--- 2999,3009 
 /row
 row
  entryoption-h replaceablex/replaceable/option/entry
! entryliterallisten_addresses = replaceablex/replaceable//entry
 /row
 row
  entryoption-i/option/entry
! entryliterallisten_addresses = '*'//entry
 /row
 row
  entryoption-k replaceablex/replaceable/option/entry
Index: src/backend/postmaster/postmaster.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v
retrieving revision 1.375
diff -c -r1.375 postmaster.c
*** src/backend/postmaster/postmaster.c 15 Mar 2004 16:18:42 -  1.375
--- src/backend/postmaster/postmaster.c 22 Mar 2004 17:26:38 -
***
*** 149,155 
  /* The socket number we are listening for connections on */
  int   PostPortNumber;
  char *UnixSocketDir;
! char *VirtualHost;
  
  /*
   * MaxBackends is the limit on the number of backends we can start.
--- 149,155 
  /* The socket number we are listening for connections on */
  int   PostPortNumber;
  char *UnixSocketDir;
! char *ListenAddresses;
  
  /*
   * MaxBackends is the limit on the number of backends we can start.
***
*** 202,208 
  static intSendStop = false;
  
  /* still more option variables */
- bool  NetServer = false;  /* listen on TCP/IP */
  bool  EnableSSL = false;
  bool  SilentMode = false; /* silent mode (-S) */
  
--- 202,207 
***
*** 513,522 
SetConfigOption(fsync, false, PGC_POSTMASTER, 
PGC_S_ARGV);
break;
case 'h':
!   SetConfigOption(virtual_host, optarg, 

[PATCHES] Initial eventlog support on win32

2004-03-22 Thread Magnus Hagander
This patch adds initial eventlog support on win32. It's good enough for
most purposes, but we will probably want a specific message DLL later to
format the messages nicer.

The patch mimcs the syslog handling in most cases. It also hijacks the
syslog guc variable. Since syslog is not available on win32, it's
meaning is redefined as eventlog.  So syslog=1 means eventlog+stdout,
syslog=2 means just eventlog.

For reviews and application to head if nobody objects.

//Magnus
 
 eventlog.patch 


eventlog.patch
Description: eventlog.patch

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] Initial eventlog support on win32

2004-03-22 Thread Andrew Dunstan
Magnus Hagander wrote:

This patch adds initial eventlog support on win32. It's good enough for
most purposes, but we will probably want a specific message DLL later to
format the messages nicer.
 

I'm extremely happy to see this being done - it's a must-have for WIN32, 
I think.

The patch mimcs the syslog handling in most cases. It also hijacks the
syslog guc variable. Since syslog is not available on win32, it's
meaning is redefined as eventlog.  So syslog=1 means eventlog+stdout,
syslog=2 means just eventlog.
 

I'm less happy about this. In fact the 0 | 1 | 2 for syslog is very 
hokey anyway. What is more, it is not inconceivable that someone would 
run syslogd on a Windows host, especially if it pointed to a remote 
syslog. Such things exist, as a quick Google search will demonstrate. 
(I'm not sure if we have any API available on WIndows to support it, but 
that's another question.)

I would rather see the setting cleaned up and allow zero or more of 
stdout, syslog, and eventlog (and it should probably be called 
log_destination or some such instead of syslog).

cheers

andrew





---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [PATCHES] Patch for select and APC on win32

2004-03-22 Thread Claudio Natoli
 

 Here's a patch implementing the thread method to workaround the bug
 with socket calls in signal handlers. See details in mail to
 pgsql-hackers-win32 a couple of minutes ago.

Looks ok, but wouldn't it be better placed in pgstat.c?

My $0.02,
Claudio

--- 
Certain disclaimers and policies apply to all email sent from Memetrics.
For the full text of these disclaimers and policies see 
a
href=http://www.memetrics.com/emailpolicy.html;http://www.memetrics.com/em
ailpolicy.html/a

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] [HACKERS] listening addresses

2004-03-22 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 A small problem with it was reported to me a couple of days ago - 
 user had firewalled off all IP6 traffic. The stats collector happily 
 bound and connected to the socket, but all the packets fell in the 
 bit bucket. They found it quite hard to diagnose the problem.

 Revised patch attached. I think this is about as much trouble as this 
 problem is worth ;-)

I thought the messages were a bit sloppy, which made the patch much less
useful than it should be: we are testing for a very specific failure
mode and we can give a very specific message.  Patch as-applied is
attached.

I don't have any real convenient way to set up a situation where this
failure can actually occur.  Anyone want to verify that the patch
acts as intended?

regards, tom lane

*** src/backend/postmaster/pgstat.c.origMon Mar 15 15:01:57 2004
--- src/backend/postmaster/pgstat.c Mon Mar 22 18:55:29 2004
***
*** 191,196 
--- 191,202 
   *addr,
hints;
int ret;
+   fd_set  rset;
+   struct timeval tv;
+   chartest_byte;
+   int sel_res;
+ 
+ #define TESTBYTEVAL ((char) 199)
  
/*
 * Force start of collector daemon if something to collect
***
*** 303,308 
--- 309,393 
ereport(LOG,
(errcode_for_socket_access(),
 errmsg(could not connect socket for 
statistics collector: %m)));
+   closesocket(pgStatSock);
+   pgStatSock = -1;
+   continue;
+   }
+ 
+   /*
+* Try to send and receive a one-byte test message on the socket.
+* This is to catch situations where the socket can be created but
+* will not actually pass data (for instance, because kernel packet
+* filtering rules prevent it).
+*/
+   test_byte = TESTBYTEVAL;
+   if (send(pgStatSock, test_byte, 1, 0) != 1)
+   {
+   ereport(LOG,
+   (errcode_for_socket_access(),
+errmsg(could not send test message on socket 
for statistics collector: %m)));
+   closesocket(pgStatSock);
+   pgStatSock = -1;
+   continue;
+   }
+ 
+   /*
+* There could possibly be a little delay before the message can be
+* received.  We arbitrarily allow up to half a second before deciding
+* it's broken.
+*/
+   for (;;)/* need a loop to handle EINTR 
*/
+   {
+   FD_ZERO(rset);
+   FD_SET(pgStatSock, rset);
+   tv.tv_sec = 0;
+   tv.tv_usec = 50;
+   sel_res = select(pgStatSock+1, rset, NULL, NULL, tv);
+   if (sel_res = 0 || errno != EINTR)
+   break;
+   }
+   if (sel_res  0)
+   {
+   ereport(LOG,
+   (errcode_for_socket_access(),
+errmsg(select() failed in statistics 
collector: %m)));
+   closesocket(pgStatSock);
+   pgStatSock = -1;
+   continue;
+   }
+   if (sel_res == 0 || !FD_ISSET(pgStatSock, rset))
+   {
+   /*
+* This is the case we actually think is likely, so take pains 
to
+* give a specific message for it.
+*
+* errno will not be set meaningfully here, so don't use it.
+*/
+   ereport(LOG,
+   (ERRCODE_CONNECTION_FAILURE,
+errmsg(test message did not get through on 
socket for statistics collector)));
+   closesocket(pgStatSock);
+   pgStatSock = -1;
+   continue;
+   }
+ 
+   test_byte++;/* just make sure variable is changed 
*/
+ 
+   if (recv(pgStatSock, test_byte, 1, 0) != 1)
+   {
+   ereport(LOG,
+   (errcode_for_socket_access(),
+errmsg(could not receive test message on 
socket for statistics collector: %m)));
+   closesocket(pgStatSock);
+   pgStatSock = -1;
+   

Re: [PATCHES] listening addresses

2004-03-22 Thread Tom Lane
Andrew Dunstan [EMAIL PROTECTED] writes:
 Second attempt attached. The fatal message now reads no configured 
 listening socket available, but I am not wedded to the wording. I also 
 was not sure how to mark up * in the docs.

Reviewed and committed.

I found a bunch more references in the docs to the postmaster -i and -h
switches, and I'm far from sure we've hit them all yet; anyone want to
make another pass to check?

Code-wise it looked great, except that you need to remember to cast the
argument of isspace() to unsigned char; on most machines with signed
chars, failing to do this causes big trouble for 8th-bit-set characters.

I went with no socket configured to listen on for the failure message,
but am not wedded to that either.

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[PATCHES] Fix for fseeko.c and pg_dump -Ft

2004-03-22 Thread Bruce Momjian
I just fixed a problem with our port/fseeko.c code.

I added an fflush() so the FILE buffer would update the file descriptor
so stat() gets proper size in fseeko.c.

This fixes a problem with pg_dump tar backups.  Only happens on
platforms that use our port/fseeko.c, which is currently BSD/OS and
NetBSD.  The error would be:

$ pg_dump -Ft test /dev/null
pg_dump: [tar archiver] actual file length (2171) does not match
expected (2171)

Backpatched to 7.4.X too.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/port/fseeko.c
===
RCS file: /cvsroot/pgsql-server/src/port/fseeko.c,v
retrieving revision 1.13
diff -c -c -r1.13 fseeko.c
*** src/port/fseeko.c   29 Nov 2003 19:52:13 -  1.13
--- src/port/fseeko.c   23 Mar 2004 05:24:52 -
***
*** 68,73 
--- 68,74 
  #ifdef bsdi
flockfile(stream);
  #endif
+   fflush(stream); /* force writes to fd for stat() */
if (fstat(fileno(stream), filestat) != 0)
goto failure;
floc = filestat.st_size;

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] charset / postmaster doc improv

2004-03-22 Thread Neil Conway
On 22-Mar-04, at 11:54 PM, Tom Lane wrote:
... setting the listen_addresses seems a bit too brief to me; in a
medium that doesn't mark up the crossref at all, it'd seem 
disconnected.
I'd have written at least the xref linkend=guc-listen-addresses
configuration parameter.
Indeed, that's a typo. Good catch -- thanks! I've committed a fix for 
this to CVS.

Cheers,

Neil

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match