[liboobs] Use utmpx rather than utmp



commit 5c597274af5bbd3092be03df6e5a7094da228288
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Jan 25 18:37:03 2010 +0100

    Use utmpx rather than utmp
    
    We now require utmpx.h to be present, since utmp has been deprecated for a long time. This was requested by FreeBSD, thanks to Ed Schouten for the original patch.

 configure.in     |    2 ++
 oobs/oobs-user.c |   18 ++++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/configure.in b/configure.in
index 9bf5752..c71128a 100644
--- a/configure.in
+++ b/configure.in
@@ -75,6 +75,8 @@ AC_SUBST(HAL_CFLAGS)
 AC_CHECK_LIB(crypt, crypt, , [AC_MSG_ERROR(crypt library is required.)])
 AC_CHECK_HEADER(crypt.h, AC_DEFINE(HAVE_CRYPT_H, "", [whether it has crypt function]))
 
+AC_CHECK_HEADER(utmpx.h,,AC_MSG_ERROR([utmpx.h not found]))
+
 AC_MSG_CHECKING(whether rtnetlink exists)
 AC_TRY_CPP([
 #include <sys/types.h>
diff --git a/oobs/oobs-user.c b/oobs/oobs-user.c
index 4d632b7..b48e30b 100644
--- a/oobs/oobs-user.c
+++ b/oobs/oobs-user.c
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <crypt.h>
-#include <utmp.h>
+#include <utmpx.h>
 
 #include "oobs-object-private.h"
 #include "oobs-usersconfig.h"
@@ -1252,7 +1252,7 @@ oobs_user_set_locale (OobsUser *user, const gchar *locale)
 gboolean
 oobs_user_get_active (OobsUser *user)
 {
-  struct utmp *entry;
+  struct utmpx *entry;
   const gchar *login;
   gboolean match = FALSE;
 
@@ -1260,14 +1260,16 @@ oobs_user_get_active (OobsUser *user)
 
   login = oobs_user_get_login_name (user);
 
-  while (!match && (entry = getutent ()) != NULL)
-    {
-      match = (entry->ut_type == USER_PROCESS &&
-	       strcmp (entry->ut_user, login) == 0);
-    }
+  setutxent ();
+
+  while (!match && (entry = getutxent ()) != NULL)
+     {
+       match = (entry->ut_type == USER_PROCESS &&
+               strcmp (entry->ut_user, login) == 0);
+     }
 
   /* close utmp */
-  endutent ();
+  endutxent ();
 
   return match;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]