diff common/util.c @ 1332:8362e30f7b55

(issue139) Check that pid is not running if the lock can be aquired If the lock on the lockfile can be aquired it might still be possible that another process is running. So we read the pid from the lockfile and check if another process with the same installation prefix as us is running.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 15 Oct 2014 14:19:46 +0200
parents 2bacaec6e101
children b90df38bb6dc
line wrap: on
line diff
--- a/common/util.c	Wed Oct 15 13:24:59 2014 +0200
+++ b/common/util.c	Wed Oct 15 14:19:46 2014 +0200
@@ -314,15 +314,26 @@
 #else /* WIN32 */
 
 char *
-get_install_dir()
+get_proc_install_dir(const char *proc)
 {
   char *retval = NULL,
-        *p = NULL,
-         buf[MAX_PATH_LINUX];
+       *procpath = NULL,
+       *p = NULL,
+        buf[MAX_PATH_LINUX];
   ssize_t ret;
   size_t path_len = 0;
 
-  ret = readlink ("/proc/self/exe", buf, MAX_PATH_LINUX);
+  if (!proc)
+    {
+      return NULL;
+    }
+
+  xasprintf(&procpath, "/proc/%s/exe", proc);
+
+  ret = readlink (procpath, buf, MAX_PATH_LINUX);
+  xfree(procpath);
+  procpath = NULL;
+
   if (ret <= 0)
     {
       ERRORPRINTF ("readlink failed\n");
@@ -348,6 +359,12 @@
   return retval;
 }
 
+char *
+get_install_dir()
+{
+  return get_proc_install_dir("self");
+}
+
 bool
 is_system_install()
 {

http://wald.intevation.org/projects/trustbridge/