aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2018-04-06 16:38:56 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2018-04-07 20:16:08 -0400
commitbe1546b87f3b60f107b8f8dfef0e268cc12792f1 (patch)
treed17a0a57f3e8959d7a4f49fdf4e083b8ab4aa4a6
parentf5ef48855733360c850be82221ce7454294a1580 (diff)
ktest.pl: Add MAIL_PATH option to define where to find the mailer
The option MAIL_PATH lets the user decide how to find the mailer they are using. For example, sendmail is usually located in /usr/sbin but is not always in the path of non admin users. Have ktest look through the user's PATH environment variable (adding /usr/sbin) as well, but if that's not good enough, allow the user to define where to find the mailer. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> squash to mail exec Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rwxr-xr-xtools/testing/ktest/ktest.pl36
-rw-r--r--tools/testing/ktest/sample.conf4
2 files changed, 35 insertions, 5 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 07d0a47816e4..637545bd9e98 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -23,7 +23,7 @@ my %evals;
23 23
24#default opts 24#default opts
25my %default = ( 25my %default = (
26 "MAILER" => "sendmail", # default mailer 26 "MAILER" => "sendmail", # default mailer
27 "EMAIL_ON_ERROR" => 1, 27 "EMAIL_ON_ERROR" => 1,
28 "EMAIL_WHEN_FINISHED" => 1, 28 "EMAIL_WHEN_FINISHED" => 1,
29 "EMAIL_WHEN_CANCELED" => 0, 29 "EMAIL_WHEN_CANCELED" => 0,
@@ -218,6 +218,7 @@ my $dirname = $FindBin::Bin;
218 218
219my $mailto; 219my $mailto;
220my $mailer; 220my $mailer;
221my $mail_path;
221my $email_on_error; 222my $email_on_error;
222my $email_when_finished; 223my $email_when_finished;
223my $email_when_started; 224my $email_when_started;
@@ -250,8 +251,9 @@ my $no_reboot = 1;
250my $reboot_success = 0; 251my $reboot_success = 0;
251 252
252my %option_map = ( 253my %option_map = (
253 "MAILTO" => \$mailto, 254 "MAILTO" => \$mailto,
254 "MAILER" => \$mailer, 255 "MAILER" => \$mailer,
256 "MAIL_PATH" => \$mail_path,
255 "EMAIL_ON_ERROR" => \$email_on_error, 257 "EMAIL_ON_ERROR" => \$email_on_error,
256 "EMAIL_WHEN_FINISHED" => \$email_when_finished, 258 "EMAIL_WHEN_FINISHED" => \$email_when_finished,
257 "EMAIL_WHEN_STARTED" => \$email_when_started, 259 "EMAIL_WHEN_STARTED" => \$email_when_started,
@@ -4126,12 +4128,29 @@ sub set_test_option {
4126 4128
4127sub _mailx_send { 4129sub _mailx_send {
4128 my ($subject, $message) = @_; 4130 my ($subject, $message) = @_;
4129 system("$mailer -s \'$subject\' $mailto <<< \'$message\'"); 4131 system("$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'");
4130} 4132}
4131 4133
4132sub _sendmail_send { 4134sub _sendmail_send {
4133 my ($subject, $message) = @_; 4135 my ($subject, $message) = @_;
4134 system("echo -e \"Subject: $subject\n\n$message\" | sendmail -t $mailto"); 4136 system("echo -e \"Subject: $subject\n\n$message\" | $mail_path/sendmail -t $mailto");
4137}
4138
4139sub find_mailer {
4140 my ($mailer) = @_;
4141
4142 my @paths = split /:/, $ENV{PATH};
4143
4144 # sendmail is usually in /usr/sbin
4145 $paths[$#paths + 1] = "/usr/sbin";
4146
4147 foreach my $path (@paths) {
4148 if (-x "$path/$mailer") {
4149 return $path;
4150 }
4151 }
4152
4153 return undef;
4135} 4154}
4136 4155
4137sub send_email { 4156sub send_email {
@@ -4140,6 +4159,13 @@ sub send_email {
4140 doprint "No email sent: email or mailer not specified in config.\n"; 4159 doprint "No email sent: email or mailer not specified in config.\n";
4141 return; 4160 return;
4142 } 4161 }
4162 if (!defined($mail_path)) {
4163 # find the mailer
4164 $mail_path = find_mailer $mailer;
4165 if (!defined($mail_path)) {
4166 die "\nCan not find $mailer in PATH\n";
4167 }
4168 }
4143 if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} 4169 if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);}
4144 elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} 4170 elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);}
4145 else { doprint "\nYour mailer: $mailer is not supported.\n" } 4171 else { doprint "\nYour mailer: $mailer is not supported.\n" }
diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.conf
index d1a2626aaa0a..86e7cffc45c0 100644
--- a/tools/testing/ktest/sample.conf
+++ b/tools/testing/ktest/sample.conf
@@ -411,6 +411,10 @@
411# (default sendmail) 411# (default sendmail)
412#MAILER = sendmail 412#MAILER = sendmail
413# 413#
414# The executable to run
415# (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER})
416#MAIL_EXEC = /usr/sbin/sendmail
417#
414# Errors are defined as those would terminate the script 418# Errors are defined as those would terminate the script
415# (default 1) 419# (default 1)
416#EMAIL_ON_ERROR = 1 420#EMAIL_ON_ERROR = 1