[Xastir-dev] PID_FILE_CHECK patch to main.c

Dan Brown brown at brauhaus.org
Tue Mar 8 15:12:23 EST 2005



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


More information about the Xastir-dev mailing list