mirror of
https://sourceware.org/git/glibc.git
synced 2025-06-06 11:41:02 +03:00
(proc_utmp_eq): New function. (pututline_file): Correctly decide whether LAST_ENTRY matches DATA. Don't depend on ut_id ever being set. (internal_getut_r): Renamed from internal_getutid_r. Use proc_utmp_eq.
This commit is contained in:
parent
ceb2d9aaa8
commit
ced858d05f
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 1996 Free Software Foundation, Inc.
|
/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@cygnus.com>
|
Contributed by Ulrich Drepper <drepper@cygnus.com>
|
||||||
and Paul Janzen <pcj@primenet.com>, 1996.
|
and Paul Janzen <pcj@primenet.com>, 1996.
|
||||||
@ -210,7 +210,26 @@ getutline_r_file (const struct utmp *line, struct utmp *buffer,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
internal_getutid_r (const struct utmp *id, struct utmp *buffer)
|
proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
((entry->ut_type == INIT_PROCESS
|
||||||
|
|| entry->ut_type == LOGIN_PROCESS
|
||||||
|
|| entry->ut_type == USER_PROCESS
|
||||||
|
|| entry->ut_type == DEAD_PROCESS)
|
||||||
|
&&
|
||||||
|
(match->ut_type == INIT_PROCESS
|
||||||
|
|| match->ut_type == LOGIN_PROCESS
|
||||||
|
|| match->ut_type == USER_PROCESS
|
||||||
|
|| match->ut_type == DEAD_PROCESS)
|
||||||
|
&&
|
||||||
|
(entry->ut_id && match->ut_id
|
||||||
|
? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
|
||||||
|
: strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
internal_getut_r (const struct utmp *id, struct utmp *buffer)
|
||||||
{
|
{
|
||||||
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
|
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
|
||||||
|| id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
|
|| id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
|
||||||
@ -251,11 +270,7 @@ internal_getutid_r (const struct utmp *id, struct utmp *buffer)
|
|||||||
}
|
}
|
||||||
file_offset += sizeof (struct utmp);
|
file_offset += sizeof (struct utmp);
|
||||||
|
|
||||||
if (( buffer->ut_type == INIT_PROCESS
|
if (proc_utmp_eq (&buffer, id))
|
||||||
|| buffer->ut_type == LOGIN_PROCESS
|
|
||||||
|| buffer->ut_type == USER_PROCESS
|
|
||||||
|| buffer->ut_type == DEAD_PROCESS)
|
|
||||||
&& strncmp (buffer->ut_id, id->ut_id, sizeof id->ut_id) == 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +291,7 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (internal_getutid_r (id, &last_entry) < 0)
|
if (internal_getut_r (id, &last_entry) < 0)
|
||||||
{
|
{
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -306,21 +321,16 @@ pututline_file (const struct utmp *data)
|
|||||||
setutent_file (0);
|
setutent_file (0);
|
||||||
|
|
||||||
/* Find the correct place to insert the data. */
|
/* Find the correct place to insert the data. */
|
||||||
if (file_offset > 0)
|
if (file_offset > 0
|
||||||
found = 0;
|
&& ((last_entry.ut_type == data->ut_type
|
||||||
|
&& (last_entry.ut_type == RUN_LVL
|
||||||
|
|| last_entry.ut_type == BOOT_TIME
|
||||||
|
|| last_entry.ut_type == OLD_TIME
|
||||||
|
|| last_entry.ut_type == NEW_TIME))
|
||||||
|
|| proc_utmp_eq (&last_entry, data)))
|
||||||
|
found = 1;
|
||||||
else
|
else
|
||||||
if ( last_entry.ut_type == RUN_LVL
|
found = internal_getut_r (data, &buffer);
|
||||||
|| last_entry.ut_type == BOOT_TIME
|
|
||||||
|| last_entry.ut_type == OLD_TIME
|
|
||||||
|| last_entry.ut_type == NEW_TIME
|
|
||||||
|| (( last_entry.ut_type == INIT_PROCESS
|
|
||||||
|| last_entry.ut_type == LOGIN_PROCESS
|
|
||||||
|| last_entry.ut_type == USER_PROCESS
|
|
||||||
|| last_entry.ut_type == DEAD_PROCESS)
|
|
||||||
&& !strncmp (last_entry.ut_id, data->ut_id, sizeof data->ut_id)))
|
|
||||||
found = 1;
|
|
||||||
else
|
|
||||||
found = internal_getutid_r (data, &buffer);
|
|
||||||
|
|
||||||
/* Try to lock the file. */
|
/* Try to lock the file. */
|
||||||
memset (&fl, '\0', sizeof (struct flock));
|
memset (&fl, '\0', sizeof (struct flock));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user