Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15ab7a8

Browse files
committed
Where available, use utime() or utimes() to update the file mod time
of the socket file and socket lock file; this should prevent both of themfrom being removed by even the stupidest varieties of /tmp-cleaningscript. Per suggestion from Giles Lean.
1 parent80727ce commit15ab7a8

File tree

7 files changed

+99
-25
lines changed

7 files changed

+99
-25
lines changed

‎configure

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6887,7 +6887,8 @@ done
68876887
68886888
68896889
6890-
forac_headerin 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
6890+
6891+
forac_headerin 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
68916892
do
68926893
as_ac_Header=`echo"ac_cv_header_$ac_header"|$as_tr_sh`
68936894
ifeval"test\"\${$as_ac_Header+set}\" = set";then
@@ -9819,7 +9820,9 @@ test $ac_cv_func_memcmp_working = no && LIBOBJS="$LIBOBJS memcmp.$ac_objext"
98199820
98209821
98219822
9822-
forac_funcin cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync
9823+
9824+
9825+
forac_funcin cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync utime utimes
98239826
do
98249827
as_ac_var=`echo"ac_cv_func_$ac_func"|$as_tr_sh`
98259828
echo"$as_me:$LINENO: checking for$ac_func">&5

‎configure.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.232 2003/01/11 04:58:44 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.233 2003/01/25 05:19:45 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -675,7 +675,7 @@ fi
675675
##
676676

677677
dnl sys/socket.h is required by AC_FUNC_ACCEPT_ARGTYPES
678-
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])
678+
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.hutime.hkernel/OS.h kernel/image.h SupportDefs.h])
679679

680680
# At least on IRIX, cpp test for netinet/tcp.h will fail unless
681681
# netinet/in.h is included first.
@@ -782,7 +782,7 @@ PGAC_FUNC_GETTIMEOFDAY_1ARG
782782
# SunOS doesn't handle negative byte comparisons properly with +/- return
783783
AC_FUNC_MEMCMP
784784

785-
AC_CHECK_FUNCS([cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync])
785+
AC_CHECK_FUNCS([cbrt fcvt getpeereid memmove pstat setproctitle setsid sigprocmask sysconf waitpid dlopen fdatasync utime utimes])
786786

787787
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
788788

‎src/backend/libpq/pqcomm.c

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
*$Id: pqcomm.c,v 1.146 2003/01/14 22:52:57 momjian Exp $
32+
*$Id: pqcomm.c,v 1.147 2003/01/25 05:19:46 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -41,6 +41,7 @@
4141
*StreamServerPort- Open postmaster's server port
4242
*StreamConnection- Create new connection with client
4343
*StreamClose- Close a client/backend connection
44+
*TouchSocketFile- Protect socket file against /tmp cleaners
4445
*pq_init- initialize libpq at backend startup
4546
*pq_close- shutdown libpq at backend exit
4647
*
@@ -66,15 +67,19 @@
6667
#include<fcntl.h>
6768
#include<grp.h>
6869
#include<unistd.h>
69-
#include<sys/stat.h>
70+
#include<sys/file.h>
7071
#include<sys/socket.h>
72+
#include<sys/stat.h>
73+
#include<sys/time.h>
7174
#include<netdb.h>
7275
#include<netinet/in.h>
7376
#ifdefHAVE_NETINET_TCP_H
7477
#include<netinet/tcp.h>
7578
#endif
7679
#include<arpa/inet.h>
77-
#include<sys/file.h>
80+
#ifdefHAVE_UTIME_H
81+
#include<utime.h>
82+
#endif
7883

7984
#include"libpq/libpq.h"
8085
#include"miscadmin.h"
@@ -87,8 +92,8 @@ extern ssize_t secure_write(Port *, const void *, size_t);
8792
staticvoidpq_close(void);
8893

8994
#ifdefHAVE_UNIX_SOCKETS
90-
intLock_AF_UNIX(unsigned shortportNumber,char*unixSocketName);
91-
intSetup_AF_UNIX(void);
95+
staticintLock_AF_UNIX(unsigned shortportNumber,char*unixSocketName);
96+
staticintSetup_AF_UNIX(void);
9297
#endif/* HAVE_UNIX_SOCKETS */
9398

9499
#ifdefHAVE_IPV6
@@ -175,12 +180,14 @@ static char sock_path[MAXPGPATH];
175180
* Shutdown routine for backend connection
176181
* If a Unix socket is used for communication, explicitly close it.
177182
*/
183+
#ifdefHAVE_UNIX_SOCKETS
178184
staticvoid
179185
StreamDoUnlink(void)
180186
{
181187
Assert(sock_path[0]);
182188
unlink(sock_path);
183189
}
190+
#endif/* HAVE_UNIX_SOCKETS */
184191

185192
/*
186193
* StreamServerPort -- open a sock stream "listening" port.
@@ -345,12 +352,13 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
345352

346353
}
347354

355+
356+
#ifdefHAVE_UNIX_SOCKETS
357+
348358
/*
349359
* Lock_AF_UNIX -- configure unix socket file path
350360
*/
351-
352-
#ifdefHAVE_UNIX_SOCKETS
353-
int
361+
staticint
354362
Lock_AF_UNIX(unsigned shortportNumber,char*unixSocketName)
355363
{
356364
SockAddrsaddr;/* just used to get socket path */
@@ -377,7 +385,7 @@ Lock_AF_UNIX(unsigned short portNumber, char *unixSocketName)
377385
/*
378386
* Setup_AF_UNIX -- configure unix socket permissions
379387
*/
380-
int
388+
staticint
381389
Setup_AF_UNIX(void)
382390
{
383391
/* Arrange to unlink the socket file at exit */
@@ -429,6 +437,7 @@ Setup_AF_UNIX(void)
429437
}
430438
returnSTATUS_OK;
431439
}
440+
432441
#endif/* HAVE_UNIX_SOCKETS */
433442

434443

@@ -506,6 +515,38 @@ StreamClose(int sock)
506515
close(sock);
507516
}
508517

518+
/*
519+
* TouchSocketFile -- mark socket file as recently accessed
520+
*
521+
* This routine should be called every so often to ensure that the socket
522+
* file has a recent mod date (ordinary operations on sockets usually won't
523+
* change the mod date). That saves it from being removed by
524+
* overenthusiastic /tmp-directory-cleaner daemons. (Another reason we should
525+
* never have put the socket file in /tmp...)
526+
*/
527+
void
528+
TouchSocketFile(void)
529+
{
530+
/* Do nothing if we did not create a socket... */
531+
if (sock_path[0]!='\0')
532+
{
533+
/*
534+
* utime() is POSIX standard, utimes() is a common alternative.
535+
* If we have neither, there's no way to affect the mod or access
536+
* time of the socket :-(
537+
*
538+
* In either path, we ignore errors; there's no point in complaining.
539+
*/
540+
#ifdefHAVE_UTIME
541+
utime(sock_path,NULL);
542+
#else/* !HAVE_UTIME */
543+
#ifdefHAVE_UTIMES
544+
utimes(sock_path,NULL);
545+
#endif/* HAVE_UTIMES */
546+
#endif/* HAVE_UTIME */
547+
}
548+
}
549+
509550

510551
/* --------------------------------
511552
* Low-level I/O routines begin here.

‎src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.305 2003/01/16 00:26:44 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.306 2003/01/25 05:19:46 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -2678,6 +2678,7 @@ SSDataBase(int xlop)
26782678
* do other actions that should happen every now and then on no
26792679
* particular schedule. Such as...
26802680
*/
2681+
TouchSocketFile();
26812682
TouchSocketLockFile();
26822683
}
26832684

‎src/backend/utils/init/miscinit.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.98 2002/12/05 04:04:46momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.99 2003/01/25 05:19:46tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include"postgres.h"
1616

1717
#include<sys/param.h>
1818
#include<signal.h>
19-
#include<sys/stat.h>
2019
#include<sys/file.h>
20+
#include<sys/stat.h>
21+
#include<sys/time.h>
2122
#include<fcntl.h>
2223
#include<unistd.h>
2324
#include<grp.h>
2425
#include<pwd.h>
2526
#include<errno.h>
2627
#include<netinet/in.h>
2728
#include<arpa/inet.h>
29+
#ifdefHAVE_UTIME_H
30+
#include<utime.h>
31+
#endif
2832

2933
#include"catalog/catname.h"
3034
#include"catalog/pg_shadow.h"
@@ -872,27 +876,42 @@ CreateSocketLockFile(const char *socketfile, bool amPostmaster)
872876
}
873877

874878
/*
875-
* Re-read the socket lock file. This should be called every so often
876-
* to ensure that the lock file has a recent access date. That saves it
879+
* TouchSocketLockFile -- mark socket lock file as recently accessed
880+
*
881+
* This routine should be called every so often to ensure that the lock file
882+
* has a recent mod or access date. That saves it
877883
* from being removed by overenthusiastic /tmp-directory-cleaner daemons.
878884
* (Another reason we should never have put the socket file in /tmp...)
879885
*/
880886
void
881887
TouchSocketLockFile(void)
882888
{
883-
intfd;
884-
charbuffer[1];
885-
886889
/* Do nothing if we did not create a socket... */
887890
if (socketLockFile[0]!='\0')
888891
{
889-
/* XXX any need to complain about errors here? */
892+
/*
893+
* utime() is POSIX standard, utimes() is a common alternative;
894+
* if we have neither, fall back to actually reading the file
895+
* (which only sets the access time not mod time, but that should
896+
* be enough in most cases). In all paths, we ignore errors.
897+
*/
898+
#ifdefHAVE_UTIME
899+
utime(socketLockFile,NULL);
900+
#else/* !HAVE_UTIME */
901+
#ifdefHAVE_UTIMES
902+
utimes(socketLockFile,NULL);
903+
#else/* !HAVE_UTIMES */
904+
intfd;
905+
charbuffer[1];
906+
890907
fd=open(socketLockFile,O_RDONLY |PG_BINARY,0);
891908
if (fd >=0)
892909
{
893910
read(fd,buffer,sizeof(buffer));
894911
close(fd);
895912
}
913+
#endif/* HAVE_UTIMES */
914+
#endif/* HAVE_UTIME */
896915
}
897916
}
898917

‎src/include/libpq/libpq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq.h,v 1.55 2003/01/06 03:18:27 momjian Exp $
10+
* $Id: libpq.h,v 1.56 2003/01/25 05:19:47 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -49,6 +49,7 @@ extern int StreamServerPort(int family, char *hostName,
4949
unsigned shortportNumber,char*unixSocketName,int*fdP);
5050
externintStreamConnection(intserver_fd,Port*port);
5151
externvoidStreamClose(intsock);
52+
externvoidTouchSocketFile(void);
5253
externvoidpq_init(void);
5354
externintpq_getbytes(char*s,size_tlen);
5455
externintpq_getstring(StringInfos,intmaxlen);

‎src/include/pg_config.h.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your
99
* changes will be overwritten the next time you run configure.
1010
*
11-
* $Id: pg_config.h.in,v 1.37 2003/01/06 06:07:20 momjian Exp $
11+
* $Id: pg_config.h.in,v 1.38 2003/01/25 05:19:47 tgl Exp $
1212
*/
1313

1414
#ifndefPG_CONFIG_H
@@ -383,6 +383,9 @@
383383
/* Set to 1 if you have <termios.h> */
384384
#undef HAVE_TERMIOS_H
385385

386+
/* Set to 1 if you have <utime.h> */
387+
#undef HAVE_UTIME_H
388+
386389
/* Set to 1 if you have <sys/pstat.h> */
387390
#undef HAVE_SYS_PSTAT_H
388391

@@ -520,6 +523,12 @@
520523
/* Define if you have fdatasync() */
521524
#undef HAVE_FDATASYNC
522525

526+
/* Define if you have utime() */
527+
#undef HAVE_UTIME
528+
529+
/* Define if you have utimes() */
530+
#undef HAVE_UTIMES
531+
523532
/* Define if the standard header unistd.h declares fdatasync() */
524533
#undef HAVE_DECL_FDATASYNC
525534

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp