$NetBSD: patch-ak,v 1.4 2025/10/20 18:32:10 vins Exp $

* Try to get term name from terminal slaves.
* Use ut_session only when it is available in struct utmpx.
* If updwtmpx is not available, use pututxline instead.

--- src/logging.c.orig	2002-12-16 00:33:04.000000000 +0000
+++ src/logging.c
@@ -82,7 +82,8 @@ rxvt_makeutent(rxvt_t *r, const char *pt
     else if (sscanf(pty, "pts/%d", &i) == 1)
 	sprintf(ut_id, "vt%02x", (i & 0xff));	/* sysv naming */
 #endif
-    else if (STRNCMP(pty, "pty", 3) && STRNCMP(pty, "tty", 3)) {
+    else if (STRNCMP(pty, "pty", 3) && STRNCMP(pty, "tty", 3) &&
+	STRNCMP(pty, "pts/", 4)) {
 	rxvt_print_error("can't parse tty name \"%s\"", pty);
 	return;
     }
@@ -137,7 +138,9 @@ rxvt_makeutent(rxvt_t *r, const char *pt
     STRNCPY(utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?",
 	    sizeof(utx->ut_user));
     STRNCPY(utx->ut_id, ut_id, sizeof(utx->ut_id));
+# ifdef HAVE_UTMPX_SESSION
     utx->ut_session = getsid(0);
+# endif
     utx->ut_tv.tv_sec = time(NULL);
     utx->ut_tv.tv_usec = 0;
     utx->ut_pid = r->h->cmd_pid;
@@ -203,7 +206,11 @@ rxvt_makeutent(rxvt_t *r, const char *pt
 #  endif
 # endif
 # ifdef HAVE_STRUCT_UTMPX
+#  ifdef HAVE_UPDWTMPX
 	updwtmpx(RXVT_WTMPX_FILE, utx);
+#  else
+	pututxline(utx);
+#  endif
 # endif
     }
 #endif
@@ -254,7 +261,9 @@ rxvt_cleanutent(rxvt_t *r)
     if ((tmputx = getutxid(utx)))	/* position to entry in utmp file */
 	utx = tmputx;
     utx->ut_type = DEAD_PROCESS;
+# ifdef HAVE_UTMPX_SESSION
     utx->ut_session = getsid(0);
+# endif
     utx->ut_tv.tv_sec = time(NULL);
     utx->ut_tv.tv_usec = 0;
 #endif
@@ -275,7 +284,11 @@ rxvt_cleanutent(rxvt_t *r)
 #  endif
 # endif
 # ifdef HAVE_STRUCT_UTMPX
+#  ifdef HAVE_UPDWTMPX
 	updwtmpx(RXVT_WTMPX_FILE, utx);
+#  else
+	pututxline(utx);
+#  endif
 # endif
     }
 #endif
@@ -327,7 +340,7 @@ rxvt_write_bsd_utmp(int utmp_pos, struct
 /*
  * Update a BSD style wtmp entry
  */
-#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP)
+#if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP)
 /* INTPROTO */
 void
 rxvt_update_wtmp(const char *fname, const struct utmp *putmp)
