Debian Codegraph @

Debconf/Element/Noninteractive/Error.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Noninteractive::Error - noninteractive error message Element
6
7 =cut
8
9 package Debconf::Element::Noninteractive::Error;
10 use warnings;
11 use strict;
12 use Text::Wrap;
13 use Debconf::Gettext;
14 use Debconf::Config;
15 use Debconf::Log ':all';
16 use Debconf::Path;
17 use base qw(Debconf::Element::Noninteractive);
18
19 =head1 DESCRIPTION
20
21 This is a noninteractive error message Element. Since we are running
22 non-interactively, we can't pause to show the error messages. Instead, they
23 are mailed to someone.
24
25 =cut
26
27 =head1 METHODS
28
29 =over 4
30
31 =item show
32
33 Calls sendmail to mail the error, if the error has not been seen before.
34
35 =cut
36
37 sub show {
38 my $this=shift;
39
40 if ($this->question->flag('seen') ne 'true') {
41 $this->sendmail(gettext("Debconf is not confident this error message was displayed, so it mailed it to you."));
42
43 $this->frontend->display($this->question->description."\n\n".
44 $this->question->extended_description."\n");
45 }
46 $this->value('');
47 }
48
49 =item sendmail
50
51 The sendmail method mails the text to root. The external unix mail
52 program is used to do this, if it is present.
53
54 If the mail is successfully sent a true value is returned. Also, the
55 question is marked as seen.
56
57 A footer may be passed as the first parameter; it is generally used to
58 explain why the note was sent.
59
60 =cut
61
62 sub sendmail {
63 my $this=shift;
64 my $footer=shift;
65 return unless length Debconf::Config->admin_email;
66 if (Debconf::Path::find("mail")) {
67 debug user => "mailing a note";
68 my $title=gettext("Debconf").": ".
69 $this->frontend->title." -- ".
70 $this->question->description;
71 unless (open(my $mail, "|-")) { # child
72 exec("mail", "-s", $title, Debconf::Config->admin_email) or return '';
73 }
74 # Let's not clobber this, other parts of debconf might use
75 # Text::Wrap at other spacings.
76 my $old_columns=$Text::Wrap::columns;
77 $Text::Wrap::columns=75;
78 # $Text::Wrap::break=q/\s+/;
79 if ($this->question->extended_description ne '') {
80 print $mail wrap('', '', $this->question->extended_description);
81 }
82 else {
83 # Evil note!
84 print $mail wrap('', '', $this->question->description);
85 }
86 print $mail "\n\n";
87 my $hostname=`hostname -f 2>/dev/null`;
88 if (! defined $hostname) {
89 $hostname="unknown system";
90 }
91 print $mail "-- \n", sprintf(gettext("Debconf, running at %s"), $hostname, "\n");
92 print $mail "[ ", wrap('', '', $footer), " ]\n" if $footer;
93 close $mail or return '';
94
95 $Text::Wrap::columns=$old_columns;
96
97 # Mark this note as seen. The frontend doesn't do this for us,
98 # since we are marked as not visible.
99 $this->question->flag('seen', 'true');
100
101 return 1;
102 }
103 }
104
105 =back
106
107 =head1 AUTHOR
108
109 Joey Hess <[email protected]>
110 Colin Watson <[email protected]>
111
112 =cut
113
114 1