From dbeb169dfe3172af8c771e169e177e12ba50c117 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Sat, 8 Mar 2014 18:11:15 -0500 Subject: [PATCH 2/4] wtmp: split out the platform-specific bits The logic for how to begin the iteration of the wtmp file is platform-specific. Split out. --- src/wtmp-helper.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/wtmp-helper.c b/src/wtmp-helper.c index 5f7c6ed..af460e6 100644 --- a/src/wtmp-helper.c +++ b/src/wtmp-helper.c @@ -55,6 +55,24 @@ user_previous_login_free (UserPreviousLogin *previous_login) g_free (previous_login); } +static gboolean +wtmp_helper_start (void) +{ +#ifdef UTXDB_LOG + if (setutxdb (UTXDB_LOG, NULL) != 0) { + return FALSE; + } +#else + if (utmpxname (PATH_WTMP) != 0) { + return FALSE; + } + + setutxent (); +#endif + + return TRUE; +} + struct passwd * wtmp_helper_entry_generator (GHashTable *users, gpointer *state) @@ -71,14 +89,11 @@ wtmp_helper_entry_generator (GHashTable *users, if (*state == NULL) { /* First iteration */ -#ifdef UTXDB_LOG - if (setutxdb (UTXDB_LOG, NULL) != 0) { + + if (!wtmp_helper_start ()) return NULL; } -#else - utmpxname (PATH_WTMP); - setutxent (); -#endif + *state = g_new (WTmpGeneratorState, 1); state_data = *state; state_data->login_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -- 1.8.5.3