Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] flock patch breaks things here

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
Cc: dz(at)cs(dot)unitn(dot)it (Massimo Dal Zotto), hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] flock patch breaks things here
Date: 1998-08-30 15:23:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> writes:
> Can't we just have configure check for flock().  Another idea is to
> create a 'pid' file in the pgsql/data/base directory, and do a kill -0
> to see if it is stil running before removing the lock.

The latter approach is what I was going to suggest.  Writing a pid file
would be a fine idea anyway --- for one thing, it makes it a lot easier
to write a "kill the postmaster" script.  Given that the postmaster
should write a pid file, a new postmaster should look for an existing
pid file, and try to do a kill(pid, 0) on the number contained therein.
If this doesn't return an error, then you figure there is already a
postmaster running, complain, and exit.  Otherwise you figure you is it,
(re)write the pid file and away you go.  Then pqcomm.c can just
unconditionally delete any old file that's in the way of making the

The pidfile checking and creation probably ought to go in postmaster.c,
not down inside pqcomm.c.  I never liked the fact that a critical
interlock function was being done by a low-level library that one might
not even want to invoke (if all your clients are using TCP, opening up
the Unix-domain socket is a waste of time, no?).

BTW, there is another problem with relying on flock on the socket file
for this purpose: it opens up a hole for a denial-of-service attack.
Anyone who can write the file can flock it.  (We already had a problem
with DOS via creating a dummy file at /tmp/.s.PGSQL.5432, but it would
be harder to spot the culprit with an flock-based interference.)

			regards, tom lane


pgsql-hackers by date

Next:From: Massimo Dal ZottoDate: 1998-08-30 15:24:36
Subject: bug + patch
Previous:From: Peter T MountDate: 1998-08-30 14:04:08
Subject: Re: [HACKERS] pgindent for Monday

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group