From 4548981fb45fbc917cc2c26b7c96b31cfa14bc9b Mon Sep 17 00:00:00 2001 From: David Levine Date: Mon, 16 Jan 2012 20:58:15 -0600 Subject: [PATCH] Wrapped setjmp(), sigsetjmp(), and vfork() calls to silence gcc -Wclobbered for good. Undid ca34fbd0a5204d47ad019f64ef03d21ebd3397fd, which added volatile qualifiers but was not general. --- h/Makefile.in | 2 +- h/m_setjmp.h | 16 ++++++++++++++++ h/prototypes.h | 1 + h/rcvmail.h | 1 - sbr/Makefile.in | 2 +- sbr/ext_hook.c | 2 +- sbr/folder_delmsgs.c | 2 +- sbr/getans.c | 4 ++-- sbr/m_setjmp.c | 25 +++++++++++++++++++++++++ sbr/m_vfork.c | 17 +++++++++++++++++ sbr/makedir.c | 2 +- sbr/refile.c | 2 +- sbr/showfile.c | 2 +- uip/mhbuildsbr.c | 5 ++--- uip/mhcachesbr.c | 1 - uip/mhlsbr.c | 12 ++++++------ uip/mhparse.c | 8 +++----- uip/mhshowsbr.c | 8 ++++---- uip/mhstoresbr.c | 1 - uip/msh.c | 4 ++-- uip/mshcmds.c | 1 - uip/post.c | 1 - uip/prompter.c | 4 ++-- uip/rcvtty.c | 10 +++++----- uip/replsbr.c | 2 +- uip/sendsbr.c | 11 +++++------ uip/slocal.c | 3 ++- uip/spost.c | 6 +++--- uip/whatnowsbr.c | 8 ++++---- 29 files changed, 107 insertions(+), 56 deletions(-) create mode 100644 h/m_setjmp.h create mode 100644 sbr/m_setjmp.c create mode 100644 sbr/m_vfork.c diff --git a/h/Makefile.in b/h/Makefile.in index 7dcbb6f..865df96 100644 --- a/h/Makefile.in +++ b/h/Makefile.in @@ -10,7 +10,7 @@ VPATH = @srcdir@ # header files included in distribution HDRS = addrsbr.h aliasbr.h crawl_folders.h dropsbr.h fmt_compile.h fmt_scan.h \ md5.h mf.h mh.h mhcachesbr.h mhparse.h mime.h msh.h mts.h \ - nmh.h picksbr.h popsbr.h prototypes.h rcvmail.h \ + m_setjmp.h nmh.h picksbr.h popsbr.h prototypes.h rcvmail.h \ scansbr.h signals.h tws.h vmhsbr.h utils.h # auxiliary files diff --git a/h/m_setjmp.h b/h/m_setjmp.h new file mode 100644 index 0000000..767c3f1 --- /dev/null +++ b/h/m_setjmp.h @@ -0,0 +1,16 @@ + +/* + * m_setjmp.h -- Wraps setjmp() and sigsetjmp(), to help prevent warnings + * -- about arguments and variables that might be clobbered by + * -- a setjmp call with gcc -Wclobbered. + * + * This code is Copyright (c) 2012, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include + +int m_setjmp(jmp_buf); + +int m_sigsetjmp(sigjmp_buf, int); diff --git a/h/prototypes.h b/h/prototypes.h index 12124cd..0544306 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -80,6 +80,7 @@ int m_putenv (char *, char *); char *m_mktemp(const char *, int *, FILE **); char *m_mktemp2(const char *, const char *, int *, FILE **); void m_unknown(FILE *); +pid_t m_vfork (); int makedir (char *); char *nmh_getpass(const char *); char *norm_charmap(char *); diff --git a/h/rcvmail.h b/h/rcvmail.h index 37fba4d..275ea74 100644 --- a/h/rcvmail.h +++ b/h/rcvmail.h @@ -6,7 +6,6 @@ #if defined(SMTPMTS) # include # include -# include # include # include # include diff --git a/sbr/Makefile.in b/sbr/Makefile.in index c949469..c65828b 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -62,7 +62,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_maildir.c m_name.c m_setjmp.c m_vfork.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/ext_hook.c b/sbr/ext_hook.c index e94083b..506457d 100644 --- a/sbr/ext_hook.c +++ b/sbr/ext_hook.c @@ -23,7 +23,7 @@ ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2) if ((hook = context_find(hook_name)) == (char *)0) return (OK); - switch (pid = vfork()) { + switch (pid = m_vfork()) { case -1: status = NOTOK; advise(NULL, "external database may be out-of-date."); diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c index 6bde76f..b812def 100644 --- a/sbr/folder_delmsgs.c +++ b/sbr/folder_delmsgs.c @@ -57,7 +57,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) fflush (stdout); vec[0] = r1bindex (rmmproc, '/'); - switch (pid = vfork()) { + switch (pid = m_vfork()) { case -1: advise ("fork", "unable to"); return -1; diff --git a/sbr/getans.c b/sbr/getans.c index 173e1b4..95e34c4 100644 --- a/sbr/getans.c +++ b/sbr/getans.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include static char ansbuf[BUFSIZ]; @@ -28,7 +28,7 @@ getans (char *prompt, struct swit *ansp) SIGNAL_HANDLER istat = NULL; char *cp, **cpp; - if (!(setjmp (sigenv))) { + if (!(m_setjmp (sigenv))) { istat = SIGNAL (SIGINT, intrser); } else { SIGNAL (SIGINT, istat); diff --git a/sbr/m_setjmp.c b/sbr/m_setjmp.c new file mode 100644 index 0000000..f19546b --- /dev/null +++ b/sbr/m_setjmp.c @@ -0,0 +1,25 @@ + +/* + * m_setjmp.h -- Wraps setjmp() and sigsetjmp(), to help prevent warnings + * -- about arguments and variables that might be clobbered by + * -- a setjmp call with gcc -Wclobbered. + * + * This code is Copyright (c) 2012, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include + + +int +m_setjmp(jmp_buf env) { + return setjmp(env); +} + + +int +m_sigsetjmp(sigjmp_buf env, int savesigs) { + return sigsetjmp(env, savesigs); +} + diff --git a/sbr/m_vfork.c b/sbr/m_vfork.c new file mode 100644 index 0000000..e35f0bc --- /dev/null +++ b/sbr/m_vfork.c @@ -0,0 +1,17 @@ + +/* + * m_vfork.c -- Wraps vfork(), to help prevent warnings about arguments + * -- and variables that might be clobbered by a vfork call + * -- with gcc -Wclobbered. + * + * This code is Copyright (c) 2012, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include + +pid_t +m_vfork() { + return vfork(); +} diff --git a/sbr/makedir.c b/sbr/makedir.c index 4337b7c..bbeef80 100644 --- a/sbr/makedir.c +++ b/sbr/makedir.c @@ -85,7 +85,7 @@ makedir (char *dir) nested directories like the above code can. -- Dan Harkless */ - switch (pid = vfork()) { + switch (pid = m_vfork()) { case -1: advise ("fork", "unable to"); return 0; diff --git a/sbr/refile.c b/sbr/refile.c index fc2793c..a2a958d 100644 --- a/sbr/refile.c +++ b/sbr/refile.c @@ -34,7 +34,7 @@ refile (char **arg, char *file) context_save(); /* save the context file */ fflush(stdout); - switch (pid = vfork()) { + switch (pid = m_vfork()) { case -1: advise ("fork", "unable to"); return -1; diff --git a/sbr/showfile.c b/sbr/showfile.c index 59ae795..17f84b9 100644 --- a/sbr/showfile.c +++ b/sbr/showfile.c @@ -28,7 +28,7 @@ showfile (char **arg, char *file) if (!strcmp (r1bindex (lproc, '/'), "mhl")) lproc = mhlproc; - switch (pid = vfork()) { + switch (pid = m_vfork()) { case -1: /* fork error */ advise ("fork", "unable to"); diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 87ebf16..d417bef 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -988,8 +988,7 @@ compose_content (CT ct) default: if (!ce->ce_file) { pid_t child_id; - int i, len, buflen; - volatile int xstdout; + int i, xstdout, len, buflen; char *bp, **ap, *cp; char *vec[4], buffer[BUFSIZ]; FILE *out; @@ -1088,7 +1087,7 @@ raw: if ((out = fopen (ce->ce_file, "w")) == NULL) adios (ce->ce_file, "unable to open for writing"); - for (i = 0; (child_id = vfork()) == NOTOK && i > 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i > 5; i++) sleep (5); switch (child_id) { case NOTOK: diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index cf9087b..eee8631 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 4c2558f..b494812 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include /* @@ -790,13 +790,13 @@ parse (void) static void -process (char *folder, char *volatile fname, int ofilen, int ofilec) +process (char *folder, char *fname, int ofilen, int ofilec) { char *cp = NULL; FILE *fp = NULL; struct mcomp *c1; - switch (setjmp (env)) { + switch (m_setjmp (env)) { case OK: if (fname) { fp = mhl_action ? (*mhl_action) (fname) : fopen (fname, "r"); @@ -1587,7 +1587,7 @@ doface (struct mcomp *c1) return NOTOK; } - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { @@ -1682,7 +1682,7 @@ mhlsbr (int argc, char **argv, FILE *(*action)()) char *cp = NULL; struct mcomp *c1; - switch (setjmp (mhlenv)) { + switch (m_setjmp (mhlenv)) { case OK: cp = invo_name; sleepsw = 0; /* XXX */ @@ -1761,7 +1761,7 @@ m_popen (char *name) if (pipe (pd) == NOTOK) adios ("pipe", "unable to"); - switch (m_pid = vfork ()) { + switch (m_pid = m_vfork()) { case NOTOK: adios ("fork", "unable to"); diff --git a/uip/mhparse.c b/uip/mhparse.c index ea78b42..265276d 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -2472,8 +2471,7 @@ InitFTP (CT ct) static int openFTP (CT ct, char **file) { - int cachetype, fd; - volatile int caching; + int cachetype, caching, fd; int len, buflen; char *bp, *ftp, *user, *pass; char buffer[BUFSIZ], cachefile[BUFSIZ]; @@ -2606,7 +2604,7 @@ openFTP (CT ct, char **file) fflush (stdout); - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: @@ -2748,7 +2746,7 @@ openMail (CT ct, char **file) vec[vecp++] = e->eb_body; vec[vecp] = NULL; - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 6f511f3..ae90a7b 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -197,7 +197,7 @@ DisplayMsgHeader (CT ct, char *form) fflush (stdout); - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { @@ -541,7 +541,7 @@ show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer SIGNAL_HANDLER istat; istat = SIGNAL (SIGINT, intrser); - if ((intr = sigsetjmp (intrenv, 1)) == OK) { + if ((intr = m_sigsetjmp (intrenv, 1)) == OK) { fflush (stdout); prompt[0] = 0; read (fileno (stdout), prompt, sizeof(prompt)); @@ -564,7 +564,7 @@ show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer fflush (stdout); - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index a1b5e2a..5962184 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/uip/msh.c b/uip/msh.c index 2339821..43530db 100644 --- a/uip/msh.c +++ b/uip/msh.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -1919,7 +1919,7 @@ pFIN (void) { int status; - switch (setjmp (peerenv)) { + switch (m_setjmp (peerenv)) { case OK: SIGNAL (SIGALRM, alrmser); alarm (ALARM); diff --git a/uip/mshcmds.c b/uip/mshcmds.c index cec475e..19d8b5b 100644 --- a/uip/mshcmds.c +++ b/uip/mshcmds.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/uip/post.c b/uip/post.c index 8845560..2449d5f 100644 --- a/uip/post.c +++ b/uip/post.c @@ -20,7 +20,6 @@ #include #include -#include #include #ifdef HAVE_SYS_TIME_H diff --git a/uip/prompter.c b/uip/prompter.c index 981e820..ecfd05f 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include @@ -353,7 +353,7 @@ getln (char *buffer, int n) cp = buffer; *cp = 0; - switch (setjmp (sigenv)) { + switch (m_setjmp (sigenv)) { case OK: wtuser = 1; break; diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 8ce068d..1ae8576 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -217,21 +218,20 @@ static int message_fd (char **vec) { pid_t child_id; - int bytes, seconds; - volatile int fd; + int bytes, fd, seconds; char tmpfil[BUFSIZ]; struct stat st; fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil))); 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; @@ -317,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); diff --git a/uip/replsbr.c b/uip/replsbr.c index ace850d..7365b45 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -466,7 +466,7 @@ replfilter (FILE *in, FILE *out, char *filter) rewind (in); lseek (fileno(in), (off_t) 0, SEEK_SET); - switch (pid = vfork ()) { + switch (pid = m_vfork()) { case NOTOK: adios ("fork", "unable to"); diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 09126c2..63efbc0 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -110,7 +110,7 @@ sendsbr (char **vec, int vecp, char *drft, struct stat *st, int rename_drft, cha } done=armed_done; - switch (setjmp (env)) { + switch (m_setjmp (env)) { case OK: /* * If given -push and -unique (which is undocumented), then @@ -771,11 +771,10 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) */ static int -sendaux (char **vec, int vecp, char *volatile drft, struct stat *st) +sendaux (char **vec, int vecp, char *drft, struct stat *st) { pid_t child_id; - int i, status; - volatile int fd, fd2; + int i, status, fd, fd2; char backup[BUFSIZ], buf[BUFSIZ]; fd = pushsw ? tmp_fd () : NOTOK; @@ -795,7 +794,7 @@ sendaux (char **vec, int vecp, char *volatile drft, struct stat *st) done (1); vec[vecp] = NULL; - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { diff --git a/uip/slocal.c b/uip/slocal.c index f08f2ff..d701e78 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1165,7 +1166,7 @@ usr_pipe (int fd, char *cmd, char *pgm, char **vec, int suppress) default: /* parent process */ - if (!setjmp (myctx)) { + if (! m_setjmp (myctx)) { SIGNAL (SIGALRM, alrmser); bytes = fstat (fd, &st) != -1 ? (int) st.st_size : 100; diff --git a/uip/spost.c b/uip/spost.c index 187f9a0..6defbac 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -428,7 +428,7 @@ main (int argc, char **argv) if (pushflg && !(watch || verbose)) { /* fork to a child to run sendmail */ - for (i=0; (pid = vfork()) == NOTOK && i < 5; i++) + for (i=0; (pid = m_vfork()) == NOTOK && i < 5; i++) sleep(5); switch (pid) { case NOTOK: @@ -764,7 +764,7 @@ make_bcc_file (void) else { vec[0] = r1bindex (mhlproc, '/'); - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: @@ -825,7 +825,7 @@ fcc (char *file, char *folder) printf ("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", folder); fflush (stdout); - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 3009e0f..85c50b3 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -696,7 +696,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, context_save (); /* save the context file */ fflush (stdout); - switch (pid = vfork ()) { + switch (pid = m_vfork()) { case NOTOK: advise ("fork", "unable to"); status = NOTOK; @@ -811,7 +811,7 @@ copyf (char *ifile, char *ofile) */ static int -sendfile (char **arg, char *file, volatile int pushsw) +sendfile (char **arg, char *file, int pushsw) { pid_t child_id; int i, vecp; @@ -846,7 +846,7 @@ sendfile (char **arg, char *file, volatile int pushsw) context_save (); /* save the context file */ fflush (stdout); - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = m_vfork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: @@ -1349,7 +1349,7 @@ whomfile (char **arg, char *file) context_save (); /* save the context file */ fflush (stdout); - switch (pid = vfork ()) { + switch (pid = m_vfork()) { case NOTOK: advise ("fork", "unable to"); return 1; -- 1.7.10.4