=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/man/Attic/man.c,v retrieving revision 1.40 retrieving revision 1.41 diff -c -r1.40 -r1.41 *** src/usr.bin/man/Attic/man.c 2010/10/22 14:08:53 1.40 --- src/usr.bin/man/Attic/man.c 2011/05/25 14:36:04 1.41 *************** *** 1,4 **** ! /* $OpenBSD: man.c,v 1.40 2010/10/22 14:08:53 mikeb Exp $ */ /* $NetBSD: man.c,v 1.7 1995/09/28 06:05:34 tls Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: man.c,v 1.41 2011/05/25 14:36:04 deraadt Exp $ */ /* $NetBSD: man.c,v 1.7 1995/09/28 06:05:34 tls Exp $ */ /* *************** *** 77,83 **** static void build_page(char *, char **); static void cat(char *); static char *check_pager(char *); ! static int cleanup(void); static void how(char *); static void jump(char **, char *, char *); static int manual(char *, TAG *, glob_t *); --- 77,83 ---- static void build_page(char *, char **); static void cat(char *); static char *check_pager(char *); ! static int cleanup(int); static void how(char *); static void jump(char **, char *, char *); static int manual(char *, TAG *, glob_t *); *************** *** 242,248 **** /* 6: If nothing found, we're done. */ if (!found) { ! (void)cleanup(); exit (1); } --- 242,248 ---- /* 6: If nothing found, we're done. */ if (!found) { ! (void)cleanup(0); exit (1); } *************** *** 253,259 **** continue; cat(*ap); } ! exit (cleanup()); } if (f_how) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { --- 253,259 ---- continue; cat(*ap); } ! exit (cleanup(0)); } if (f_how) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { *************** *** 261,267 **** continue; how(*ap); } ! exit(cleanup()); } if (f_where) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { --- 261,267 ---- continue; how(*ap); } ! exit(cleanup(0)); } if (f_where) { for (ap = pg.gl_pathv; *ap != NULL; ++ap) { *************** *** 269,275 **** continue; (void)puts(*ap); } ! exit(cleanup()); } /* --- 269,275 ---- continue; (void)puts(*ap); } ! exit(cleanup(0)); } /* *************** *** 283,289 **** } if ((cmd = malloc(len)) == NULL) { warn(NULL); ! (void)cleanup(); exit(1); } p = cmd; --- 283,289 ---- } if ((cmd = malloc(len)) == NULL) { warn(NULL); ! (void)cleanup(0); exit(1); } p = cmd; *************** *** 304,310 **** /* Use system(3) in case someone's pager is "pager arg1 arg2". */ (void)system(cmd); ! exit(cleanup()); } /* --- 304,310 ---- /* Use system(3) in case someone's pager is "pager arg1 arg2". */ (void)system(cmd); ! exit(cleanup(0)); } /* *************** *** 445,451 **** GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE, NULL, pg)) { warn("globbing"); ! (void)cleanup(); exit(1); } if (pg->gl_matchc == 0) --- 445,451 ---- GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE, NULL, pg)) { warn("globbing"); ! (void)cleanup(0); exit(1); } if (pg->gl_matchc == 0) *************** *** 534,540 **** if ((ep = malloc(sizeof(ENTRY))) == NULL || (ep->s = strdup(page)) == NULL) { warn(NULL); ! (void)cleanup(); exit(1); } TAILQ_INSERT_TAIL(&missp->list, ep, q); --- 534,540 ---- if ((ep = malloc(sizeof(ENTRY))) == NULL || (ep->s = strdup(page)) == NULL) { warn(NULL); ! (void)cleanup(0); exit(1); } TAILQ_INSERT_TAIL(&missp->list, ep, q); *************** *** 597,603 **** (void)strlcpy(tpath, _PATH_TMPFILE, sizeof(tpath)); if ((fd = mkstemp(tpath)) == -1) { warn("%s", tpath); ! (void)cleanup(); exit(1); } (void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath); --- 597,603 ---- (void)strlcpy(tpath, _PATH_TMPFILE, sizeof(tpath)); if ((fd = mkstemp(tpath)) == -1) { warn("%s", tpath); ! (void)cleanup(0); exit(1); } (void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath); *************** *** 606,623 **** (void)close(fd); if ((*pathp = strdup(tpath)) == NULL) { warn(NULL); ! (void)cleanup(); exit(1); } /* Link the built file into the remove-when-done list. */ if ((ep = malloc(sizeof(ENTRY))) == NULL) { warn(NULL); ! (void)cleanup(); exit(1); } ep->s = *pathp; TAILQ_INSERT_TAIL(&intmpp->list, ep, q); } /* --- 606,626 ---- (void)close(fd); if ((*pathp = strdup(tpath)) == NULL) { warn(NULL); ! (void)cleanup(0); exit(1); } /* Link the built file into the remove-when-done list. */ if ((ep = malloc(sizeof(ENTRY))) == NULL) { warn(NULL); ! (void)cleanup(0); exit(1); } ep->s = *pathp; + + sigprocmask(SIG_BLOCK, &blocksigs, &osigs); TAILQ_INSERT_TAIL(&intmpp->list, ep, q); + sigprocmask(SIG_SETMASK, &osigs, NULL); } /* *************** *** 634,640 **** if (!(fp = fopen(fname, "r"))) { warn("%s", fname); ! (void)cleanup(); exit (1); } #define S1 "SYNOPSIS" --- 637,643 ---- if (!(fp = fopen(fname, "r"))) { warn("%s", fname); ! (void)cleanup(0); exit (1); } #define S1 "SYNOPSIS" *************** *** 691,708 **** if ((fd = open(fname, O_RDONLY, 0)) < 0) { warn("%s", fname); ! (void)cleanup(); exit(1); } while ((n = read(fd, buf, sizeof(buf))) > 0) if (write(STDOUT_FILENO, buf, n) != n) { warn("write"); ! (void)cleanup(); exit (1); } if (n == -1) { warn("read"); ! (void)cleanup(); exit(1); } (void)close(fd); --- 694,711 ---- if ((fd = open(fname, O_RDONLY, 0)) < 0) { warn("%s", fname); ! (void)cleanup(0); exit(1); } while ((n = read(fd, buf, sizeof(buf))) > 0) if (write(STDOUT_FILENO, buf, n) != n) { warn("write"); ! (void)cleanup(0); exit (1); } if (n == -1) { warn("read"); ! (void)cleanup(0); exit(1); } (void)close(fd); *************** *** 765,771 **** static void onsig(int signo) { ! (void)cleanup(); /* XXX signal race */ (void)signal(signo, SIG_DFL); (void)kill(getpid(), signo); --- 768,774 ---- static void onsig(int signo) { ! (void)cleanup(1); (void)signal(signo, SIG_DFL); (void)kill(getpid(), signo); *************** *** 779,802 **** * Clean up temporary files, show any error messages. */ static int ! cleanup(void) { TAG *intmpp, *missp; ENTRY *ep; ! int rval; ! rval = 0; ! ep = (missp = getlist("_missing")) == NULL ? ! NULL : TAILQ_FIRST(&missp->list); ! if (ep != NULL) ! for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) { ! if (section) ! warnx("no entry for %s in section %s of the manual.", ! ep->s, section->s); ! else ! warnx("no entry for %s in the manual.", ep->s); ! rval = 1; ! } ep = (intmpp = getlist("_intmp")) == NULL ? NULL : TAILQ_FIRST(&intmpp->list); --- 782,808 ---- * Clean up temporary files, show any error messages. */ static int ! cleanup(int insig) { TAG *intmpp, *missp; ENTRY *ep; ! int rval = 0; ! if (insig == 0) { ! ep = (missp = getlist("_missing")) == NULL ? ! NULL : TAILQ_FIRST(&missp->list); ! if (ep != NULL) ! for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) { ! if (section) ! warnx("no entry for %s in " ! "section %s of the manual.", ! ep->s, section->s); ! else ! warnx("no entry for %s in the manual.", ! ep->s); ! rval = 1; ! } ! } ep = (intmpp = getlist("_intmp")) == NULL ? NULL : TAILQ_FIRST(&intmpp->list);