[gdm] session-record: simplify utmp updating logic
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm] session-record: simplify utmp updating logic
- Date: Fri, 14 Aug 2015 19:23:59 +0000 (UTC)
commit d8e1d3890c332f2afdcdb16a391003af09aff70d
Author: Paul Szabo <psz maths usyd edu au>
Date: Fri Aug 14 14:59:56 2015 -0400
session-record: simplify utmp updating logic
The code carefully iterates over all utmp entries trying to update
existing records if found. This is not necessary putuxline will
do that for us.
https://bugzilla.gnome.org/show_bug.cgi?id=599103
daemon/gdm-session-record.c | 61 +++---------------------------------------
1 files changed, 5 insertions(+), 56 deletions(-)
---
diff --git a/daemon/gdm-session-record.c b/daemon/gdm-session-record.c
index 89c11a8..8ff0467 100644
--- a/daemon/gdm-session-record.c
+++ b/daemon/gdm-session-record.c
@@ -202,7 +202,6 @@ gdm_session_record_login (GPid session_pid,
const char *display_device)
{
UTMP session_record = { 0 };
- UTMP *u;
if (x11_display_name == NULL)
x11_display_name = display_device;
@@ -238,31 +237,10 @@ gdm_session_record_login (GPid session_pid,
#endif
#endif
- /*
- * Handle utmp
- * Update if entry already exists
- */
+ /* Handle utmp */
#if defined(HAVE_GETUTXENT)
- setutxent ();
-
- while ((u = getutxent ()) != NULL) {
- if (u->ut_type == USER_PROCESS &&
- (session_record.ut_line != NULL &&
- (strncmp (u->ut_line, session_record.ut_line,
- sizeof (u->ut_line)) == 0 ||
- u->ut_pid == session_record.ut_pid))) {
- g_debug ("Updating existing utmp record");
- pututxline (&session_record);
- break;
- }
- }
- endutxent ();
-
- /* Add new entry if update did not work */
- if (u == NULL) {
- g_debug ("Adding new utmp record");
- pututxline (&session_record);
- }
+ g_debug ("Adding or updating utmp record for login");
+ pututxline (&session_record);
#elif defined(HAVE_LOGIN)
login (&session_record);
#endif
@@ -276,7 +254,6 @@ gdm_session_record_logout (GPid session_pid,
const char *display_device)
{
UTMP session_record = { 0 };
- UTMP *u;
if (x11_display_name == NULL)
x11_display_name = display_device;
@@ -308,36 +285,8 @@ gdm_session_record_logout (GPid session_pid,
/* Handle utmp */
#if defined(HAVE_GETUTXENT)
- setutxent ();
-
- while ((u = getutxent ()) != NULL &&
- (u = getutxid (&session_record)) != NULL) {
-
- g_debug ("Removing utmp record");
- if (u->ut_pid == session_pid &&
- u->ut_type == DEAD_PROCESS) {
- /* Already done */
- break;
- }
-
- u->ut_type = DEAD_PROCESS;
-#if defined(HAVE_UT_UT_TV)
- u->ut_tv.tv_sec = session_record.ut_tv.tv_sec;
- u->ut_tv.tv_usec = session_record.ut_tv.tv_usec;
-#elif defined(HAVE_UT_UT_TIME)
- u->ut_time = session_record.ut_time;
-#endif
-#ifdef HAVE_UT_UT_EXIT_E_TERMINATION
- u->ut_exit.e_termination = 0;
- u->ut_exit.e_exit = 0;
-#endif
-
- pututxline (u);
-
- break;
- }
-
- endutxent ();
+ g_debug ("Adding or updating utmp record for logout");
+ pututxline (&session_record);
#elif defined(HAVE_LOGOUT)
logout (session_record.ut_line);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]