From f1d44763617f2d3e8c60e6314831da886c97139d Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Mon, 1 Jun 2015 00:37:30 +0200 Subject: gitweb workaround encoding issues in FCGI mode. --- roles/git/files/lib/systemd/system/gitweb.service | 3 ++- .../git/files/usr/lib/cgi-bin/gitweb-wrapper.fcgi | 22 ++++++++++++++++++++++ roles/git/tasks/gitweb.yml | 16 +++++++++------- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100755 roles/git/files/usr/lib/cgi-bin/gitweb-wrapper.fcgi (limited to 'roles') diff --git a/roles/git/files/lib/systemd/system/gitweb.service b/roles/git/files/lib/systemd/system/gitweb.service index a0f7a96..05821ce 100644 --- a/roles/git/files/lib/systemd/system/gitweb.service +++ b/roles/git/files/lib/systemd/system/gitweb.service @@ -7,7 +7,8 @@ Requires=gitweb.socket StandardInput=socket User=gitweb Group=gitweb -ExecStart=/usr/lib/cgi-bin/gitweb.fcgi +Environment=SCRIPT_FILENAME=/usr/lib/cgi-bin/gitweb-wrapper.fcgi +ExecStart=/usr/lib/cgi-bin/gitweb-wrapper.fcgi [Install] WantedBy=multi-user.target diff --git a/roles/git/files/usr/lib/cgi-bin/gitweb-wrapper.fcgi b/roles/git/files/usr/lib/cgi-bin/gitweb-wrapper.fcgi new file mode 100755 index 0000000..a7eea8c --- /dev/null +++ b/roles/git/files/usr/lib/cgi-bin/gitweb-wrapper.fcgi @@ -0,0 +1,22 @@ +#!/usr/bin/perl +# gitweb.cgi wrapper that fixes the UTF-8 problem with fastcgi + +# Local redefinition of FCGI::Stream::PRINT +use Encode; +use FCGI; + +our $enc = Encode::find_encoding('UTF-8'); +our $org = \&FCGI::Stream::PRINT; +no warnings 'redefine'; + +local *FCGI::Stream::PRINT = sub { + my @OUTPUT = @_; + for (my $i = 1; $i < @_; $i++) { + $OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC); + } + @_ = @OUTPUT; + goto $org; +}; + +# Execute original script +do "/usr/lib/cgi-bin/gitweb.cgi"; diff --git a/roles/git/tasks/gitweb.yml b/roles/git/tasks/gitweb.yml index 81d8e3e..a72cc65 100644 --- a/roles/git/tasks/gitweb.yml +++ b/roles/git/tasks/gitweb.yml @@ -13,13 +13,6 @@ notify: - Restart gitweb -# See gitweb(1). To work in Fast CGI mode gitweb checks its filetype. -- name: Symlink 'gitweb.cgi' to 'gitweb.fcgi' - file: src=gitweb.cgi - dest=/usr/lib/cgi-bin/gitweb.fcgi - owner=root group=root - state=link force=no - - name: Create a user 'gitweb' user: name=gitweb system=yes home=/var/www @@ -35,6 +28,15 @@ # for pulls over HTTP/HTTPS - www-data +# XXX workaround encoding issues in FCGI mode +# http://git.661346.n2.nabble.com/Gitweb-running-as-FCGI-does-not-print-its-output-in-UTF-8-td7573415.html +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=720308 +- name: Copy gitweb.cgi wrapper to fix encoding + copy: src=usr/lib/cgi-bin/gitweb-wrapper.fcgi + dest=/usr/lib/cgi-bin/gitweb-wrapper.fcgi + owner=root group=root + mode=0755 + - name: Copy gitweb.{service,socket} copy: src=lib/systemd/system/{{ item }} dest=/lib/systemd/system/{{ item }} -- cgit v1.2.3