Hi,
>> would it help if getutline was thread safe.
I suspect that making it thread safe could very well get rid of the static
buffer and hence the problem. But it has to be done in such a way that we
don't use the same buffer for input and output, even if it is thread safe.
The getutline() routine always returns the entry in the static buffer. The
real problem is that the same memory location is being shared by getutline()
and pututline() doing an internal read
(pututline->__getutid->__getutent->read_not_cancel.
if (read_not_cancel(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(s
return &static_utmp;
Now glibc allocates the buffer and stores the pointer into a static variable.
It then has the following comment:
/* Allocate a static buffer to be returned to the caller. As well as
with the existing version of these functions the caller has to be
aware that the contents of this buffer will change with subsequent
calls. */
Seems like it's probably just not good practice to use the static buffer from
getutline() as input into pututline().
------
John G. Ata
BAE Systems
STOP Software Development
-----Original Message-----
From: Khem Raj [mailto:[email protected]]
Sent: Monday, August 17, 2015 5:44 PM
To: Ata, John (US)
Cc: [email protected]
Subject: Re: libutil's logout doesn't clear utmp entries
> On Aug 17, 2015, at 1:29 PM, Ata, John (US) <[email protected]> wrote:
>
> Hi,
>
> The module logout() in libutil does not actually remove the utmp entry that
> it attempts to do. This is because it uses getutline() to read the utmp
> entry which is returned in utmp's internal static buffer. It then modifies
> the static entry directly and attempts to write it out with pututline().
> However, pututline() reads the original entry before writing it into the
> internal static buffer (only one internal utmp buffer) so it then always
> writes the original unchanged record back out. One fix is to copy the static
> buffer into the temporary tmp stack variable (no longer needed) after reading
> but before writing. This has been tested and appears to work well.
>
> +--- uclibc/libutil/logout.c 2012-05-15 03:20:09.000000000 -0400
> ++++ uclibc/libutil/logout.c 2015-08-14 16:59:06.625944541 -0400
> +@@ -45,6 +45,10 @@
> + /* Read the record. */
> + if ((ut = getutline(&tmp)) != NULL)
would it help if getutline was thread safe.
> + {
> ++ /* We can't use the utmp static buffer on the rewrite so copy over */
> ++ memcpy(&tmp, ut, sizeof tmp);
> ++ ut = &tmp;
> ++
> + /* Clear information about who & from where. */
> + memset (ut->ut_name, 0, sizeof ut->ut_name);
> + #if _HAVE_UT_HOST - 0
>
> ------
> John Ata
> BAE Systems
> STOP Software Development
>
> _______________________________________________
> uClibc mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/uclibc
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc