[Xastir-dev] PID_FILE_CHECK patch to main.c

Dan Brown brown at brauhaus.org
Tue Mar 8 19:32:57 EST 2005


On Tue, 8 Mar 2005, Owen DeLong wrote:

> Pardon my ignorance, but, why do we want to disable multiple copies
> of XASTIR from starting?

It is actually "prevent multiple copies, running under as same user and
using the same config files." You can still have multiple users and
multiple config dirs (~username/.xastir...) with multiple instances running
on the same machine - just not as the same user with the same config files. 

It isn't so much "disable them from running" as "keep multiple instances
from stomping on the configuration files which didn't have any sort of
locking mechanism."

Next, having the xastir.pid file makes it easier to automate startups and
shutdowns and or sending signals, etc.  No more (ps | grep | awk) - just
read the xastir.pid file and go. 

Finally - the code, as currently setup with #ifdefs, is all optional.  It
is a good idea, in my opinion. 

Make sense? 

Dan. 

> Owen
> 
> 
> --On Tuesday, March 8, 2005 3:12 PM -0500 Dan Brown <brown at brauhaus.org> 
> wrote:
> 
> >
> >
> > Ok, attched is a bit more thought out patch to main.c, to implement
> > using an "xastir.pid" file. I've compiled and done some testing on
> > Redhat 9, Mac OS X 10.3.8 and Cygwin.
> >
> > Things are wrapped in ifdef statements, so, to use this code you will need
> > to, as Tom described, do:
> >
> >   ./configure CPPFLAGS="-DUSE_PID_FILE_CHECK"
> >
> >
> > How it works:
> >
> > The code looks to see if the ~/.xastir/xastir.pid file exists, and, if it
> > does, tries to open it.  If it can read a pid from it, the code tries to
> > do a kill(other_pid, 0) which doesn't send a signal, but should give us
> > indication about whether the other process exists.  If we see a negative
> > return and a ESRCH errno, the code assumes the other process doesn't
> > exist, so cleans up the old xastir.pid file.
> >
> > If it can send a signal, it assumes the other xastir is running, so
> > bails out. Otherwise, assuming nothing else has gone wrong, we fall
> > through and create the xastir.pid file with the current process's pid.
> >
> > There is also a line of code to remove the pid file in the quit()
> > function call.
> >
> > This isn't all of the "whole enchilada" that Curt had discussed as being
> > able to have multiple instances of Xastir running under the same user ID,
> > using separate configs.  It is an incremental improvement which should
> > help prevent corruption of config files, by allowing xastir to check for
> > other instances of itself. As such, I think this is worth adding to the
> > code base.
> >
> > The patch is attached, and is also available at:
> >
> > http://www.brauhaus.org/xastir/main.c.patch_PID_FILE_CHECK
> >
> > and
> >
> > http://www.brauhaus.org/xastir/main.c.patch_PID_FILE_CHECK.gz
> >
> >
> > 73,
> > N8YSZ.
> > --
> > Dan Brown
> > brown at brauhausdc.org
> 
> 
> 
> -- 
> If it wasn't crypto-signed, it probably didn't come from me.
> 

--
Dan Brown 
brown at brauhausdc.org




More information about the Xastir-dev mailing list