From 164be8e5e8b40ce4572281be26d423a9c9d595f3 Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Sun, 25 Dec 2011 12:09:21 -0800 Subject: [PATCH] Clean up process wait to use POSIX waitpid() interface. --- configure.in | 28 ---------------------------- h/prototypes.h | 2 -- sbr/Makefile.in | 2 +- sbr/lock_file.c | 10 ---------- sbr/pidstatus.c | 4 ---- sbr/pidwait.c | 17 ----------------- uip/mhbuild.c | 4 ---- uip/mhbuildsbr.c | 4 ---- uip/mhcachesbr.c | 4 ---- uip/mhlist.c | 4 ---- uip/mhn.c | 4 ---- uip/mhoutsbr.c | 4 ---- uip/mhparse.c | 4 ---- uip/mhshow.c | 4 ---- uip/mhshowsbr.c | 20 -------------------- uip/mhstore.c | 4 ---- uip/mhtest.c | 4 ---- uip/rcvtty.c | 6 ------ uip/spost.c | 13 ------------- uip/viamail.c | 4 ---- 20 files changed, 1 insertion(+), 145 deletions(-) diff --git a/configure.in b/configure.in index 01dbcf8..a933613 100644 --- a/configure.in +++ b/configure.in @@ -806,34 +806,6 @@ AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, AC_CHECK_MEMBERS(struct utmp.ut_type,,,[#include ]) -AC_MSG_CHECKING(for union wait) -AC_CACHE_VAL(nmh_cv_union_wait, [dnl - AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include -#include ]], - [[union wait status; int pid; pid = wait (&status); -#ifdef WEXITSTATUS -/* Some POSIXoid systems have both the new-style macros and the old - union wait type, and they do not work together. If union wait - conflicts with WEXITSTATUS et al, we don't want to use it at all. */ - if (WEXITSTATUS (status) != 0) pid = -1; -#ifdef WTERMSIG - /* If we have WEXITSTATUS and WTERMSIG, just use them on ints. */ - -- blow chunks here -- -#endif -#endif -#ifdef HAVE_WAITPID - /* Make sure union wait works with waitpid. */ - pid = waitpid (-1, &status, 0); -#endif - ]])], - [nmh_cv_union_wait=yes], - [nmh_cv_union_wait=no])]) -if test "$nmh_cv_union_wait" = yes; then - AC_DEFINE(HAVE_UNION_WAIT, 1, - [Define to 1 if you have the \`union wait' type in .]) -fi -AC_MSG_RESULT($nmh_cv_union_wait) - CHECK_TYPE_STRUCT_DIRENT_D_TYPE() dnl ------------- diff --git a/h/prototypes.h b/h/prototypes.h index d88cf8e..1c55136 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -77,8 +77,6 @@ char *m_maildir (char *); char *m_mailpath (char *); char *m_name (int); int m_putenv (char *, char *); -char *m_scratch (char *, char *); -char *m_tmpfil (char *); char *m_mktemp(const char *, int *, FILE **); char *m_mktemp2(const char *, const char *, int *, FILE **); void m_unknown(FILE *); diff --git a/sbr/Makefile.in b/sbr/Makefile.in index 5bb3f22..83af141 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -61,7 +61,7 @@ SRCS = addrsbr.c ambigsw.c atooi.c brkstring.c \ fmt_addr.c fmt_compile.c fmt_new.c fmt_rfc2047.c \ fmt_scan.c lock_file.c m_atoi.c m_backup.c \ m_convert.c m_draft.c m_getfld.c m_gmprot.c \ - m_maildir.c m_name.c m_scratch.c m_tmpfil.c \ + m_maildir.c m_name.c \ makedir.c mts.c norm_charmap.c \ path.c peekc.c pidwait.c pidstatus.c \ print_help.c print_sw.c print_version.c push.c \ diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 0e14e8d..83cf01a 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -431,18 +431,8 @@ lockit (struct lockinfo *li) curlock = li->curlock; tmplock = li->tmplock; -#ifdef HAVE_MKSTEMP if ((fd = mkstemp(tmplock)) == -1) return -1; -#else - if (mktemp(tmplock) == NULL) - return -1; - if (unlink(tmplock) == -1 && errno != ENOENT) - return -1; - /* create the temporary lock file */ - if ((fd = creat(tmplock, 0600)) == -1) - return -1; -#endif #if 0 /* write our process id into lock file */ diff --git a/sbr/pidstatus.c b/sbr/pidstatus.c index f16f7e0..7da78ac 100644 --- a/sbr/pidstatus.c +++ b/sbr/pidstatus.c @@ -14,10 +14,6 @@ */ #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - #ifndef WTERMSIG # define WTERMSIG(s) ((int)((s) & 0x7F)) #endif diff --git a/sbr/pidwait.c b/sbr/pidwait.c index ef42e1a..f454161 100644 --- a/sbr/pidwait.c +++ b/sbr/pidwait.c @@ -12,21 +12,13 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - int pidwait (pid_t id, int sigsok) { pid_t pid; SIGNAL_HANDLER istat = NULL, qstat = NULL; -#ifdef HAVE_UNION_WAIT - union wait status; -#else int status; -#endif if (sigsok == -1) { /* ignore a couple of signals */ @@ -34,13 +26,8 @@ pidwait (pid_t id, int sigsok) qstat = SIGNAL (SIGQUIT, SIG_IGN); } -#ifdef HAVE_WAITPID while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR) ; -#else - while ((pid = wait(&status)) != -1 && pid != id) - continue; -#endif if (sigsok == -1) { /* reset the signal handlers */ @@ -48,9 +35,5 @@ pidwait (pid_t id, int sigsok) SIGNAL (SIGQUIT, qstat); } -#ifdef HAVE_UNION_WAIT - return (pid == -1 ? -1 : status.w_status); -#else return (pid == -1 ? -1 : status); -#endif } diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 1e86290..d7a3cf0 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define CHECKSW 0 { "check", 0 }, diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index f01abd5..a36941f 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -38,10 +38,6 @@ # endif #endif -#ifdef HAVE_SYS_WAIT_H -# include -#endif - extern int debugsw; extern int verbosw; diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 2223e80..79d6bda 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -32,10 +32,6 @@ # endif #endif -#ifdef HAVE_SYS_WAIT_H -# include -#endif - extern int debugsw; extern pid_t xpid; /* mhshowsbr.c or mhbuildsbr.c */ diff --git a/uip/mhlist.c b/uip/mhlist.c index cb6a3cf..6ef455d 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define CHECKSW 0 { "check", 0 }, diff --git a/uip/mhn.c b/uip/mhn.c index a7644a3..2ce21d3 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define AUTOSW 0 { "auto", 0 }, diff --git a/uip/mhoutsbr.c b/uip/mhoutsbr.c index 7e12c46..2651452 100644 --- a/uip/mhoutsbr.c +++ b/uip/mhoutsbr.c @@ -19,10 +19,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - extern int ebcdicsw; diff --git a/uip/mhparse.c b/uip/mhparse.c index d40d78c..14322ab 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - extern int debugsw; diff --git a/uip/mhshow.c b/uip/mhshow.c index 191eeff..722dcf6 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define CHECKSW 0 { "check", 0 }, diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 368b25c..d3397ae 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - /* * Just use sigjmp/longjmp on older machines that * don't have sigsetjmp/siglongjmp. @@ -132,11 +128,7 @@ show_single_message (CT ct, char *form) { sigset_t set, oset; -#ifdef HAVE_UNION_WAIT - union wait status; -#else int status; -#endif /* Allow user executable bit so that temporary directories created by * the viewer (e.g., lynx) are going to be accessible */ @@ -170,11 +162,7 @@ show_single_message (CT ct, char *form) SIGPROCMASK (SIG_BLOCK, &set, &oset); while (wait (&status) != NOTOK) { -#ifdef HAVE_UNION_WAIT - pidcheck (status.w_status); -#else pidcheck (status); -#endif continue; } @@ -783,11 +771,7 @@ show_multi_internal (CT ct, int serial, int alternate) if (serial && !nowserial) { pid_t pid; int kids; -#ifdef HAVE_UNION_WAIT - union wait status; -#else int status; -#endif kids = 0; for (part = m->mp_parts; part; part = part->mp_next) { @@ -802,11 +786,7 @@ show_multi_internal (CT ct, int serial, int alternate) } while (kids > 0 && (pid = wait (&status)) != NOTOK) { -#ifdef HAVE_UNION_WAIT - pidcheck (status.w_status); -#else pidcheck (status); -#endif for (part = m->mp_parts; part; part = part->mp_next) { p = part->mp_part; diff --git a/uip/mhstore.c b/uip/mhstore.c index 7b44a96..5bc8daa 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define AUTOSW 0 { "auto", 0 }, diff --git a/uip/mhtest.c b/uip/mhtest.c index 5c10b8b..022f6c4 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -20,10 +20,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define CHECKSW 0 { "check", 0 }, diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 219af22..07053d2 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -223,13 +223,7 @@ 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) { diff --git a/uip/spost.c b/uip/spost.c index c7582ba..e9e44a8 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -350,15 +350,8 @@ main (int argc, char **argv) out = stdout; } else { -#ifdef HAVE_MKSTEMP if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL ) adios (tmpfil, "unable to create"); -#else - mktemp (tmpfil); - if ((out = fopen (tmpfil, "w")) == NULL) - adios (tmpfil, "unable to create"); - chmod (tmpfil, 0600); -#endif } hdrtab = (msgstate == normal) ? NHeaders : RHeaders; @@ -747,15 +740,9 @@ make_bcc_file (void) char *vec[6]; FILE * in, *out; -#ifdef HAVE_MKSTEMP fd = mkstemp(bccfil); if (fd == -1 || (out = fdopen(fd, "w")) == NULL) adios (bccfil, "unable to create"); -#else - mktemp (bccfil); - if ((out = fopen (bccfil, "w")) == NULL) - adios (bccfil, "unable to create"); -#endif chmod (bccfil, 0600); fprintf (out, "Date: %s\n", dtimenow (0)); diff --git a/uip/viamail.c b/uip/viamail.c index aea746d..2e1c51c 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -18,10 +18,6 @@ #include #include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - static struct swit switches[] = { #define TOSW 0 { "to mailpath", 0 }, -- 1.7.10.4