On 09/26/2012 10:31 AM, Jiri Moskovcak wrote:
---
src/daemon/abrtd.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c
index 3bf705c..8dc4322 100644
--- a/src/daemon/abrtd.c
+++ b/src/daemon/abrtd.c
@@ -704,6 +704,28 @@ static void dumpsocket_shutdown()
}
}
+static pid_t get_locking_pid()
+{
+ FILE *pid_file = fopen(VAR_RUN_PIDFILE, "r");
+ pid_t retval = 0;
+
+ if (!pid_file)
+ {
+ perror_msg("Can't open %s", VAR_RUN_PIDFILE);
+ return retval;
+ }
+
+ char line[128]; //should be enough to store pid
+
+ if (fgets(line, sizeof(line), pid_file) != NULL)
+ {
+ retval = strtol(line, (char **)NULL, 10);
+ }
+
+ fclose(pid_file);
+ return retval;
+}
+
static int create_pidfile()
{
/* Note:
@@ -718,6 +740,11 @@ static int create_pidfile()
if (lockf(fd, F_TLOCK, 0) < 0)
{
perror_msg("Can't lock file '%s'", VAR_RUN_PIDFILE);
+ /* should help with problems like rhbz#859724 */
+ pid_t locking_pid = get_locking_pid();
You have an open fd to the VAR_RUN_PIDFILE, you can just read it,
no need to open it again :)
Say:
size_t maxsize = 128;
pid_str = xmalloc_read(fd, &maxsize);
close(fd);
- if (locking_pid > 0)
+ if (pid_str && pid_str[0])
unsigned long locking_pid = strtoul(pid_str, NULL, 10);
+ error_msg("Process: '%s (%u)' is
holding the lock", get_cmdline(locking_pid), locking_pid);
free(pid_str);
+
return -1;
}