From ced858d05f9514a0082f661aae29ba592aae28fb Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Sun, 2 Mar 1997 04:15:21 +0000 Subject: (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. --- login/utmp_file.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/login/utmp_file.c b/login/utmp_file.c index 102eba02e1..ad65ec1309 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -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. Contributed by Ulrich Drepper and Paul Janzen , 1996. @@ -210,7 +210,26 @@ getutline_r_file (const struct utmp *line, struct utmp *buffer, 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 || 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); - if (( buffer->ut_type == INIT_PROCESS - || 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) + if (proc_utmp_eq (&buffer, id)) break; } } @@ -276,7 +291,7 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer, return -1; } - if (internal_getutid_r (id, &last_entry) < 0) + if (internal_getut_r (id, &last_entry) < 0) { *result = NULL; return -1; @@ -306,21 +321,16 @@ pututline_file (const struct utmp *data) setutent_file (0); /* Find the correct place to insert the data. */ - if (file_offset > 0) - found = 0; + if (file_offset > 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 - if ( last_entry.ut_type == RUN_LVL - || 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); + found = internal_getut_r (data, &buffer); /* Try to lock the file. */ memset (&fl, '\0', sizeof (struct flock)); -- cgit 1.4.1