Ugh,

It seems there are more things that can be improved here. Please see the
attached set of patches. The previous email can be ignored.

Greetings,
-- 
 Ed Schouten <[email protected]>
 WWW: http://80386.nl/
From 42e3ce68f68471ff714167b0e2860c36dda82efd Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sat, 25 Jun 2011 10:35:25 +0200
Subject: [PATCH 1/7] Don't forget to include <sys/types.h> before <utmp.h>.

Some operating systems (e.g. FreeBSD) require <sys/types.h> to be
included before <utmp.h>, because they depend on type definitions such
as int32_t, time_t, etc.

Signed-off-by: Ed Schouten <[email protected]>
---
 configure.ac |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index be90cf3..6d616ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,7 +48,10 @@ AC_CHECK_MEMBERS([
 	struct utmp.ut_host,
 	struct utmp.ut_id,
 	struct utmp.ut_pid,
-	struct utmp.ut_type], [], [], [#include <utmp.h>])
+	struct utmp.ut_type], [], [], [
+	#include <sys/types.h>
+	#include <utmp.h>
+	])
 AC_CHECK_MEMBERS([struct utmpx.ut_syslen], [], [], [#include <utmpx.h>])
 
 # Checks for library functions.
-- 
1.7.5.4

From df1052ff70922671d6a5d95b0c169d5d8a315585 Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 09:43:37 +0200
Subject: [PATCH 2/7] Get rid of SYSV definition. Just check for pututline().

If the system provides pututline(), we just want to use that, instead of
specifically checking for certain operating systems.

Signed-off-by: Ed Schouten <[email protected]>
---
 configure.ac |    2 +-
 sessreg.c    |   20 ++++++++------------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6d616ae..739abfa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,7 +55,7 @@ AC_CHECK_MEMBERS([
 AC_CHECK_MEMBERS([struct utmpx.ut_syslen], [], [], [#include <utmpx.h>])
 
 # Checks for library functions.
-AC_CHECK_FUNCS([updwtmpx utmpxname])
+AC_CHECK_FUNCS([pututline updwtmpx utmpxname])
 
 # Obtain compiler/linker options for depedencies
 PKG_CHECK_MODULES(SESSREG, xproto)
diff --git a/sessreg.c b/sessreg.c
index 7bce6ef..899b070 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -77,10 +77,6 @@
 # include	<stdio.h>
 # include	<stdlib.h>
 
-#if defined(__SVR4) || defined(SVR4) || defined(linux) || defined(__GLIBC__)
-# define SYSV
-#endif
-
 #include <time.h>
 #define Time_t time_t
 
@@ -111,7 +107,7 @@ static int utmp_none, wtmp_none;
  */
 static int hflag, sflag, xflag, tflag;
 static char *host_name = NULL;
-#ifdef USE_UTMP
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 static int slot_number;
 #endif
 static char *xservers_file, *ttys_file;
@@ -124,7 +120,7 @@ static int llog_none, Lflag;
 
 static char *program_name;
 
-#ifndef SYSV
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 static int findslot (char *line_name, char *host_name, int addp, int slot);
 static int Xslot (char *ttys_file, char *servers_file, char *tty_line,
 		  char *host_name, int addp);
@@ -160,7 +156,7 @@ getstring (char ***avp, int *flagp)
 	return *a;
 }
 
-#ifndef SYSV
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 static int
 syserr (int x, const char *s)
 {
@@ -185,7 +181,7 @@ sysnerr (int x, const char *s)
 int
 main (int argc, char **argv)
 {
-#if defined(USE_UTMP) && !defined(SYSV)
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 	int		utmp;
 #endif
 #ifndef USE_UTMPX
@@ -229,7 +225,7 @@ main (int argc, char **argv)
 			host_name = getstring (&argv, &hflag);
 			break;
 		case 's':
-#ifdef USE_UTMP
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 			slot_number = atoi (getstring (&argv, &sflag));
 #endif
 			break;
@@ -275,7 +271,7 @@ main (int argc, char **argv)
 	if (!Lflag)
 		llog_file = LLOG_FILE;
 #endif
-#if defined(USE_UTMP) && !defined(SYSV) && !defined(linux) && !defined(__QNX__)
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 	if (!tflag)
 		ttys_file = TTYS_FILE;
 	if (!sflag && !utmp_none) {
@@ -320,7 +316,7 @@ main (int argc, char **argv)
 		}
 #endif
 #ifdef USE_UTMP
-# ifdef SYSV
+# ifdef HAVE_PUTUTLINE
 		utmpname (utmp_file);
 		setutent ();
 		(void) getutid (&utmp_entry);
@@ -546,7 +542,7 @@ set_utmpx (struct utmpx *u, const char *line, const char *user,
 }
 #endif /* USE_UTMPX */
 
-#if defined(USE_UTMP) && !defined(SYSV)
+#if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
 /*
  * compute the slot-number for an X display.  This is computed
  * by counting the lines in /etc/ttys and adding the line-number
-- 
1.7.5.4

From 2e5eb9a3665ba4d1ca80da6b74074510fc9c04e0 Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 09:47:40 +0200
Subject: [PATCH 3/7] Only expose the sflag variable when needed.

The sflag variable is only used when using BSD-style utmp.

Signed-off-by: Ed Schouten <[email protected]>
---
 sessreg.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/sessreg.c b/sessreg.c
index 899b070..671f257 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -105,9 +105,10 @@ static int utmp_none, wtmp_none;
  * BSD specific variables.  To make life much easier for Xstartup/Xreset
  * maintainers, these arguments are accepted but ignored for sysV
  */
-static int hflag, sflag, xflag, tflag;
+static int hflag, xflag, tflag;
 static char *host_name = NULL;
 #if defined(USE_UTMP) && !defined(HAVE_PUTUTLINE)
+static int sflag;
 static int slot_number;
 #endif
 static char *xservers_file, *ttys_file;
-- 
1.7.5.4

From 17a5fa05323ce198ee831f804dc5e7e0813fd713 Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 09:51:01 +0200
Subject: [PATCH 4/7] Just use time_t directly.

There is no use for this #define (anymore). We can already assume that
any decent system has time_t defined. It has to, otherwise struct utmp
and struct utmpx can't even be defined.

Signed-off-by: Ed Schouten <[email protected]>
---
 sessreg.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/sessreg.c b/sessreg.c
index 671f257..7aad1b6 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -78,16 +78,15 @@
 # include	<stdlib.h>
 
 #include <time.h>
-#define Time_t time_t
 
 #ifdef USE_UTMP
 static void set_utmp (struct utmp *u, char *line, char *user, char *host,
-		      Time_t date, int addp);
+		      time_t date, int addp);
 #endif
 
 #ifdef USE_UTMPX
 static void set_utmpx (struct utmpx *u, const char *line, const char *user,
-		       const char *host, Time_t date, int addp);
+		       const char *host, time_t date, int addp);
 #endif
 
 static int wflag, uflag, lflag;
@@ -188,7 +187,7 @@ main (int argc, char **argv)
 #ifndef USE_UTMPX
 	int		wtmp;
 #endif
-	Time_t		current_time;
+	time_t		current_time;
 #ifdef USE_UTMP
 	struct utmp	utmp_entry;
 #endif
@@ -385,7 +384,7 @@ main (int argc, char **argv)
 
 #ifdef USE_UTMP
 static void
-set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int addp)
+set_utmp (struct utmp *u, char *line, char *user, char *host, time_t date, int addp)
 {
 	memset (u, 0, sizeof (*u));
 	if (line)
@@ -462,7 +461,7 @@ UtmpxIdOpen( char *utmpId )
 
 static void
 set_utmpx (struct utmpx *u, const char *line, const char *user,
-	   const char *host, Time_t date, int addp)
+	   const char *host, time_t date, int addp)
 {
 	static const char letters[] =
 	       "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-- 
1.7.5.4

From 10286c41dd0eceb6e0294302e7f55859279ccc08 Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 10:15:59 +0200
Subject: [PATCH 5/7] Fix whitespace inconsistencies.


Signed-off-by: Ed Schouten <[email protected]>
---
 sessreg.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/sessreg.c b/sessreg.c
index 7aad1b6..67c1b6d 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -72,11 +72,10 @@
 
 #include "sessreg.h"
 
-# include	<X11/Xos.h>
-# include	<X11/Xfuncs.h>
-# include	<stdio.h>
-# include	<stdlib.h>
-
+#include <X11/Xos.h>
+#include <X11/Xfuncs.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <time.h>
 
 #ifdef USE_UTMP
@@ -486,7 +485,7 @@ set_utmpx (struct utmpx *u, const char *line, const char *user,
 		memset (u->ut_user, 0, sizeof (u->ut_user));
 
 	if (line) {
-		int     i;
+		int	i;
 		/*
 		 * this is a bit crufty, but
 		 * follows the apparent conventions in
@@ -570,9 +569,9 @@ Xslot (char *ttys_file, char *servers_file, char *tty_line, char *host_name,
 	strncpy(disp_name, host_name ? host_name : tty_line, sizeof(disp_name)-1);
 	pos = strrchr(disp_name, ':');
 	if (pos) {
-	    pos = strchr(pos, '.');
-	    if (pos)
-		*pos = '\0';
+		pos = strchr(pos, '.');
+		if (pos)
+			*pos = '\0';
 	}
 	sysnerr ((int)(long)(ttys = fopen (ttys_file, "r")), ttys_file);
 	while ((c = getc (ttys)) != EOF)
-- 
1.7.5.4

From 7c96341f30ae6cde01f3d0429e6b6705c22c9c2a Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 13:50:36 +0200
Subject: [PATCH 6/7] Simply define LLOG_FILE and TTYS_FILE unconditionally.

It doesn't matter if we define these pathnames, even if we're not going
to use them in the code itself. It is already done that way for utmp and
wtmp.

Signed-off-by: Ed Schouten <[email protected]>
---
 sessreg.h |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/sessreg.h b/sessreg.h
index cf721c8..0b93dc7 100644
--- a/sessreg.h
+++ b/sessreg.h
@@ -103,18 +103,13 @@
 #  define UTMP_FILE	"/etc/utmp"
 # endif
 #endif
-#ifndef NO_LASTLOG
-# ifndef LLOG_FILE
-#  ifdef _PATH_LASTLOG
-#   define LLOG_FILE	_PATH_LASTLOG
-#  else
-#   define LLOG_FILE	"/usr/adm/lastlog"
-#  endif
+#ifndef LLOG_FILE
+# ifdef _PATH_LASTLOG
+#  define LLOG_FILE	_PATH_LASTLOG
+# else
+#  define LLOG_FILE	"/usr/adm/lastlog"
 # endif
 #endif
-#ifndef SYSV
-# ifndef TTYS_FILE
-#  define TTYS_FILE	"/etc/ttys"
-# endif
+#ifndef TTYS_FILE
+# define TTYS_FILE	"/etc/ttys"
 #endif
-
-- 
1.7.5.4

From 965088a492fb4cfa3a942665df3168b2912c81bf Mon Sep 17 00:00:00 2001
From: Ed Schouten <[email protected]>
Date: Sun, 26 Jun 2011 14:04:20 +0200
Subject: [PATCH 7/7] Make lastlog work on BSD systems without <lastlog.h>.

FreeBSD 8.x and lower have struct lastlog in <utmp.h>. Add a specific
Autoconf check for struct lastlog, where we include both <utmp.h> and
<lastlog.h>.

Also, change NO_LASTLOG to a definition for the opposite; USE_LASTLOG.
This is more consistent with USE_UTMP and USE_UTMPX.

Signed-off-by: Ed Schouten <[email protected]>
---
 configure.ac |   12 +++++++++++-
 sessreg.c    |   12 ++++++------
 sessreg.h    |   17 +++++------------
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/configure.ac b/configure.ac
index 739abfa..98061b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,7 +41,7 @@ XORG_DEFAULT_OPTIONS
 XORG_WITH_LINT
 
 # Checks for header files.
-AC_CHECK_HEADERS([lastlog.h utmp.h utmpx.h sys/param.h])
+AC_CHECK_HEADERS([lastlog.h pwd.h utmp.h utmpx.h sys/param.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_MEMBERS([
@@ -53,6 +53,16 @@ AC_CHECK_MEMBERS([
 	#include <utmp.h>
 	])
 AC_CHECK_MEMBERS([struct utmpx.ut_syslen], [], [], [#include <utmpx.h>])
+AC_CHECK_TYPES([
+	struct lastlog], [], [],[
+	#include <sys/types.h>
+	#ifdef HAVE_UTMP_H
+	#include <utmp.h>
+	#endif
+	#ifdef HAVE_LASTLOG_H
+	#include <lastlog.h>
+	#endif
+	])
 
 # Checks for library functions.
 AC_CHECK_FUNCS([pututline updwtmpx utmpxname])
diff --git a/sessreg.c b/sessreg.c
index 67c1b6d..d445498 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -61,7 +61,7 @@
  *
  * usage: sessreg [ -w <wtmp-file> ] [ -u <utmp-file> ]
  *		  [ -l <line> ]
- *		  [ -L <lastlog-file> ]		      / #ifndef NO_LASTLOG
+ *		  [ -L <lastlog-file> ]		      / #ifdef USE_LASTLOG
  *		  [ -h <host-name> ]				/ BSD only
  *		  [ -s <slot-number> ] [ -x Xservers-file ]	/ BSD only
  *		  [ -t <ttys-file> ]				/ BSD only
@@ -112,7 +112,7 @@ static int slot_number;
 static char *xservers_file, *ttys_file;
 static char *user_name;
 static int aflag, dflag;
-#ifndef NO_LASTLOG
+#ifdef USE_LASTLOG
 static char *llog_file;
 static int llog_none, Lflag;
 #endif
@@ -130,7 +130,7 @@ usage (int x)
 {
 	if (x) {
 		fprintf (stderr, "%s: usage %s {-a -d} [-w wtmp-file] [-u utmp-file]", program_name, program_name);
-#ifndef NO_LASTLOG
+#ifdef USE_LASTLOG
 		fprintf (stderr, " [-L lastlog-file]");
 #endif
 		fprintf (stderr, "\n");
@@ -207,7 +207,7 @@ main (int argc, char **argv)
 			if (!strcmp (utmp_file, "none"))
 				utmp_none = 1;
 			break;
-#ifndef NO_LASTLOG
+#ifdef USE_LASTLOG
 		case 'L':
 			llog_file = getstring (&argv, &Lflag);
 			if (!strcmp (llog_file, "none"))
@@ -266,7 +266,7 @@ main (int argc, char **argv)
 #else
 	utmp_none = 1;
 #endif
-#ifndef NO_LASTLOG
+#ifdef USE_LASTLOG
 	if (!Lflag)
 		llog_file = LLOG_FILE;
 #endif
@@ -348,7 +348,7 @@ main (int argc, char **argv)
 		}
 #endif
 	}
-#ifndef NO_LASTLOG
+#ifdef USE_LASTLOG
 	if (aflag && !llog_none) {
 		int llog;
 		struct passwd *pwd = getpwnam(user_name);
diff --git a/sessreg.h b/sessreg.h
index 0b93dc7..a5e7f83 100644
--- a/sessreg.h
+++ b/sessreg.h
@@ -67,19 +67,12 @@
 # include <sys/param.h>
 #endif
 
-#ifndef HAVE_LASTLOG_H
-# define NO_LASTLOG
-#endif
-
-#ifndef NO_LASTLOG
-# ifdef CSRG_BASED
-#  if (BSD < 199103)
-#   include	<lastlog.h>
-#  endif
-# else
-#  include	<lastlog.h>
+#if defined(HAVE_STRUCT_LASTLOG) && defined(HAVE_PWD_H)
+# ifdef HAVE_LASTLOG_H
+#  include <lastlog.h>
 # endif
-# include	<pwd.h>
+# include <pwd.h>
+# define USE_LASTLOG
 #endif
 
 #ifdef CSRG_BASED
-- 
1.7.5.4

Attachment: pgpLgBWSvJ47L.pgp
Description: PGP signature

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to