comparison 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
comparison
equal deleted inserted replaced
1331:8897c90b8166 1332:8362e30f7b55
312 return ret; 312 return ret;
313 } 313 }
314 #else /* WIN32 */ 314 #else /* WIN32 */
315 315
316 char * 316 char *
317 get_install_dir() 317 get_proc_install_dir(const char *proc)
318 { 318 {
319 char *retval = NULL, 319 char *retval = NULL,
320 *p = NULL, 320 *procpath = NULL,
321 buf[MAX_PATH_LINUX]; 321 *p = NULL,
322 buf[MAX_PATH_LINUX];
322 ssize_t ret; 323 ssize_t ret;
323 size_t path_len = 0; 324 size_t path_len = 0;
324 325
325 ret = readlink ("/proc/self/exe", buf, MAX_PATH_LINUX); 326 if (!proc)
327 {
328 return NULL;
329 }
330
331 xasprintf(&procpath, "/proc/%s/exe", proc);
332
333 ret = readlink (procpath, buf, MAX_PATH_LINUX);
334 xfree(procpath);
335 procpath = NULL;
336
326 if (ret <= 0) 337 if (ret <= 0)
327 { 338 {
328 ERRORPRINTF ("readlink failed\n"); 339 ERRORPRINTF ("readlink failed\n");
329 return NULL; 340 return NULL;
330 } 341 }
344 retval = xmalloc (path_len + 1); 355 retval = xmalloc (path_len + 1);
345 strncpy (retval, buf, path_len); 356 strncpy (retval, buf, path_len);
346 retval[path_len] = '\0'; 357 retval[path_len] = '\0';
347 358
348 return retval; 359 return retval;
360 }
361
362 char *
363 get_install_dir()
364 {
365 return get_proc_install_dir("self");
349 } 366 }
350 367
351 bool 368 bool
352 is_system_install() 369 is_system_install()
353 { 370 {

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