-for ac_header in crypt.h dld.h endian.h fp_class.h getopt.h ieeefp.h pwd.h sys/ipc.h sys/pstat.h sys/select.h sys/sem.h sys/socket.h sys/shm.h sys/un.h termios.h kernel/OS.h kernel/image.h SupportDefs.h
+
+for ac_header in crypt.h dld.h endian.h fp_class.h getopt.h ieeefp.h pwd.h sys/ipc.h sys/pstat.h sys/select.h sys/sem.h sys/socket.h sys/shm.h sys/un.h termios.h utime.h kernel/OS.h kernel/image.h SupportDefs.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
-for ac_func in cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync
+
+
+for ac_func in cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync utime utimes
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.232 2003/01/11 04:58:44 momjian Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.233 2003/01/25 05:19:45 tgl Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
##
dnl sys/socket.h is required by AC_FUNC_ACCEPT_ARGTYPES
-AC_CHECK_HEADERS([crypt.h dld.h endian.h fp_class.h getopt.h ieeefp.h pwd.h sys/ipc.h sys/pstat.h sys/select.h sys/sem.h sys/socket.h sys/shm.h sys/un.h termios.h kernel/OS.h kernel/image.h SupportDefs.h])
+AC_CHECK_HEADERS([crypt.h dld.h endian.h fp_class.h getopt.h ieeefp.h pwd.h sys/ipc.h sys/pstat.h sys/select.h sys/sem.h sys/socket.h sys/shm.h sys/un.h termios.h utime.h kernel/OS.h kernel/image.h SupportDefs.h])
# At least on IRIX, cpp test for netinet/tcp.h will fail unless
# netinet/in.h is included first.
# SunOS doesn't handle negative byte comparisons properly with +/- return
AC_FUNC_MEMCMP
-AC_CHECK_FUNCS([cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync])
+AC_CHECK_FUNCS([cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync utime utimes])
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.c,v 1.146 2003/01/14 22:52:57 momjian Exp $
+ * $Id: pqcomm.c,v 1.147 2003/01/25 05:19:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* StreamServerPort - Open postmaster's server port
* StreamConnection - Create new connection with client
* StreamClose - Close a client/backend connection
+ * TouchSocketFile - Protect socket file against /tmp cleaners
* pq_init - initialize libpq at backend startup
* pq_close - shutdown libpq at backend exit
*
#include <fcntl.h>
#include <grp.h>
#include <unistd.h>
-#include <sys/stat.h>
+#include <sys/file.h>
#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
#include <netdb.h>
#include <netinet/in.h>
#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#include <arpa/inet.h>
-#include <sys/file.h>
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#endif
#include "libpq/libpq.h"
#include "miscadmin.h"
static void pq_close(void);
#ifdef HAVE_UNIX_SOCKETS
-int Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName);
-int Setup_AF_UNIX(void);
+static int Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName);
+static int Setup_AF_UNIX(void);
#endif /* HAVE_UNIX_SOCKETS */
#ifdef HAVE_IPV6
* Shutdown routine for backend connection
* If a Unix socket is used for communication, explicitly close it.
*/
+#ifdef HAVE_UNIX_SOCKETS
static void
StreamDoUnlink(void)
{
Assert(sock_path[0]);
unlink(sock_path);
}
+#endif /* HAVE_UNIX_SOCKETS */
/*
* StreamServerPort -- open a sock stream "listening" port.
}
+
+#ifdef HAVE_UNIX_SOCKETS
+
/*
* Lock_AF_UNIX -- configure unix socket file path
*/
-
-#ifdef HAVE_UNIX_SOCKETS
-int
+static int
Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName)
{
SockAddr saddr; /* just used to get socket path */
/*
* Setup_AF_UNIX -- configure unix socket permissions
*/
-int
+static int
Setup_AF_UNIX(void)
{
/* Arrange to unlink the socket file at exit */
}
return STATUS_OK;
}
+
#endif /* HAVE_UNIX_SOCKETS */
close(sock);
}
+/*
+ * TouchSocketFile -- mark socket file as recently accessed
+ *
+ * This routine should be called every so often to ensure that the socket
+ * file has a recent mod date (ordinary operations on sockets usually won't
+ * change the mod date). That saves it from being removed by
+ * overenthusiastic /tmp-directory-cleaner daemons. (Another reason we should
+ * never have put the socket file in /tmp...)
+ */
+void
+TouchSocketFile(void)
+{
+ /* Do nothing if we did not create a socket... */
+ if (sock_path[0] != '\0')
+ {
+ /*
+ * utime() is POSIX standard, utimes() is a common alternative.
+ * If we have neither, there's no way to affect the mod or access
+ * time of the socket :-(
+ *
+ * In either path, we ignore errors; there's no point in complaining.
+ */
+#ifdef HAVE_UTIME
+ utime(sock_path, NULL);
+#else /* !HAVE_UTIME */
+#ifdef HAVE_UTIMES
+ utimes(sock_path, NULL);
+#endif /* HAVE_UTIMES */
+#endif /* HAVE_UTIME */
+ }
+}
+
/* --------------------------------
* Low-level I/O routines begin here.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.305 2003/01/16 00:26:44 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.306 2003/01/25 05:19:46 tgl Exp $
*
* NOTES
*
* do other actions that should happen every now and then on no
* particular schedule. Such as...
*/
+ TouchSocketFile();
TouchSocketLockFile();
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.98 2002/12/05 04:04:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.99 2003/01/25 05:19:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/param.h>
#include <signal.h>
-#include <sys/stat.h>
#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <grp.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#endif
#include "catalog/catname.h"
#include "catalog/pg_shadow.h"
}
/*
- * Re-read the socket lock file. This should be called every so often
- * to ensure that the lock file has a recent access date. That saves it
+ * TouchSocketLockFile -- mark socket lock file as recently accessed
+ *
+ * This routine should be called every so often to ensure that the lock file
+ * has a recent mod or access date. That saves it
* from being removed by overenthusiastic /tmp-directory-cleaner daemons.
* (Another reason we should never have put the socket file in /tmp...)
*/
void
TouchSocketLockFile(void)
{
- int fd;
- char buffer[1];
-
/* Do nothing if we did not create a socket... */
if (socketLockFile[0] != '\0')
{
- /* XXX any need to complain about errors here? */
+ /*
+ * utime() is POSIX standard, utimes() is a common alternative;
+ * if we have neither, fall back to actually reading the file
+ * (which only sets the access time not mod time, but that should
+ * be enough in most cases). In all paths, we ignore errors.
+ */
+#ifdef HAVE_UTIME
+ utime(socketLockFile, NULL);
+#else /* !HAVE_UTIME */
+#ifdef HAVE_UTIMES
+ utimes(socketLockFile, NULL);
+#else /* !HAVE_UTIMES */
+ int fd;
+ char buffer[1];
+
fd = open(socketLockFile, O_RDONLY | PG_BINARY, 0);
if (fd >= 0)
{
read(fd, buffer, sizeof(buffer));
close(fd);
}
+#endif /* HAVE_UTIMES */
+#endif /* HAVE_UTIME */
}
}
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq.h,v 1.55 2003/01/06 03:18:27 momjian Exp $
+ * $Id: libpq.h,v 1.56 2003/01/25 05:19:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
unsigned short portNumber, char *unixSocketName, int *fdP);
extern int StreamConnection(int server_fd, Port *port);
extern void StreamClose(int sock);
+extern void TouchSocketFile(void);
extern void pq_init(void);
extern int pq_getbytes(char *s, size_t len);
extern int pq_getstring(StringInfo s, int maxlen);
* or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your
* changes will be overwritten the next time you run configure.
*
- * $Id: pg_config.h.in,v 1.37 2003/01/06 06:07:20 momjian Exp $
+ * $Id: pg_config.h.in,v 1.38 2003/01/25 05:19:47 tgl Exp $
*/
#ifndef PG_CONFIG_H
/* Set to 1 if you have <termios.h> */
#undef HAVE_TERMIOS_H
+/* Set to 1 if you have <utime.h> */
+#undef HAVE_UTIME_H
+
/* Set to 1 if you have <sys/pstat.h> */
#undef HAVE_SYS_PSTAT_H
/* Define if you have fdatasync() */
#undef HAVE_FDATASYNC
+/* Define if you have utime() */
+#undef HAVE_UTIME
+
+/* Define if you have utimes() */
+#undef HAVE_UTIMES
+
/* Define if the standard header unistd.h declares fdatasync() */
#undef HAVE_DECL_FDATASYNC