From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: "John Warthog9 Hawley" <warthog9@kernel.org>,
Scott Wood <swood@redhat.com>,
Tim Tianyang Chen <tianyang.chen@oracle.com>
Subject: [for-next][PATCH 23/23] ktest.pl: Add MAIL_COMMAND option to define how to send email
Date: Sun, 08 Apr 2018 16:17:31 -0400 [thread overview]
Message-ID: <20180408201837.758159465@goodmis.org> (raw)
In-Reply-To: <20180408201708.346970379@goodmis.org>
[-- Attachment #1: 0023-ktest.pl-Add-MAIL_COMMAND-option-to-define-how-to-se.patch --]
[-- Type: text/plain, Size: 4342 bytes --]
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Allow the user to override the default way to send email. This will allow
the user to add their own mailer and format for sending email.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
tools/testing/ktest/ktest.pl | 54 ++++++++++++++++++++++++++---------------
tools/testing/ktest/sample.conf | 12 +++++++++
2 files changed, 46 insertions(+), 20 deletions(-)
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index f487f91ccf03..a14fc309d140 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -219,6 +219,7 @@ my $dirname = $FindBin::Bin;
my $mailto;
my $mailer;
my $mail_path;
+my $mail_command;
my $email_on_error;
my $email_when_finished;
my $email_when_started;
@@ -254,6 +255,7 @@ my %option_map = (
"MAILTO" => \$mailto,
"MAILER" => \$mailer,
"MAIL_PATH" => \$mail_path,
+ "MAIL_COMMAND" => \$mail_command,
"EMAIL_ON_ERROR" => \$email_on_error,
"EMAIL_WHEN_FINISHED" => \$email_when_finished,
"EMAIL_WHEN_STARTED" => \$email_when_started,
@@ -4133,16 +4135,6 @@ sub set_test_option {
return eval_option($name, $option, $i);
}
-sub _mailx_send {
- my ($subject, $message) = @_;
- run_command "$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'";
-}
-
-sub _sendmail_send {
- my ($subject, $message) = @_;
- run_command "echo \'Subject: $subject\n\n$message\' | $mail_path/sendmail -t $mailto";
-}
-
sub find_mailer {
my ($mailer) = @_;
@@ -4160,22 +4152,44 @@ sub find_mailer {
return undef;
}
+sub do_send_mail {
+ my ($subject, $message) = @_;
+
+ if (!defined($mail_path)) {
+ # find the mailer
+ $mail_path = find_mailer $mailer;
+ if (!defined($mail_path)) {
+ die "\nCan not find $mailer in PATH\n";
+ }
+ }
+
+ if (!defined($mail_command)) {
+ if ($mailer eq "mail" || $mailer eq "mailx") {
+ $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'";
+ } elsif ($mailer eq "sendmail" ) {
+ $mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO";
+ } else {
+ die "\nYour mailer: $mailer is not supported.\n";
+ }
+ }
+
+ $mail_command =~ s/\$MAILER/$mailer/g;
+ $mail_command =~ s/\$MAIL_PATH/$mail_path/g;
+ $mail_command =~ s/\$MAILTO/$mailto/g;
+ $mail_command =~ s/\$SUBJECT/$subject/g;
+ $mail_command =~ s/\$MESSAGE/$message/g;
+
+ run_command $mail_command;
+}
+
sub send_email {
+
if (defined($mailto)) {
if (!defined($mailer)) {
doprint "No email sent: email or mailer not specified in config.\n";
return;
}
- if (!defined($mail_path)) {
- # find the mailer
- $mail_path = find_mailer $mailer;
- if (!defined($mail_path)) {
- die "\nCan not find $mailer in PATH\n";
- }
- }
- if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
- elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
- else { die "\nYour mailer: $mailer is not supported.\n" }
+ do_send_mail @_;
}
}
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index 86e7cffc45c0..6ca6ca0ce695 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -415,6 +415,18 @@
# (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER})
#MAIL_EXEC = /usr/sbin/sendmail
#
+# The command used to send mail, which uses the above options
+# can be modified. By default if the mailer is "sendmail" then
+# MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO
+# For mail or mailx:
+# MAIL_COMMAND = "$MAIL_PATH/$MAILER -s \'$SUBJECT\' $MAILTO <<< \'$MESSAGE\'
+# ktest.pl will do the substitution for MAIL_PATH, MAILER, MAILTO at the time
+# it sends the mail if "$FOO" format is used. If "${FOO}" format is used,
+# then the substitutions will occur at the time the config file is read.
+# But note, MAIL_PATH and MAILER require being set by the config file if
+# ${MAIL_PATH} or ${MAILER} are used, but not if $MAIL_PATH or $MAILER are.
+#MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO
+#
# Errors are defined as those would terminate the script
# (default 1)
#EMAIL_ON_ERROR = 1
--
2.16.3
prev parent reply other threads:[~2018-04-08 20:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-08 20:17 [for-next][PATCH 00/23] ktest: Updates for 4.17 Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 01/23] ktest: Wait for console process to exit Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 02/23] ktest: Add CONNECT_TIMEOUT to change the connection timeout time Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 03/23] ktest: Clarify config file usage Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 04/23] ktest: Comment about other names than just ktest.conf Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 05/23] ktest: Set buildonly=1 for CONFIG_BISECT_TYPE=build Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 06/23] ktest: Set do_not_reboot=y " Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 07/23] ktest: Add standalone config-bisect.pl program Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 08/23] ktest: Use config-bisect.pl in ktest.pl Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 09/23] ktest.pl: Allow for the config-bisect.pl output to display to console Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 10/23] ktest.pl: Use diffconfig if available for failed config bisects Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 11/23] ktest.pl: Have ktest.pl pass -r to config-bisect.pl to reset bisect Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 12/23] ktest.pl: Make finding config-bisect.pl dynamic Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 13/23] ktest.pl: Detect if a config-bisect was interrupted Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 14/23] Ktest: Add email support Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 15/23] Ktest: Add SigInt handling Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 16/23] Ktest: Use dodie for critical falures Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 17/23] Ktest: add email options to sample.config Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 18/23] ktest.pl: No need to print no mailer is specified when mailto is not Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 19/23] ktest.pl: Add MAIL_PATH option to define where to find the mailer Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 20/23] ktest.pl: Kill test if mailer is not supported Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 21/23] ktest.pl: Allow dodie be recursive Steven Rostedt
2018-04-08 20:17 ` [for-next][PATCH 22/23] ktest.pl: Use run_command to execute sending mail Steven Rostedt
2018-04-08 20:17 ` Steven Rostedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180408201837.758159465@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-kernel@vger.kernel.org \
--cc=swood@redhat.com \
--cc=tianyang.chen@oracle.com \
--cc=warthog9@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®