| 1 |
=head1 NAME |
| 2 |
|
| 3 |
Debconf::FrontEnd::Kde - GUI Kde frontend |
| 4 |
|
| 5 |
=cut |
| 6 |
|
| 7 |
package Debconf::FrontEnd::Kde; |
| 8 |
|
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
use IO::Handle; |
| 12 |
use Fcntl; |
| 13 |
use POSIX ":sys_wait_h"; |
| 14 |
use Debconf::Config; |
| 15 |
use base "Debconf::FrontEnd::Passthrough"; |
| 16 |
|
| 17 |
=head1 DESCRIPTION |
| 18 |
|
| 19 |
This frontend is a recommended KDE UI for Debconf. This frontend relays all |
| 20 |
requests to the debconf-kde-helper application via Debconf Passthrough |
| 21 |
protocol. The latter takes care of displaying actual UI. |
| 22 |
|
| 23 |
By default, debugging output from debconf-kde-helper is silenced. If you need |
| 24 |
to see it, set C<DEBCONF_DEBUG=kde> in the environment. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
=head2 clear_fd_cloexec |
| 29 |
|
| 30 |
Clears FD_CLOEXEC flag for the specified file descriptor |
| 31 |
|
| 32 |
=cut |
| 33 |
|
| 34 |
sub clear_fd_cloexec { |
| 35 |
my $fh = shift; |
| 36 |
my $flags; |
| 37 |
$flags = $fh->fcntl(F_GETFD, 0); |
| 38 |
$flags &= ~FD_CLOEXEC; |
| 39 |
$fh->fcntl(F_SETFD, $flags); |
| 40 |
} |
| 41 |
|
| 42 |
=head2 init |
| 43 |
|
| 44 |
This function takes care of starting and preparing debconf-kde-helper for the |
| 45 |
communication with Debconf. It opens a pair of FIFO pipes and passes one end to |
| 46 |
the debconf-kde-helper process and the other end to the Passthrough frontend. |
| 47 |
Before returning, it makes sure that debconf-kde-helper is ready to accept |
| 48 |
commands. |
| 49 |
|
| 50 |
=cut |
| 51 |
|
| 52 |
sub init { |
| 53 |
my $this = shift; |
| 54 |
|
| 55 |
$this->need_tty(0); |
| 56 |
|
| 57 |
# FIFO pipe for debconf -> helper (dc2hp) communication |
| 58 |
pipe my $dc2hp_readfh, my $dc2hp_writefh; |
| 59 |
# FIFO pipe for helper -> debconf (hp2dc) communication |
| 60 |
pipe my $hp2dc_readfh, my $hp2dc_writefh; |
| 61 |
|
| 62 |
my $helper_pid = fork(); |
| 63 |
if (!defined $helper_pid) { |
| 64 |
die "Unable to fork for execution of debconf-kde-helper: $!\n"; |
| 65 |
} elsif ($helper_pid == 0) { |
| 66 |
# Child: execute debconf-kde-helper |
| 67 |
# Close unneeded file handles for this end. |
| 68 |
close $hp2dc_readfh; |
| 69 |
close $dc2hp_writefh; |
| 70 |
# Clear FD_CLOEXEC flags |
| 71 |
clear_fd_cloexec($dc2hp_readfh); |
| 72 |
clear_fd_cloexec($hp2dc_writefh); |
| 73 |
my $debug = Debconf::Config->debug; |
| 74 |
local $ENV{QT_LOGGING_RULES} = 'org.kde.debconf.debug=false' |
| 75 |
unless $debug && 'kde' =~ /$debug/; |
| 76 |
my $fds = sprintf("%d,%d", $dc2hp_readfh->fileno(), $hp2dc_writefh->fileno()); |
| 77 |
if (!exec("debconf-kde-helper", "--fifo-fds=$fds")) { |
| 78 |
print STDERR "Unable to execute debconf-kde-helper - is debconf-kde-helper installed?"; |
| 79 |
exit(10); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
# Parent process |
| 84 |
# Close unneeded file handles for this end |
| 85 |
close $dc2hp_readfh; |
| 86 |
close $hp2dc_writefh; |
| 87 |
|
| 88 |
# Initialize Passthrough frontend |
| 89 |
$this->{kde_helper_pid} = $helper_pid; |
| 90 |
$this->{readfh} = $hp2dc_readfh; |
| 91 |
$this->{writefh} = $dc2hp_writefh; |
| 92 |
$this->SUPER::init(); |
| 93 |
|
| 94 |
# Ping debconf-kde-helper and wait for the reply for 15 seconds |
| 95 |
my $timeout = 15; |
| 96 |
my $tag = $this->talk_with_timeout($timeout, "X_PING"); |
| 97 |
unless (defined $tag && $tag == 0) { |
| 98 |
close $hp2dc_readfh; |
| 99 |
close $dc2hp_writefh; |
| 100 |
if (waitpid($helper_pid, WNOHANG) == $helper_pid) { |
| 101 |
# debconf-helper-kde has probably died already |
| 102 |
die "debconf-kde-helper terminated abnormally (exit status: " . WEXITSTATUS($?) . ")\n"; |
| 103 |
} elsif (kill(0, $helper_pid) == 1) { |
| 104 |
# It has hung or something like that. Kill it forcefully. |
| 105 |
kill 9, $helper_pid; |
| 106 |
# Collect zombie |
| 107 |
waitpid($helper_pid, 0); |
| 108 |
} |
| 109 |
if (defined $tag) { |
| 110 |
die "debconf-kde-helper failed to respond to ping. Response was $tag\n"; |
| 111 |
} else { |
| 112 |
die "debconf-kde-helper did not respond to ping in $timeout seconds\n"; |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
=head2 shutdown |
| 118 |
|
| 119 |
Closes pipes and waits for the debconf-kde-helper process to finish. |
| 120 |
|
| 121 |
=cut |
| 122 |
|
| 123 |
sub shutdown { |
| 124 |
my $this = shift; |
| 125 |
$this->SUPER::shutdown(); |
| 126 |
if (defined $this->{kde_helper_pid}) { |
| 127 |
waitpid $this->{kde_helper_pid}, 0; |
| 128 |
delete $this->{kde_helper_pid}; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
=head1 AUTHOR |
| 133 |
|
| 134 |
Modestas Vainius <[email protected]> |
| 135 |
|
| 136 |
=cut |
| 137 |
|
| 138 |
1; |