From 73bd66814e7335e7148c7e975655e2f349955d5e Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Thu, 13 Oct 2011 14:40:56 +0200 Subject: [PATCH 1/4] Make use of utmpx optional and buildable on FreeBSD. Not all operating systems out there support utmpx. Examples include OpenBSD, but also FreeBSD prior to version 9.0. Also, FreeBSD's utmpx (fortunately) does not support utmpxname(), to prevent applications from hardcoding the path to the wtmp file. Use the setutxdb() function to switch to the wtmp database. Signed-off-by: Ed Schouten --- configure.ac | 2 ++ src/daemon.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/configure.ac b/configure.ac index 1b76623..216d8e6 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,8 @@ AC_CACHE_CHECK([for supported warning flags], accountsservice_cv_warn_cflags, [ WARN_CFLAGS="$accountsservice_cv_warn_cflags" AC_SUBST(WARN_CFLAGS) +AC_CHECK_HEADERS([utmpx.h]) + dnl --------------------------------------------------------------------------- dnl - DocBook Documentation dnl --------------------------------------------------------------------------- diff --git a/src/daemon.c b/src/daemon.c index 99ee161..c6ae9e0 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -32,7 +32,9 @@ #include #include #include +#ifdef HAVE_UTMPX_H #include +#endif #include #include @@ -238,13 +240,19 @@ daemon_local_user_is_excluded (Daemon *daemon, const gchar *username, uid_t uid) static void reload_wtmp_history (Daemon *daemon) { +#ifdef HAVE_UTMPX_H struct utmpx *wtmp_entry; GHashTable *login_frequency_hash; GHashTableIter iter; gpointer key, value; - utmpxname(_PATH_WTMPX); +#ifdef UTXDB_LOG + if (setutxdb (UTXDB_LOG, NULL) != 0) + return; +#else + utmpxname (_PATH_WTMPX); setutxent (); +#endif login_frequency_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); @@ -298,6 +306,7 @@ reload_wtmp_history (Daemon *daemon) g_hash_table_foreach (login_frequency_hash, (GHFunc) g_free, NULL); g_hash_table_unref (login_frequency_hash); +#endif /* HAVE_UTMPX_H */ } static void -- 1.7.7