Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ktest.pl: Add MAIL_COMMAND option to define how to send email

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>

+46 -20
+34 -20
tools/testing/ktest/ktest.pl
··· 219 219 my $mailto; 220 220 my $mailer; 221 221 my $mail_path; 222 + my $mail_command; 222 223 my $email_on_error; 223 224 my $email_when_finished; 224 225 my $email_when_started; ··· 255 254 "MAILTO" => \$mailto, 256 255 "MAILER" => \$mailer, 257 256 "MAIL_PATH" => \$mail_path, 257 + "MAIL_COMMAND" => \$mail_command, 258 258 "EMAIL_ON_ERROR" => \$email_on_error, 259 259 "EMAIL_WHEN_FINISHED" => \$email_when_finished, 260 260 "EMAIL_WHEN_STARTED" => \$email_when_started, ··· 4135 4133 return eval_option($name, $option, $i); 4136 4134 } 4137 4135 4138 - sub _mailx_send { 4139 - my ($subject, $message) = @_; 4140 - run_command "$mail_path/$mailer -s \'$subject\' $mailto <<< \'$message\'"; 4141 - } 4142 - 4143 - sub _sendmail_send { 4144 - my ($subject, $message) = @_; 4145 - run_command "echo \'Subject: $subject\n\n$message\' | $mail_path/sendmail -t $mailto"; 4146 - } 4147 - 4148 4136 sub find_mailer { 4149 4137 my ($mailer) = @_; 4150 4138 ··· 4152 4160 return undef; 4153 4161 } 4154 4162 4163 + sub do_send_mail { 4164 + my ($subject, $message) = @_; 4165 + 4166 + if (!defined($mail_path)) { 4167 + # find the mailer 4168 + $mail_path = find_mailer $mailer; 4169 + if (!defined($mail_path)) { 4170 + die "\nCan not find $mailer in PATH\n"; 4171 + } 4172 + } 4173 + 4174 + if (!defined($mail_command)) { 4175 + if ($mailer eq "mail" || $mailer eq "mailx") { 4176 + $mail_command = "\$MAIL_PATH/\$MAILER -s \'\$SUBJECT\' \$MAILTO <<< \'\$MESSAGE\'"; 4177 + } elsif ($mailer eq "sendmail" ) { 4178 + $mail_command = "echo \'Subject: \$SUBJECT\n\n\$MESSAGE\' | \$MAIL_PATH/\$MAILER -t \$MAILTO"; 4179 + } else { 4180 + die "\nYour mailer: $mailer is not supported.\n"; 4181 + } 4182 + } 4183 + 4184 + $mail_command =~ s/\$MAILER/$mailer/g; 4185 + $mail_command =~ s/\$MAIL_PATH/$mail_path/g; 4186 + $mail_command =~ s/\$MAILTO/$mailto/g; 4187 + $mail_command =~ s/\$SUBJECT/$subject/g; 4188 + $mail_command =~ s/\$MESSAGE/$message/g; 4189 + 4190 + run_command $mail_command; 4191 + } 4192 + 4155 4193 sub send_email { 4194 + 4156 4195 if (defined($mailto)) { 4157 4196 if (!defined($mailer)) { 4158 4197 doprint "No email sent: email or mailer not specified in config.\n"; 4159 4198 return; 4160 4199 } 4161 - if (!defined($mail_path)) { 4162 - # find the mailer 4163 - $mail_path = find_mailer $mailer; 4164 - if (!defined($mail_path)) { 4165 - die "\nCan not find $mailer in PATH\n"; 4166 - } 4167 - } 4168 - if ($mailer eq "mail" || $mailer eq "mailx"){ _mailx_send(@_);} 4169 - elsif ($mailer eq "sendmail" ) { _sendmail_send(@_);} 4170 - else { die "\nYour mailer: $mailer is not supported.\n" } 4200 + do_send_mail @_; 4171 4201 } 4172 4202 } 4173 4203
+12
tools/testing/ktest/sample.conf
··· 415 415 # (default: for sendmail "/usr/sbin/sendmail", otherwise equals ${MAILER}) 416 416 #MAIL_EXEC = /usr/sbin/sendmail 417 417 # 418 + # The command used to send mail, which uses the above options 419 + # can be modified. By default if the mailer is "sendmail" then 420 + # MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO 421 + # For mail or mailx: 422 + # MAIL_COMMAND = "$MAIL_PATH/$MAILER -s \'$SUBJECT\' $MAILTO <<< \'$MESSAGE\' 423 + # ktest.pl will do the substitution for MAIL_PATH, MAILER, MAILTO at the time 424 + # it sends the mail if "$FOO" format is used. If "${FOO}" format is used, 425 + # then the substitutions will occur at the time the config file is read. 426 + # But note, MAIL_PATH and MAILER require being set by the config file if 427 + # ${MAIL_PATH} or ${MAILER} are used, but not if $MAIL_PATH or $MAILER are. 428 + #MAIL_COMMAND = echo \'Subject: $SUBJECT\n\n$MESSAGE\' | $MAIL_PATH/$MAILER -t $MAILTO 429 + # 418 430 # Errors are defined as those would terminate the script 419 431 # (default 1) 420 432 #EMAIL_ON_ERROR = 1