changeset 12966:0d2f176e1e5e

6739360 UNIX03/UNIX98: *man* man does not set non-zero exit value and write to stderr for missing man page
author Amrita Sadhukhan <Amrita.Sadhukhan@Sun.COM>
date Thu, 29 Jul 2010 12:37:20 +0530
parents 7a5c324190b8
children 1e73c8f5a88b
files usr/src/cmd/man/src/man.c
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/man/src/man.c	Thu Jul 29 02:14:42 2010 -0400
+++ b/usr/src/cmd/man/src/man.c	Thu Jul 29 12:37:20 2010 +0530
@@ -303,7 +303,7 @@
 static void fullpaths(struct man_node **);
 static void lower(char *);
 static int cmp(const void *, const void *);
-static void manual(struct man_node *, char *);
+static int manual(struct man_node *, char *);
 static void mandir(char **, char *, char *);
 static void sortdir(DIR *, char ***);
 static int searchdir(char *, char *, char *);
@@ -355,6 +355,7 @@
 	char *manpath = NULL;
 	static struct man_node	*manpage = NULL;
 	int bmp_flags = 0;
+	int err = 0;
 
 	if (access(SROFF_CMD, F_OK | X_OK) != 0)
 		no_sroff = 1;
@@ -584,7 +585,7 @@
 			} else if (printmp != 0) {
 				print_manpath(mp, argv[optind]);
 			} else {
-				manual(mp, argv[optind]);
+				err += manual(mp, argv[optind]);
 			}
 
 			if (mp != NULL && mp != manpage) {
@@ -593,7 +594,7 @@
 			}
 		}
 	}
-	return (0);
+	return (err == 0 ? 0 : 1);
 	/*NOTREACHED*/
 }
 
@@ -1590,7 +1591,7 @@
  *   and if it doesn't exist, do the hard way.
  */
 
-static void
+static int
 manual(struct man_node *manp, char *name)
 {
 	struct man_node *p;
@@ -1662,19 +1663,21 @@
 		more(pages, nomore);
 	} else {
 		if (sargs) {
-			(void) printf(gettext("No entry for %s in section(s) "
-			    "%s of the manual.\n"), fullname, mansec);
+			(void) fprintf(stderr, gettext("No entry for %s in "
+			    "section(s) %s of the manual.\n"),
+			    fullname, mansec);
 		} else {
-			(void) printf(gettext(
+			(void) fprintf(stderr, gettext(
 			    "No manual entry for %s.\n"), fullname, mansec);
 		}
 
 		if (sman_no_man_no_sroff)
-			(void) printf(gettext("(An SGML manpage was found "
-			    "for '%s' but it cannot be displayed.)\n"),
+			(void) fprintf(stderr, gettext("(An SGML manpage was "
+			    "found for '%s' but it cannot be displayed.)\n"),
 			    fullname, mansec);
 	}
 	sman_no_man_no_sroff = 0;
+	return (!found);
 }