Handle utmpx on NetBSD-current.

This commit is contained in:
kim 2002-09-15 06:51:35 +00:00
parent 7721daae4f
commit fe233f7a84
9 changed files with 233 additions and 10 deletions

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.34 2002/07/05 08:05:55 tron Exp $
# $NetBSD: Makefile,v 1.35 2002/09/15 06:51:35 kim Exp $
DISTNAME= screen-3.9.11
PKGREVISION= 1
PKGREVISION= 2
CATEGORIES= misc
MASTER_SITES= ftp://ftp.uni-erlangen.de/pub/utilities/screen/ \
${MASTER_SITE_GNU:=screen/}

View file

@ -1,7 +1,13 @@
$NetBSD: distinfo,v 1.7 2002/05/21 17:57:04 tron Exp $
$NetBSD: distinfo,v 1.8 2002/09/15 06:51:36 kim Exp $
SHA1 (screen-3.9.11.tar.gz) = bcf97667f6018e82f566f363f4905d2c7d0c33a6
Size (screen-3.9.11.tar.gz) = 722396 bytes
SHA1 (patch-aa) = 870701007522e0fff1ea666e9e83e1b55470e258
SHA1 (patch-aa) = 57a7800823cf46c42011f7703fd9949bc614736d
SHA1 (patch-ab) = 97a465b4eefb0ec0cae3cd077f7c880cf46f3355
SHA1 (patch-ae) = 488f9df708f28ee1411afc48a2239e11ecbf7809
SHA1 (patch-ai) = a3d2c7d2ef3db9deb7a5e70ed7f906efd3196af6
SHA1 (patch-aj) = 8aa5c79e483e500ca9b3ed978835bbf1a866a5dc
SHA1 (patch-ak) = d80a6b113d31014bb643dae5b04b8dd7510462c5
SHA1 (patch-al) = 2f042d43030a9166f4c1bf19e4d473d1031aba4e
SHA1 (patch-am) = 5fdc32f33ebbb5385292919f6cd01bedc30491d9
SHA1 (patch-an) = 9c5f451edb228f10daf593eba79f1fb11b4ffb24

View file

@ -1,8 +1,8 @@
$NetBSD: patch-aa,v 1.8 2002/05/21 17:57:04 tron Exp $
$NetBSD: patch-aa,v 1.9 2002/09/15 06:51:37 kim Exp $
--- pty.c.orig Mon Feb 11 13:44:18 2002
+++ pty.c Tue May 21 19:55:36 2002
@@ -318,6 +318,47 @@
--- pty.c.orig Mon Feb 11 07:44:18 2002
+++ pty.c Mon Aug 5 19:58:48 2002
@@ -318,6 +318,45 @@
/***************************************************************/
@ -10,9 +10,7 @@ $NetBSD: patch-aa,v 1.8 2002/05/21 17:57:04 tron Exp $
+#define PTY_DONE
+
+#include <sys/param.h>
+
+#include <string.h>
+#include <util.h>
+
+int
+OpenPTY(ttyn)

View file

@ -0,0 +1,24 @@
$NetBSD: patch-ai,v 1.1 2002/09/15 06:51:37 kim Exp $
Use utmpx on NetBSD where available.
--- os.h.orig Tue Jan 8 10:42:33 2002
+++ os.h Sun Sep 15 01:47:33 2002
@@ -260,9 +260,15 @@
#endif
#if defined(UTMPOK) || defined(BUGGYGETLOGIN)
-# if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
+# if (defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)) \
+ || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106050000))
# include <utmpx.h>
-# define UTMPFILE UTMPX_FILE
+# ifdef __NetBSD__
+# define UTMPFILE _PATH_UTMPX
+# define NetBSD_UTMP
+# else
+# define UTMPFILE UTMPX_FILE
+# endif
# define utmp utmpx
# define getutent getutxent
# define getutid getutxid

View file

@ -0,0 +1,23 @@
$NetBSD: patch-aj,v 1.1 2002/09/15 06:51:38 kim Exp $
Detect getutent correctly on NetBSD with utmpx.
--- configure.in.orig Sat Sep 14 23:22:33 2002
+++ configure.in Sat Sep 14 23:37:06 2002
@@ -798,9 +798,15 @@
AC_TRY_LINK([
#include <time.h> /* to get time_t on SCO */
#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
+#include <sys/param.h>
+#if (defined(SVR4) && !defined(DGUX)) \
+ || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106050000))
#include <utmpx.h>
#define utmp utmpx
+# ifdef __NetBSD__
+# define pututline pututxline
+# define getutent getutxent
+# endif
#else
#include <utmp.h>
#endif

View file

@ -0,0 +1,24 @@
$NetBSD: patch-ak,v 1.1 2002/09/15 06:51:38 kim Exp $
The configure.in patch manually applied to configure, as
our autoreconf produces an extensively different result.
--- configure.orig Thu Feb 14 08:11:21 2002
+++ configure Sat Sep 14 23:44:07 2002
@@ -4077,9 +4077,15 @@
#include <time.h> /* to get time_t on SCO */
#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
+#include <sys/param.h>
+#if (defined(SVR4) && !defined(DGUX)) \
+ || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106050000))
#include <utmpx.h>
#define utmp utmpx
+# ifdef __NetBSD__
+# define pututline pututxline
+# define getutent getutxent
+# endif
#else
#include <utmp.h>
#endif

View file

@ -0,0 +1,41 @@
$NetBSD: patch-al,v 1.1 2002/09/15 06:51:39 kim Exp $
Make extra calls to remove utmp entries when utmpx is used.
For non-login entries we only update utmpx, as it stores
more information, and utilities are reading both.
--- utmp.c.orig Tue Jan 8 10:44:37 2002
+++ utmp.c Sun Sep 15 02:36:15 2002
@@ -47,6 +47,12 @@
extern int real_uid, eff_uid;
+#ifdef NetBSD_UTMP
+extern void utmp_login __P((char *));
+extern void utmp_logout __P((char *));
+#endif
+
+
/*
* UTNOKEEP: A (ugly) hack for apollo that does two things:
* 1) Always close and reopen the utmp file descriptor. (I don't know
@@ -314,6 +320,9 @@
ASSERT(display);
debug("RemoveLoginSlot: removing your logintty\n");
+#ifdef NetBSD_UTMP
+ utmp_logout(stripdev(D_usertty));
+#endif
D_loginslot = TtyNameSlot(D_usertty);
if (D_loginslot == (slot_t)0 || D_loginslot == (slot_t)-1)
return;
@@ -378,6 +387,9 @@
debug("RestoreLoginSlot()\n");
ASSERT(display);
+#ifdef NetBSD_UTMP
+ utmp_login(stripdev(D_usertty));
+#endif
if (utmpok && D_loginslot != (slot_t)0 && D_loginslot != (slot_t)-1)
{
debug1(" logging you in again (slot %#x)\n", (int)D_loginslot);

View file

@ -0,0 +1,88 @@
$NetBSD: patch-am,v 1.1 2002/09/15 06:51:39 kim Exp $
Code to handle the login slot in utmp when utmpx is available.
Daemons shipped with NetBSD tend to write to both, while 3rd
party software might write to only one.
--- /dev/null Sun Sep 15 02:36:51 2002
+++ utmp-netbsd.c Sun Sep 15 02:38:27 2002
@@ -0,0 +1,79 @@
+#include <sys/param.h>
+#if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106050000)
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <ttyent.h>
+#include <unistd.h>
+#include <util.h>
+#include <utmp.h>
+
+static struct utmp saved_utmp;
+static int saved_utmp_ok = 0;
+
+int
+lineslot(line)
+char *line;
+{
+ int slot;
+ struct ttyent *ttyp;
+
+ setttyent();
+ for (slot = 1; (ttyp = getttyent()) != NULL; ++slot)
+ if (!strcmp(ttyp->ty_name, line)) {
+ endttyent();
+ return(slot);
+ }
+ endttyent();
+ return(0);
+}
+
+void
+utmp_login(line)
+char *line;
+{
+ int fd;
+ int tty;
+
+ if (!saved_utmp_ok)
+ return;
+
+ tty = lineslot(line);
+ if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
+ (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
+ (void)write(fd, &saved_utmp, sizeof(struct utmp));
+ (void)close(fd);
+ }
+}
+
+void
+utmp_logout(const char *line)
+{
+ int fd;
+ struct utmp ut;
+
+ if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
+ return;
+ while (read(fd, &ut, sizeof(ut)) == sizeof(ut)) {
+ if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
+ continue;
+ memcpy(&saved_utmp, &ut, sizeof(ut));
+ saved_utmp_ok = 1;
+ memset(ut.ut_name, 0, UT_NAMESIZE);
+ memset(ut.ut_host, 0, UT_HOSTSIZE);
+ (void)time(&ut.ut_time);
+ (void)lseek(fd, -(off_t)sizeof(ut), SEEK_CUR);
+ (void)write(fd, &ut, sizeof(ut));
+ }
+ (void)close(fd);
+}
+
+#endif

View file

@ -0,0 +1,19 @@
$NetBSD: patch-an,v 1.1 2002/09/15 06:51:40 kim Exp $
--- Makefile.in.orig Thu Feb 14 08:36:33 2002
+++ Makefile.in Sun Sep 15 01:57:20 2002
@@ -55,12 +55,12 @@
search.c tty.c term.c window.c utmp.c loadav.c putenv.c help.c \
termcap.c input.c attacher.c pty.c process.c display.c comm.c \
kmapdef.c acls.c braille.c braille_tsi.c logfile.c layer.c \
- sched.c teln.c nethack.c encoding.c
+ sched.c teln.c nethack.c encoding.c utmp-netbsd.c
OFILES= screen.o ansi.o fileio.o mark.o misc.o resize.o socket.o \
search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o \
termcap.o input.o attacher.o pty.o process.o display.o comm.o \
kmapdef.o acls.o braille.o braille_tsi.o logfile.o layer.o \
- sched.o teln.o nethack.o encoding.o
+ sched.o teln.o nethack.o encoding.o utmp-netbsd.o
all: screen