diff -ru nagios-plugins-1.4.15.orig/plugins/check_smtp.c nagios-plugins-1.4.15/plugins/check_smtp.c --- nagios-plugins-1.4.15.orig/plugins/check_smtp.c 2010-07-27 20:47:16.000000000 +0000 +++ nagios-plugins-1.4.15/plugins/check_smtp.c 2011-07-15 10:51:11.000000000 +0000 @@ -114,6 +114,7 @@ TCP_PROTOCOL = 1, UDP_PROTOCOL = 2, }; +int ignore_send_quit_failure = FALSE; int @@ -129,6 +130,9 @@ char *error_msg = ""; struct timeval tv; + /* catch pipe errors in read.write */ + (void) signal (SIGPIPE, SIG_IGN); + setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); @@ -476,6 +480,7 @@ {"help", no_argument, 0, 'h'}, {"starttls",no_argument,0,'S'}, {"certificate",required_argument,0,'D'}, + {"ignore-quit-failure",no_argument,0,'q'}, {0, 0, 0, 0} }; @@ -492,7 +497,7 @@ } while (1) { - c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:", + c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", longopts, &option); if (c == -1 || c == EOF) @@ -579,6 +584,9 @@ case 'v': /* verbose */ verbose++; break; + case 'q': + ignore_send_quit_failure++; /* ignore problem sending QUIT */ + break; case 't': /* timeout */ if (is_intnonneg (optarg)) { socket_timeout = atoi (optarg); @@ -662,8 +670,21 @@ smtp_quit(void) { int bytes; + int n; + + n = my_send(SMTP_QUIT, strlen(SMTP_QUIT)); + if(n != 0) { + if(ignore_send_quit_failure) { + if(verbose) { + printf( + _("Connection closed by server before sending QUIT command\n")); + } + return; + } + die (STATE_UNKNOWN, + _("Connection closed by server before sending QUIT command\n")); + } - my_send(SMTP_QUIT, strlen(SMTP_QUIT)); if (verbose) printf(_("sent %s\n"), "QUIT"); @@ -797,7 +818,9 @@ printf (" %s\n", _("SMTP AUTH username")); printf (" %s\n", "-P, --authpass=STRING"); printf (" %s\n", _("SMTP AUTH password")); - + printf (" %s\n", "-q, --ignore-quit-failure"); + printf (" %s\n", _("Ignore failure when sending QUIT command to server")); + printf (UT_WARN_CRIT); printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); @@ -821,6 +844,6 @@ printf ("%s\n", _("Usage:")); printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname); printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n"); - printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6]\n"); + printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6] [-q]\n"); }