[uClibc 0000716]: libc/misc/utmp/utent.c deadlocks when used with libpthread
bugs at busybox.net
bugs at busybox.net
Tue Feb 14 15:20:47 UTC 2006
A NOTE has been added to this issue.
======================================================================
http://busybox.net/bugs/view.php?id=716
======================================================================
Reported By: rholzmann
Assigned To: uClibc
======================================================================
Project: uClibc
Issue ID: 716
Category: Other
Reproducibility: always
Severity: minor
Priority: normal
Status: assigned
======================================================================
Date Submitted: 02-10-2006 10:49 PST
Last Modified: 02-14-2006 07:20 PST
======================================================================
Summary: libc/misc/utmp/utent.c deadlocks when used with
libpthread
Description:
utent.c has a few problems with mutex locking when used in a binary that
was linked with pthreads. The are a few deadlock conditions where
functions may be called which lock the utmplock but never release it and
where a function that hold the lock calls other functions which try to
relock the same lock. Here is one example in the function __getutent:
static struct utmp *__getutent(int utmp_fd)
{
if (utmp_fd == -1) {
setutent();
}
if (utmp_fd == -1) {
return NULL;
}
LOCK;
if (read(utmp_fd, (char *) &static_utmp, sizeof(struct utmp)) !=
sizeof(struct utmp))
{
return NULL;
}
UNLOCK;
return &static_utmp;
}
Notice the error condition does not unlock the semaphore. The problem is
not visible when pthreads isn't used since the lock/unlock functions are
NOOP functions.
I have attached a patch file that tries to correct these problems. I
think the patch fixes all of the possible deadlock conditions. Let me
know what you think.
======================================================================
----------------------------------------------------------------------
vapier - 02-10-06 21:37
----------------------------------------------------------------------
thanks, the patch looks good ... ive also shrunk the code in a few other
places as well and added to svn
----------------------------------------------------------------------
rholzmann - 02-14-06 07:20
----------------------------------------------------------------------
I think there is still a problem if you call pututline.
1. pututline LOCKs
2. pututline calls getutid
3. getutid calls __getutent
4. a. __getutent possibly calls setutent
b. setutent LOCKs (deadlock)
-OR-
5. __getutent LOCKs (deadlock)
I think a good solution would be to change __getutent to not lock and have
calling functions obtain the lock. I have attached my proposed change.
The basic design behind the change is to make the utent API layer of
functions handle obtaining/releasing the lock which relieves the
__api_functions from worrying about the locking. I think this makes the
code a bit easier to follow as well.
Issue History
Date Modified Username Field Change
======================================================================
02-10-06 10:49 rholzmann New Issue
02-10-06 10:49 rholzmann Status new => assigned
02-10-06 10:49 rholzmann Assigned To => uClibc
02-10-06 10:49 rholzmann File Added: utmp-thread.patch
02-10-06 21:37 vapier Note Added: 0001083
02-14-06 07:20 rholzmann Note Added: 0001095
======================================================================
More information about the uClibc-cvs
mailing list