Skip to content

Commit

Permalink
[BZ #6634]
Browse files Browse the repository at this point in the history
2008-08-13  Ulrich Drepper  <drepper@redhat.com>
	[BZ #6634]
	* login/utmp_file.c (getutent_r_file): Take additional parameter.
	Set to true if locking failed.
	(getutid_r_file): Adjust caller.
	(pututline_file): Likewise.  Return NULL in this case.
	Patch mostly by halesh.s@gmail.com.
  • Loading branch information
Ulrich Drepper committed Aug 14, 2008
1 parent c567169 commit 1bfa05c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2008-08-13 Ulrich Drepper <drepper@redhat.com>

[BZ #6634]
* login/utmp_file.c (getutent_r_file): Take additional parameter.
Set to true if locking failed.
(getutid_r_file): Adjust caller.
(pututline_file): Likewise. Return NULL in this case.
Patch mostly by halesh.s@gmail.com.

2008-08-12 Ulrich Drepper <drepper@redhat.com>

[BZ #6589]
Expand Down
25 changes: 21 additions & 4 deletions login/utmp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -244,12 +245,16 @@ getutent_r_file (struct utmp *buffer, struct utmp **result)


static int
internal_getut_r (const struct utmp *id, struct utmp *buffer)
internal_getut_r (const struct utmp *id, struct utmp *buffer,
bool *lock_failed)
{
int result = -1;

LOCK_FILE (file_fd, F_RDLCK)
LOCKING_FAILED ();
{
*lock_failed = true;
LOCKING_FAILED ();
}

#if _HAVE_UT_TYPE - 0
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
Expand Down Expand Up @@ -320,7 +325,10 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer,
return -1;
}

if (internal_getut_r (id, &last_entry) < 0)
/* We don't have to distinguish whether we can lock the file or
whether there is no entry. */
bool lock_failed = false;
if (internal_getut_r (id, &last_entry, &lock_failed) < 0)
{
*result = NULL;
return -1;
Expand Down Expand Up @@ -410,7 +418,16 @@ pututline_file (const struct utmp *data)
__utmp_equal (&last_entry, data)))
found = 1;
else
found = internal_getut_r (data, &buffer);
{
bool lock_failed = false;
found = internal_getut_r (data, &buffer, &lock_failed);

if (__builtin_expect (lock_failed, false))
{
__set_errno (EAGAIN);
return NULL;
}
}

LOCK_FILE (file_fd, F_WRLCK)
{
Expand Down

0 comments on commit 1bfa05c

Please sign in to comment.