diff options
author | Ryan Lortie <desrt@desrt.ca> | 2014-03-08 18:11:15 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2014-03-19 09:46:47 -0400 |
commit | f94afeb0865cbaeaed17ef9bf949d90ad6255824 (patch) | |
tree | 75b28355398676bee70aeac2e8f90f3345f277d0 | |
parent | 9771f8e9ba0d5c7bb3cf10b244463fcfd21f9776 (diff) | |
download | accountsservice-f94afeb0865cbaeaed17ef9bf949d90ad6255824.tar.gz |
wtmp: split out the platform-specific bits
The logic for how to begin the iteration of the wtmp file is
platform-specific. Split out.
https://bugs.freedesktop.org/show_bug.cgi?id=75938
-rw-r--r-- | src/wtmp-helper.c | 27 |
1 files 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); |