mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-31 19:40:33 +08:00
* syscalls.cc (locked_append): New.
(updwtmp): Remove mutex code and call locked_append. (pututline): Ditto.
This commit is contained in:
parent
ae2543ed76
commit
2e3ff06d3c
@ -1,3 +1,9 @@
|
|||||||
|
2003-12-07 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
|
* syscalls.cc (locked_append): New.
|
||||||
|
(updwtmp): Remove mutex code and call locked_append.
|
||||||
|
(pututline): Ditto.
|
||||||
|
|
||||||
2003-12-06 Christopher Faylor <cgf@redhat.com>
|
2003-12-06 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* exceptions.cc (_threadinfo::remove): Avoid a linked list walk.
|
* exceptions.cc (_threadinfo::remove): Avoid a linked list walk.
|
||||||
|
@ -2553,28 +2553,37 @@ ffs (int i)
|
|||||||
return table[x >> a] + a;
|
return table[x >> a] + a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
locked_append (int fd, const void * buf, size_t size)
|
||||||
|
{
|
||||||
|
struct __flock64 lock_buffer = {F_WRLCK, SEEK_SET, 0, 0, 0};
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
if ((lock_buffer.l_start = lseek64 (fd, 0, SEEK_END)) != (_off64_t)-1
|
||||||
|
&& fcntl_worker (fd, F_SETLKW, &lock_buffer) != -1)
|
||||||
|
{
|
||||||
|
if (lseek64 (fd, 0, SEEK_END) != (_off64_t)-1)
|
||||||
|
write (fd, buf, size);
|
||||||
|
lock_buffer.l_type = F_UNLCK;
|
||||||
|
fcntl_worker (fd, F_SETLK, &lock_buffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (count++ < 1000
|
||||||
|
&& (errno == EACCES || errno == EAGAIN)
|
||||||
|
&& !usleep (1000));
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
updwtmp (const char *wtmp_file, const struct utmp *ut)
|
updwtmp (const char *wtmp_file, const struct utmp *ut)
|
||||||
{
|
{
|
||||||
/* Writing to wtmp must be atomic to prevent mixed up data. */
|
|
||||||
char mutex_name[CYG_MAX_PATH];
|
|
||||||
HANDLE mutex;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
mutex = CreateMutex (NULL, FALSE, shared_name (mutex_name, "wtmp_mutex", 0));
|
if ((fd = open (wtmp_file, O_WRONLY | O_BINARY, 0)) >= 0)
|
||||||
if (mutex)
|
|
||||||
while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED)
|
|
||||||
;
|
|
||||||
if ((fd = open (wtmp_file, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0)
|
|
||||||
{
|
{
|
||||||
write (fd, ut, sizeof *ut);
|
locked_append (fd, ut, sizeof *ut);
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
if (mutex)
|
|
||||||
{
|
|
||||||
ReleaseMutex (mutex);
|
|
||||||
CloseHandle (mutex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
@ -2783,25 +2792,15 @@ pututline (struct utmp *ut)
|
|||||||
ut->ut_type, ut->ut_pid, ut->ut_line, ut->ut_id);
|
ut->ut_type, ut->ut_pid, ut->ut_line, ut->ut_id);
|
||||||
debug_printf ("ut->ut_user '%s', ut->ut_host '%s'\n",
|
debug_printf ("ut->ut_user '%s', ut->ut_host '%s'\n",
|
||||||
ut->ut_user, ut->ut_host);
|
ut->ut_user, ut->ut_host);
|
||||||
/* Read/write to utmp must be atomic to prevent overriding data
|
|
||||||
by concurrent processes. */
|
|
||||||
char mutex_name[CYG_MAX_PATH];
|
|
||||||
HANDLE mutex = CreateMutex (NULL, FALSE,
|
|
||||||
shared_name (mutex_name, "utmp_mutex", 0));
|
|
||||||
if (mutex)
|
|
||||||
while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED)
|
|
||||||
;
|
|
||||||
struct utmp *u;
|
struct utmp *u;
|
||||||
if ((u = getutid (ut)))
|
if ((u = getutid (ut)))
|
||||||
lseek (utmp_fd, -sizeof *ut, SEEK_CUR);
|
|
||||||
else
|
|
||||||
lseek (utmp_fd, 0, SEEK_END);
|
|
||||||
write (utmp_fd, ut, sizeof *ut);
|
|
||||||
if (mutex)
|
|
||||||
{
|
{
|
||||||
ReleaseMutex (mutex);
|
lseek (utmp_fd, -sizeof *ut, SEEK_CUR);
|
||||||
CloseHandle (mutex);
|
write (utmp_fd, ut, sizeof *ut);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
locked_append (utmp_fd, ut, sizeof *ut);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user