Hi,

When I was upgrading the OpenBSD nmh package from 1.4 to 1.5rc1, the build
errored out, because OpenBSD does not have utmpx.h. Speaking with other
devs implies that this is unlikely to ever be supported on OpenBSD.

Reverting 7ba29497ff3f164e2a507eda35e81f1cb0658c74 lets nmh build again
on OpenBSD. Can this change be applied?

--
Anthony J. Bentley
--- configure.ac.orig   Mon Apr 23 12:04:51 2012
+++ configure.ac        Mon Apr 23 12:05:52 2012
@@ -424,7 +424,7 @@ AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTE
 dnl ---------------
 dnl CHECK FUNCTIONS
 dnl ---------------
-AC_CHECK_FUNCS([wcwidth mbtowc writev lstat nl_langinfo])
+AC_CHECK_FUNCS([wcwidth mbtowc writev lstat getutent nl_langinfo])
 
 dnl Check for multibyte character set support
 if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = 
"xyes" \
@@ -693,6 +693,8 @@ dnl For platforms such as FreeBSD that have tm_gmtoff 
 dnl (FreeBSD has a timezone() function but not a timezone global
 dnl variable that is visible).
 AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
+
+AC_CHECK_MEMBERS(struct utmp.ut_type,,,[#include <utmp.h>])
 
 AC_STRUCT_DIRENT_D_TYPE
 
--- uip/rcvtty.c.orig   Mon Apr 23 12:06:17 2012
+++ uip/rcvtty.c        Mon Apr 23 12:11:08 2012
@@ -22,8 +22,18 @@
 #include <signal.h>
 #include <fcntl.h>
 
-#include <utmpx.h>
+#include <utmp.h>
 
+#ifndef HAVE_GETUTENT
+# ifndef UTMP_FILE
+#  ifdef _PATH_UTMP
+#   define UTMP_FILE _PATH_UTMP
+#  else
+#   define UTMP_FILE "/etc/utmp"
+#  endif
+# endif
+#endif
+
 #define        SCANFMT \
 "%2(hour{dtimenow}):%02(min{dtimenow}): %<(size)%5(size) %>%<{encrypted}E%>\
 %<(mymbox{from})%<{to}To:%14(friendly{to})%>%>%<(zero)%17(friendly{from})%>  \
@@ -81,7 +91,13 @@ main (int argc, char **argv)
     int md, vecp = 0;
     char *cp, *user, buf[BUFSIZ], tty[BUFSIZ];
     char **argp, **arguments, *vec[MAXARGS];
-    struct utmpx *utp;
+#ifdef HAVE_GETUTENT
+    struct utmp *utp;
+#else
+    struct utmp ut;
+    register FILE *uf;
+#endif
+
 #ifdef LOCALE
     setlocale(LC_ALL, "");
 #endif
@@ -156,16 +172,33 @@ main (int argc, char **argv)
 
     user = getusername();
 
-    setutxent();
-    while ((utp = getutxent()) != NULL) {
-        if (utp->ut_type == USER_PROCESS && utp->ut_user[0] != 0
+#ifdef HAVE_GETUTENT
+    setutent();
+    while ((utp = getutent()) != NULL) {
+        if (
+#ifdef HAVE_STRUCT_UTMP_UT_TYPE
+              utp->ut_type == USER_PROCESS
+              &&
+#endif
+               utp->ut_name[0] != 0
                && utp->ut_line[0] != 0
-               && strncmp (user, utp->ut_user, sizeof(utp->ut_user)) == 0) {
+               && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) {
             strncpy (tty, utp->ut_line, sizeof(utp->ut_line));
            alert (tty, md);
         }
     }
-    endutxent();
+    endutent();
+#else
+    if ((uf = fopen (UTMP_FILE, "r")) == NULL)
+       exit (RCV_MBX);
+    while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1)
+       if (ut.ut_name[0] != 0
+               && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) {
+           strncpy (tty, ut.ut_line, sizeof(ut.ut_line));
+           alert (tty, md);
+       }
+    fclose (uf);
+#endif
 
     exit (RCV_MOK);
     return 0;  /* dead code to satisfy the compiler */
--- uip/slocal.c.orig   Mon Apr 23 12:12:20 2012
+++ uip/slocal.c        Mon Apr 23 12:15:01 2012
@@ -51,8 +51,18 @@
 #include NDBM_HEADER
 #endif
 
-#include <utmpx.h>
+#include <utmp.h>
 
+#ifndef HAVE_GETUTENT
+# ifndef UTMP_FILE
+#  ifdef _PATH_UTMP
+#   define UTMP_FILE _PATH_UTMP
+#  else
+#   define UTMP_FILE "/etc/utmp"
+#  endif
+# endif
+#endif
+
 static struct swit switches[] = {
 #define        ADDRSW         0
     { "addr address", 0 },
@@ -927,29 +937,62 @@ lookup (struct pair *pairs, char *key)
  * logged in.
  */
 
+#ifdef HAVE_GETUTENT
 static int
 logged_in (void)
 {
-    struct utmpx *utp;
+    struct utmp *utp;
 
     if (utmped)
         return utmped;
 
-    setutxent();
+    setutent();
 
-    while ((utp = getutxent()) != NULL) {
-        if ( utp->ut_type == USER_PROCESS && utp->ut_user[0] != 0
-                && strncmp (user, utp->ut_user, sizeof(utp->ut_user)) == 0) {
+    while ((utp = getutent()) != NULL) {
+        if (
+#ifdef HAVE_STRUCT_UTMP_UT_TYPE
+               utp->ut_type == USER_PROCESS
+                &&
+#endif
+               utp->ut_name[0] != 0
+                && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) {
             if (debug)
                 continue;
-            endutxent();
+            endutent();
             return (utmped = DONE);
         }
     }
 
-    endutxent();
+    endutent();
     return (utmped = NOTOK);
 }
+#else
+static int
+logged_in (void)
+{
+    struct utmp ut;
+    FILE *uf;
+
+    if (utmped)
+       return utmped;
+
+    if ((uf = fopen (UTMP_FILE, "r")) == NULL)
+       return NOTOK;
+
+    while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) {
+       if (ut.ut_name[0] != 0
+           && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) {
+           if (debug)
+               continue;
+           fclose (uf);
+           return (utmped = DONE);
+       }
+    }
+
+    fclose (uf);
+    return (utmped = NOTOK);
+}
+#endif
 
 #define        check(t,a,b)            if (t < a || t > b) return -1
 #define        cmpar(h1,m1,h2,m2)      if (h1 < h2 || (h1 == h2 && m1 < m2)) 
return 0
_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/nmh-workers

Reply via email to