From 301cbd433bb698147e05e7dbfb4de2ce2e0e9cbb Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Fri, 24 Jun 2011 15:46:43 +0200 Subject: Use Autoconf to check for utmp field existence. Don't use the quirky SYSV and __QNX__ definitions to determine whether the utmp fields exist. Signed-off-by: Ed Schouten Signed-off-by: Alan Coopersmith --- configure.ac | 5 +++++ sessreg.c | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index c7e5e90..be90cf3 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,11 @@ XORG_WITH_LINT AC_CHECK_HEADERS([lastlog.h utmp.h utmpx.h sys/param.h]) # Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_MEMBERS([ + struct utmp.ut_host, + struct utmp.ut_id, + struct utmp.ut_pid, + struct utmp.ut_type], [], [], [#include ]) AC_CHECK_MEMBERS([struct utmpx.ut_syslen], [], [], [#include ]) # Checks for library functions. diff --git a/sessreg.c b/sessreg.c index 6bd593a..9ce4653 100644 --- a/sessreg.c +++ b/sessreg.c @@ -399,7 +399,7 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a (void) strncpy (u->ut_name, user, sizeof (u->ut_name)); else bzero (u->ut_name, sizeof (u->ut_name)); -#ifdef SYSV +#ifdef HAVE_STRUCT_UTMP_UT_ID if (line) { int i; /* @@ -417,15 +417,20 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a (void) strncpy (u->ut_id, line + i, sizeof (u->ut_id)); } else bzero (u->ut_id, sizeof (u->ut_id)); - if (addp) { +#endif +#ifdef HAVE_STRUCT_UTMP_UT_PID + if (addp) u->ut_pid = getppid (); - u->ut_type = USER_PROCESS; - } else { + else u->ut_pid = 0; +#endif +#ifdef HAVE_STRUCT_UTMP_UT_TYPE + if (addp) + u->ut_type = USER_PROCESS; + else u->ut_type = DEAD_PROCESS; - } #endif -#if (!defined(SYSV) && !defined(__QNX__)) || defined(linux) +#ifdef HAVE_STRUCT_UTMP_UT_HOST if (addp && host) (void) strncpy (u->ut_host, host, sizeof (u->ut_host)); else @@ -633,7 +638,7 @@ findslot (char *line_name, char *host_name, int addp, int slot) while (read (utmp, (char *) &entry, sizeof (entry)) == sizeof (entry)) { if (strncmp(entry.ut_line, line_name, sizeof(entry.ut_line)) == 0 -#ifndef __QNX__ +#ifdef HAVE_STRUCT_UTMP_UT_HOST && strncmp(entry.ut_host, host_name, sizeof(entry.ut_host)) == 0 -- cgit v1.2.3