X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Frcvtty.c;h=1ae85765e1e27b51db605c99fe6237a79cdc474a;hb=4548981fb45fbc917cc2c26b7c96b31cfa14bc9b;hp=31ca80ab42746021d7047d4214d10fcf6c7ffa3b;hpb=522138c8d86c20435f045eaee0944a9b008b1c5a;p=mmh diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 31ca80a..1ae8576 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -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, @@ -12,10 +14,11 @@ #include #include +#include #include #include -#include -#include +#include +#include #include #include @@ -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);