Revision f1648f3c
Von Cem Aydin vor etwa 2 Jahren hinzugefügt
SL/Template/OpenDocument.pm | ||
---|---|---|
582 | 582 |
return $outfile; |
583 | 583 |
} |
584 | 584 |
|
585 |
sub is_xvfb_running { |
|
586 |
$main::lxdebug->enter_sub(); |
|
587 |
|
|
588 |
my ($self) = @_; |
|
589 |
|
|
590 |
local *IN; |
|
591 |
my $dfname = $self->{"userspath"} . "/xvfb_display"; |
|
592 |
my $display; |
|
593 |
|
|
594 |
$main::lxdebug->message(LXDebug->DEBUG2(), " Looking for $dfname\n"); |
|
595 |
if ((-f $dfname) && open(IN, $dfname)) { |
|
596 |
my $pid = <IN>; |
|
597 |
chomp($pid); |
|
598 |
$display = <IN>; |
|
599 |
chomp($display); |
|
600 |
my $xauthority = <IN>; |
|
601 |
chomp($xauthority); |
|
602 |
close(IN); |
|
603 |
|
|
604 |
$main::lxdebug->message(LXDebug->DEBUG2(), " found with $pid and $display\n"); |
|
605 |
|
|
606 |
if ((! -d "/proc/$pid") || !open(IN, "/proc/$pid/cmdline")) { |
|
607 |
$main::lxdebug->message(LXDebug->DEBUG2(), " no/wrong process #1\n"); |
|
608 |
unlink($dfname, $xauthority); |
|
609 |
$main::lxdebug->leave_sub(); |
|
610 |
return undef; |
|
611 |
} |
|
612 |
my $line = <IN>; |
|
613 |
close(IN); |
|
614 |
if ($line !~ /xvfb/i) { |
|
615 |
$main::lxdebug->message(LXDebug->DEBUG2(), " no/wrong process #2\n"); |
|
616 |
unlink($dfname, $xauthority); |
|
617 |
$main::lxdebug->leave_sub(); |
|
618 |
return undef; |
|
619 |
} |
|
620 |
|
|
621 |
$ENV{"XAUTHORITY"} = $xauthority; |
|
622 |
$ENV{"DISPLAY"} = $display; |
|
623 |
} else { |
|
624 |
$main::lxdebug->message(LXDebug->DEBUG2(), " not found\n"); |
|
625 |
} |
|
626 |
|
|
627 |
$main::lxdebug->leave_sub(); |
|
628 |
|
|
629 |
return $display; |
|
630 |
} |
|
631 |
|
|
632 |
sub spawn_xvfb { |
|
633 |
$main::lxdebug->enter_sub(); |
|
634 |
|
|
635 |
my ($self) = @_; |
|
636 |
|
|
637 |
$main::lxdebug->message(LXDebug->DEBUG2, "spawn_xvfb()\n"); |
|
638 |
|
|
639 |
my $display = $self->is_xvfb_running(); |
|
640 |
|
|
641 |
if ($display) { |
|
642 |
$main::lxdebug->leave_sub(); |
|
643 |
return $display; |
|
644 |
} |
|
645 |
|
|
646 |
$display = 99; |
|
647 |
while ( -f "/tmp/.X${display}-lock") { |
|
648 |
$display++; |
|
649 |
} |
|
650 |
$display = ":${display}"; |
|
651 |
$main::lxdebug->message(LXDebug->DEBUG2(), " display $display\n"); |
|
652 |
|
|
653 |
my $mcookie = `mcookie`; |
|
654 |
die("Installation error: mcookie not found.") if ($? != 0); |
|
655 |
chomp($mcookie); |
|
656 |
|
|
657 |
$main::lxdebug->message(LXDebug->DEBUG2(), " mcookie $mcookie\n"); |
|
658 |
|
|
659 |
my $xauthority = "/tmp/.Xauthority-" . $$ . "-" . time() . "-" . int(rand(9999999)); |
|
660 |
$ENV{"XAUTHORITY"} = $xauthority; |
|
661 |
|
|
662 |
$main::lxdebug->message(LXDebug->DEBUG2(), " xauthority $xauthority\n"); |
|
663 |
|
|
664 |
if (system("xauth add \"${display}\" . \"${mcookie}\"") == -1) { |
|
665 |
die "system call to xauth failed: $!"; |
|
666 |
} |
|
667 |
if ($? != 0) { |
|
668 |
$self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started (xauth: $!)"; |
|
669 |
$main::lxdebug->leave_sub(); |
|
670 |
return undef; |
|
671 |
} |
|
672 |
|
|
673 |
$main::lxdebug->message(LXDebug->DEBUG2(), " about to fork()\n"); |
|
674 |
|
|
675 |
my $pid = fork(); |
|
676 |
if (0 == $pid) { |
|
677 |
$main::lxdebug->message(LXDebug->DEBUG2(), " Child execing\n"); |
|
678 |
exec($::lx_office_conf{applications}->{xvfb}, $display, "-screen", "0", "640x480x8", "-nolisten", "tcp"); |
|
679 |
} |
|
680 |
sleep(3); |
|
681 |
$main::lxdebug->message(LXDebug->DEBUG2(), " parent dont sleeping\n"); |
|
682 |
|
|
683 |
local *OUT; |
|
684 |
my $dfname = $self->{"userspath"} . "/xvfb_display"; |
|
685 |
if (!open(OUT, ">", $dfname)) { |
|
686 |
$self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started ($dfname: $!)"; |
|
687 |
unlink($xauthority); |
|
688 |
kill($pid); |
|
689 |
$main::lxdebug->leave_sub(); |
|
690 |
return undef; |
|
691 |
} |
|
692 |
print(OUT "$pid\n$display\n$xauthority\n"); |
|
693 |
close(OUT); |
|
694 |
|
|
695 |
$main::lxdebug->message(LXDebug->DEBUG2(), " parent re-testing\n"); |
|
696 |
|
|
697 |
if (!$self->is_xvfb_running()) { |
|
698 |
$self->{"error"} = "Conversion to PDF failed because OpenOffice could not be started."; |
|
699 |
unlink($xauthority, $dfname); |
|
700 |
kill($pid); |
|
701 |
$main::lxdebug->leave_sub(); |
|
702 |
return undef; |
|
703 |
} |
|
704 |
|
|
705 |
$main::lxdebug->message(LXDebug->DEBUG2(), " spawn OK\n"); |
|
706 |
|
|
707 |
$main::lxdebug->leave_sub(); |
|
708 |
|
|
709 |
return $display; |
|
710 |
} |
|
711 |
|
|
712 | 585 |
sub _run_python_uno { |
713 | 586 |
my ($self, @args) = @_; |
714 | 587 |
|
... | ... | |
820 | 693 |
$ENV{'HOME'} = getcwd() . "/" . $self->{"userspath"}; |
821 | 694 |
} |
822 | 695 |
|
823 |
if (!$self->spawn_xvfb()) { |
|
824 |
$main::lxdebug->leave_sub(); |
|
825 |
return 0; |
|
826 |
} |
|
827 |
|
|
828 | 696 |
if (!$::lx_office_conf{print_templates}->{openofficeorg_daemon}) { |
829 | 697 |
if (system($::lx_office_conf{applications}->{openofficeorg_writer}, |
830 | 698 |
"--minimized", "--norestore", "--nologo", "--nolockcheck", "--headless", |
Auch abrufbar als: Unified diff
OpenDocument PDF Erzeugung: Xvfb wird nicht mehr gebraucht um libreoffice auf dem Server zu starten
- libreoffice wird mit --headless gestartet, das funktioniert auch ohne Xvfb, getestet auch mit openofficeorg_daemon Variante