Description: ttyrun: Introduce verbose option for syslog messages
Symptom:     Users experience syslog error messages like:
	      "Could not open tty /dev/hvc6 (No such file or directory)"
	     ttyrun prevents respawning of getty processes on terminal
	     that are not available. For example, hvc terminal devices
	     that are not assigned to a backend driver.  If ttyrun fails
	     to open a terminal device, the respective error condition
	     is logged.
Problem:     If ttyrun fails to open a terminal device, the
	     error condition is reported to syslog.  Depending on
	     the environment, multiple terminal devices might not
	     be available and, hence, multiple error messages are
	     issued.
Solution:    Introduce a verbose option to switch on/off syslog
	     messages issued by ttyrun.
Problem-ID:  77444
---
 iucvterm/doc/ttyrun.8 |    9 +++++++--
 iucvterm/src/ttyrun.c |   23 +++++++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)

--- a/iucvterm/doc/ttyrun.8
+++ b/iucvterm/doc/ttyrun.8
@@ -1,10 +1,10 @@
 .\" ttyrun.8
 .\"
 .\"
-.\" Copyright IBM Corp. 2010
+.\" Copyright IBM Corp. 2010, 2011
 .\" Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
 .\" -------------------------------------------------------------------------
-.TH "ttyrun" "8" "April 2010" "s390-tools" "System Management Commands"
+.TH "ttyrun" "8" "December 2011" "s390-tools" "System Management Commands"
 .LO 8
 .
 .ds s ttyrun
@@ -17,6 +17,7 @@ ttyrun \- Start a program if a specified
 .
 .SH SYNOPSIS
 .B \*s
+.RB [ \-V | \-\-verbose ]
 .RB [ \-e | \-\-exitstatus
 .IR status ]
 .I term
@@ -74,6 +75,10 @@ You can use this status value in an upst
 respawning.
 .
 .TP
+.BR \-V ", " \-\-verbose
+Displays syslog messages.
+.
+.TP
 .BR \-h ", " \-\-help
 Displays a short help text, then exits.
 .
--- a/iucvterm/src/ttyrun.c
+++ b/iucvterm/src/ttyrun.c
@@ -22,7 +22,7 @@
  *    1..255 - terminal is not available and the return code is
  *	       specified with the -e option
  *
- * Copyright IBM Corp. 2010
+ * Copyright IBM Corp. 2010, 2011
  * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
  */
 #include <errno.h>
@@ -56,6 +56,7 @@ static const char usage[] =
 "that causes an exit or exit with the return value specified with status.\n"
 "\n"
 "-e, --exitstatus     Specifies an exit status in the range 1 to 255.\n"
+"-V, --verbose        Displays syslog messages.\n"
 "-h, --help           Displays this help, then exits.\n"
 "-v, --version        Displays version information, then exits.\n";
 
@@ -90,12 +91,13 @@ static const struct option prog_opts[] =
 	{ "help",	no_argument, NULL, 'h'},
 	{ "version",	no_argument, NULL, 'v'},
 	{ "exitstatus",	required_argument, NULL, 'e'},
+	{ "verbose",	no_argument, NULL, 'V'},
 	{ NULL,		no_argument, NULL,  0 },
 };
 
 int main(int argc, char *argv[])
 {
-	int rc, tty, i, c, index, done, term_index;
+	int rc, tty, i, c, index, done, term_index, verbose;
 	char terminal[PATH_MAX] = "";
 	unsigned long exitstatus;
 
@@ -104,9 +106,9 @@ int main(int argc, char *argv[])
 	if (argc == 1)
 		err_exit(argv[0], "One or more options are required but missing");
 
-	exitstatus = done = term_index = 0;
+	exitstatus = done = term_index = verbose = 0;
 	while (!done) {
-		c = getopt_long(argc, argv, "-hve:", prog_opts, NULL);
+		c = getopt_long(argc, argv, "-hve:V", prog_opts, NULL);
 		switch (c) {
 		case -1:
 			done = 1;
@@ -133,6 +135,9 @@ int main(int argc, char *argv[])
 				err_exit(argv[0], "The exit status must be "
 					 "in the range 1 to 255");
 			break;
+		case 'V':
+			verbose = 1;
+			break;
 		case 'h':
 			help_exit(argv[0]);
 		case 'v':
@@ -157,10 +162,12 @@ int main(int argc, char *argv[])
 	/* open and check terminal device */
 	tty = open(terminal, O_NOCTTY | O_RDONLY | O_NONBLOCK);
 	if (tty == -1) {
-		openlog(argv[0], LOG_PID, LOG_DAEMON);
-		syslog(LOG_INFO, "Could not open tty %s (%s)", terminal,
-		       strerror(errno));
-		closelog();
+		if (verbose) {
+			openlog(argv[0], LOG_PID, LOG_DAEMON);
+			syslog(LOG_INFO, "Could not open tty %s (%s)",
+			       terminal, strerror(errno));
+			closelog();
+		}
 
 		/* enter wait or exit */
 		if (exitstatus)
