YANO's digital garage

Copyright ©YANO All rights reserved. https://www.bravotouring.com/~yano/

Last-modified: 2024-03-20 (水)


[一語一絵/IT系]

pngcntr改修 / 2021-02-06 (土)

Ubuntu 20.04 (Focal Fossa)アップデートの残課題、「CGIでも使えるPNG式画像カウンタ」(pngcntr)が動かない問題にようやく立ち向かうことに。

まずはコマンドライン実行でもどこでコケているのかわかるように $err を X-PNGCNT-Error: で出力するようにしてみたところ、エラー -1を返すポイントが3箇所あった…orz

yano@vps:/usr/lib/cgi-bin/pngcnt$ diff -bc ct_20161115.cgi ct_20210206.cgi
*** ct_20161115.cgi     2016-11-15 10:53:50.382253440 +0900
--- ct_20210206.cgi     2021-02-06 11:01:00.000000000 +0900
***************
*** 233,238 ****
--- 233,239 ----
  {
        my($err) = @_;

+       print "X-PNGCNT-Error: $err \n";
        $err = 4 if($err >= 100);

        print "Content-Type: image/png\n\n";
***************
*** 558,569 ****
                        }
                        else
                        {
!                               return &Error(-1);
                        }
                }
                else
                {
!                       return &Error(-1);
                }
        }
        else    # ログファイルが読み込めず。
--- 559,570 ----
                        }
                        else
                        {
!                               return &Error(-3);
                        }
                }
                else
                {
!                       return &Error(-2);
                }
        }
        else    # ログファイルが読み込めず。
yano@vps:/usr/lib/cgi-bin/pngcnt$ ./ct_20210206.cgi
Set-Cookie: =1; expires=Sat, 06 Feb 2021 02:10:12 GMT;
X-PNGCNT-Error: -1
Content-Type: image/png

        PNG
~~
yano@vps:/usr/lib/cgi-bin/pngcnt$
というわけで、エラー-1を返すポイントが require の部分と判明。

試行錯誤を繰り返したところ、require のファイルパスに./を付与する事で解決できたので、

yano@vps:/usr/lib/cgi-bin/pngcnt$ diff -bc ct_20210206.cgi ct.cgi
*** ct_20210206.cgi     2021-02-06 11:01:00.000000000 +0900
--- ct.cgi      2021-02-06 11:25:11.544278164 +0900
***************
*** 485,491 ****

        if($main::gztype eq 'png')
        {
!               eval { require 'pngren.pl'; };

                if($opts{'check'})
                {
--- 485,491 ----

        if($main::gztype eq 'png')
        {
!               eval { require './pngren.pl'; };

                if($opts{'check'})
                {
***************
*** 549,555 ****
                }
                elsif($main::gztype eq 'gif')
                {
!                       eval { require 'gifcat.pl'; };
                        if(!$@)
                        {
                                @gz = map("$main::gzdir$_.gif", @narabi);
--- 549,555 ----
                }
                elsif($main::gztype eq 'gif')
                {
!                       eval { require './gifcat.pl'; };
                        if(!$@)
                        {
                                @gz = map("$main::gzdir$_.gif", @narabi);
yano@vps:/usr/lib/cgi-bin/pngcnt$ diff -c pngren_20040622.pl pngren_20210206.pl
*** pngren_20040622.pl  2004-06-22 00:00:00.000000000 +0900
--- pngren_20210206.pl  2021-02-06 11:26:40.343152364 +0900
***************
*** 35,42 ****

  # 設定。
  $pngren::version = 2.0.1;
! $pngren::koLibrary   = 'pngrenhz.pl';
! $pngren::zlibLibrary = 'pryzlib.pl';
  $pngren::cacheChunk  = 'prYC';                # 0x25-0x28 (4bytes)
  $pngren::cacheVersion = "\x02\0\0";   # 0x29-0x2b (3bytes)
  $pngren::USEMYZLIB = 0;
--- 35,42 ----

  # 設定。
  $pngren::version = 2.0.1;
! $pngren::koLibrary   = './pngrenhz.pl';
! $pngren::zlibLibrary = './pryzlib.pl';
  $pngren::cacheChunk  = 'prYC';                # 0x25-0x28 (4bytes)
  $pngren::cacheVersion = "\x02\0\0";   # 0x29-0x2b (3bytes)
  $pngren::USEMYZLIB = 0;
yano@vps:/usr/lib/cgi-bin/pngcnt$
てな感じで改修。 perlそのもののバージョンは
This is perl 5, version 18, subversion 0 (v5.18.0) built for x86_64-linux

Copyright 1987-2013, Larry Wall
と、変わってないような気がするんだけれどなぁ…

【参照】
●nonki@rNote http://nonki.ffvv.net/
「CGIでも使えるPNG式画像カウンタ」の再配布
●Ubuntu Wiki https://wiki.ubuntu.com/
FocalFossa/ReleaseNotes/Ja
●Wikipedia http://ja.wikipedia.org/wiki/
Ubuntu
Ubuntuのバージョン履歴