This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FreeBSD port (52): platform dependent utmp comparison


'struct utmp' is platform dependent, while 'struct utmpx' is standardized.
On FreeBSD I want to reuse most of sysdeps/generic/utmp_file.c; it's
quite an important logic. The only difference needs to be the function
which compares an utmp entry with an utmp pattern. I propose to make
this a separate function with platform dependent implementation.


2002-09-04  Bruno Haible  <bruno@clisp.org>

	* login/utmp-private.h (__utmp_equal): New declaration.
	* sysdeps/generic/utmp_equal.c: New file, extracted from utmp_file.c.
	* sysdeps/generic/utmp_file.c (proc_utmp_eq): Remove function.
	(internal_getut_r, pututline_file): Call __utmp_equal instead.
	* login/Makefile (routines): Add utmp_equal.

diff -r -c3 glibc-20020828.bak/login/Makefile glibc-20020828/login/Makefile
*** glibc-20020828.bak/login/Makefile	Wed Jan  2 16:06:49 2002
--- glibc-20020828/login/Makefile	Wed Sep  4 04:16:30 2002
***************
*** 1,4 ****
! # Copyright (C) 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
  # This file is part of the GNU C Library.
  
  # The GNU C Library is free software; you can redistribute it and/or
--- 1,4 ----
! # Copyright (C) 1996-1998, 2000-2002 Free Software Foundation, Inc.
  # This file is part of the GNU C Library.
  
  # The GNU C Library is free software; you can redistribute it and/or
***************
*** 25,31 ****
  headers	:= utmp.h bits/utmp.h lastlog.h pty.h
  
  routines := getutent getutent_r getutid getutline getutid_r getutline_r \
! 	    utmp_file utmpname updwtmp getpt grantpt unlockpt ptsname
  
  CFLAGS-grantpt.c = -DLIBEXECDIR='"$(libexecdir)"'
  
--- 25,32 ----
  headers	:= utmp.h bits/utmp.h lastlog.h pty.h
  
  routines := getutent getutent_r getutid getutline getutid_r getutline_r \
! 	    utmp_equal utmp_file utmpname updwtmp \
! 	    getpt grantpt unlockpt ptsname
  
  CFLAGS-grantpt.c = -DLIBEXECDIR='"$(libexecdir)"'
  
diff -r -c3 glibc-20020828.bak/login/utmp-private.h glibc-20020828/login/utmp-private.h
*** glibc-20020828.bak/login/utmp-private.h	Thu Apr  4 20:11:23 2002
--- glibc-20020828/login/utmp-private.h	Fri Aug 30 11:04:31 2002
***************
*** 46,49 ****
--- 46,52 ----
  /* Current file name.  */
  extern const char *__libc_utmp_file_name attribute_hidden;
  
+ /* Test whether two entries match.  */
+ extern int __utmp_equal (const struct utmp *entry1, const struct utmp *entry2);
+ 
  #endif /* utmp-private.h */
diff -r -c3 glibc-20020828.bak/sysdeps/generic/utmp_file.c glibc-20020828/sysdeps/generic/utmp_file.c
*** glibc-20020828.bak/sysdeps/generic/utmp_file.c	Mon Aug 26 15:49:59 2002
--- glibc-20020828/sysdeps/generic/utmp_file.c	Fri Aug 30 11:04:33 2002
***************
*** 200,232 ****
  
  
  static int
- proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
- {
-   return
-     (
- #if _HAVE_UT_TYPE - 0
-      (entry->ut_type == INIT_PROCESS
-       || entry->ut_type == LOGIN_PROCESS
-       || entry->ut_type == USER_PROCESS
-       || entry->ut_type == DEAD_PROCESS)
-      &&
-      (match->ut_type == INIT_PROCESS
-       || match->ut_type == LOGIN_PROCESS
-       || match->ut_type == USER_PROCESS
-       || match->ut_type == DEAD_PROCESS)
-      &&
- #endif
- #if _HAVE_UT_ID - 0
-      (entry->ut_id[0] && match->ut_id[0]
-       ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
-       : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
- #else
-      strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
- #endif
-      );
- }
- 
- static int
  internal_getut_r (const struct utmp *id, struct utmp *buffer)
  {
    int result = -1;
--- 200,205 ----
***************
*** 275,281 ****
  	    }
  	  file_offset += sizeof (struct utmp);
  
! 	  if (proc_utmp_eq (buffer, id))
  	    break;
  	}
      }
--- 248,254 ----
  	    }
  	  file_offset += sizeof (struct utmp);
  
! 	  if (__utmp_equal (buffer, id))
  	    break;
  	}
      }
***************
*** 390,396 ****
  	       || last_entry.ut_type == NEW_TIME))
  	  ||
  #endif
! 	  proc_utmp_eq (&last_entry, data)))
      found = 1;
    else
      found = internal_getut_r (data, &buffer);
--- 363,369 ----
  	       || last_entry.ut_type == NEW_TIME))
  	  ||
  #endif
! 	  __utmp_equal (&last_entry, data)))
      found = 1;
    else
      found = internal_getut_r (data, &buffer);
*** /dev/null	Thu Sep  5 02:03:34 2002
--- glibc-20020828/sysdeps/generic/utmp_equal.c	Wed Jul 24 00:22:56 2002
***************
*** 0 ****
--- 1,51 ----
+ /* Copyright (C) 1996-1999,2000-2002 Free Software Foundation, Inc.
+    This file is part of the GNU C Library.
+    Contributed by Ulrich Drepper <drepper@cygnus.com>
+    and Paul Janzen <pcj@primenet.com>, 1996.
+ 
+    The GNU C Library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+ 
+    The GNU C Library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+ 
+    You should have received a copy of the GNU Lesser General Public
+    License along with the GNU C Library; if not, write to the Free
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+ 
+ #include <string.h>
+ #include <utmp.h>
+ 
+ #include "utmp-private.h"
+ 
+ int
+ __utmp_equal (const struct utmp *entry, const struct utmp *match)
+ {
+   return
+     (
+ #if _HAVE_UT_TYPE - 0
+      (entry->ut_type == INIT_PROCESS
+       || entry->ut_type == LOGIN_PROCESS
+       || entry->ut_type == USER_PROCESS
+       || entry->ut_type == DEAD_PROCESS)
+      &&
+      (match->ut_type == INIT_PROCESS
+       || match->ut_type == LOGIN_PROCESS
+       || match->ut_type == USER_PROCESS
+       || match->ut_type == DEAD_PROCESS)
+      &&
+ #endif
+ #if _HAVE_UT_ID - 0
+      (entry->ut_id[0] && match->ut_id[0]
+       ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
+       : strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0)
+ #else
+      strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
+ #endif
+      );
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]