Wrapped setjmp(), sigsetjmp(), and vfork() calls to silence gcc -Wclobbered for good...
[mmh] / uip / rcvtty.c
index 31ca80a..1ae8576 100644 (file)
@@ -2,7 +2,9 @@
 /*
  * rcvtty.c -- a rcvmail program (a lot like rcvalert) handling IPC ttys
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 /* Changed to use getutent() and friends.  Assumes that when getutent() exists,
 
 #include <h/mh.h>
 #include <h/signals.h>
+#include <h/m_setjmp.h>
 #include <h/rcvmail.h>
 #include <h/scansbr.h>
-#include <zotnet/tws/tws.h>
-#include <zotnet/mts/mts.h>
+#include <h/tws.h>
+#include <h/mts.h>
 #include <signal.h>
 #include <fcntl.h>
 
@@ -76,7 +79,7 @@ char *getusername(void);
 /*
  * static prototypes
  */
-static RETSIGTYPE alrmser (int);
+static void alrmser (int);
 static int message_fd (char **);
 static int header_fd (void);
 static void alert (char *, int);
@@ -172,10 +175,14 @@ main (int argc, char **argv)
 #ifdef HAVE_GETUTENT
     setutent();
     while ((utp = getutent()) != NULL) {
-        if (utp->ut_type == USER_PROCESS 
-               && utp->ut_user[0] != 0
+        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);
         }
@@ -198,12 +205,10 @@ main (int argc, char **argv)
 }
 
 
-static RETSIGTYPE
+static void
 alrmser (int i)
 {
-#ifndef RELIABLE_SIGNALS
-    SIGNAL (SIGALRM, alrmser);
-#endif
+    NMH_UNUSED (i);
 
     longjmp (myctx, 1);
 }
@@ -217,22 +222,16 @@ message_fd (char **vec)
     char tmpfil[BUFSIZ];
     struct stat st;
 
-#ifdef HAVE_MKSTEMP
     fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)));
-#else
-    unlink (mktemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil))));
-    if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       return header_fd ();
-#endif
     unlink (tmpfil);
 
-    if ((child_id = vfork()) == NOTOK) {
+    if ((child_id = m_vfork()) == NOTOK) {
        /* fork error */
        close (fd);
        return header_fd ();
     } else if (child_id) {
        /* parent process */
-       if (!setjmp (myctx)) {
+       if (!m_setjmp (myctx)) {
            SIGNAL (SIGALRM, alrmser);
            bytes = fstat(fileno (stdin), &st) != NOTOK ? (int) st.st_size : 100;
 
@@ -257,7 +256,7 @@ message_fd (char **vec)
             * Ruthlessly kill the child and anything
             * else in its process group.
             */
-           KILLPG(child_id, SIGKILL);
+           killpg(child_id, SIGKILL);
        }
        close (fd);
        return header_fd ();
@@ -279,12 +278,12 @@ static int
 header_fd (void)
 {
     int fd;
-    char *nfs, tmpfil[BUFSIZ];
+    char *nfs;
+    char *tfile = NULL;
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       return NOTOK;
-    unlink (tmpfil);
+    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+    if (tfile == NULL) return NOTOK;
+    unlink (tfile);
 
     rewind (stdin);
 
@@ -318,7 +317,7 @@ alert (char *tty, int md)
     if (stat (ttyspec, &st) == NOTOK || (st.st_mode & mask) == 0)
        return;
 
-    if (!setjmp (myctx)) {
+    if (!m_setjmp (myctx)) {
        SIGNAL (SIGALRM, alrmser);
        alarm (2);
        td = open (ttyspec, O_WRONLY);