LittleJack has asked for the wisdom of the Perl Monks concerning the following question:

I want to preface this question with the fact that

My task was this: view an image in a browser, click on something in the image, have perl run an ImageMagick command to modify the image.

It's not a great setup, but it's worked for me before. The problem is that I'm doing it on an M2 Mac.

This is basically it:

my $command = "/opt/local/bin/convert foo.jpg -crop ${w}x$h+$x+$x ./cr +opped/foo.jpg"; my $result = `$command`; say qq|{"result":"$result"}|;

So on my M2 mac, I get 6 as the result, and the convert doesn't work.

I solved the problem by just implementing it on an older Mac.

But what's going on here? My Apache is the XAMPP one:

Server version: Apache/2.4.56 (Unix) Server built: Oct 28 2023 12:23:23 Server's Module Magic Number: 20120211:126 Server loaded: APR 1.5.2, APR-UTIL 1.5.4, PCRE 8.44 2020-02-12 Compiled using: APR 1.5.2, APR-UTIL 1.5.4, PCRE 8.44 2020-02-12 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_FLOCK_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/usr" -D SUEXEC_BIN="/usr/bin/suexec" -D DEFAULT_PIDLOG="/private/var/run/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types" -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

My perl is:

Platform: osname=darwin osvers=22.0 archname=darwin-thread-multi-2level uname='darwin 5bxbb.p1s.plx.sd.apple.com 22.0 darwin kernel versio +n 22.1.0: thu dec 15 17:42:24 pst 2022; root:xnu-8792.41.9.100.2~1dev +elopment_x86_64 x86_64 ' config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= +-Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc +=cc'

My ImageMagick is:

Version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagi +ck.org

So, for some reason, that combination doesn't work and the system returns 6 which seems to mean "no such binary"?

Help me understand what's going on here Monks, and how I can resolve things like this in the future without having to return to an older Mac system?

Replies are listed 'Best First'.
Re: Perl on M2 Mac issues: somewhere between Perl, Apache and ImageMagick my code fails
by bliako (Abbot) on Oct 24, 2024 at 06:58 UTC

    I do not know much about apache, this is on the perl side of your problem.

    my $result = `$command`; ... executed  as  a system  command,  via /bin/sh or its equivalent if required. see qx/STRING/

    So, additionally to checking 1) if the convert binary is indeed installed in said location, 2) if apache is allowed to execute arbitrary binaries from arbitrary filesystem locations, 3) if the current apache user is allowed to do the above for the specific binary, you must also check if apache is also allowed to spawn a shell (and knows where to find its binary).

    In order to debug this, I would use Perl's system command passing the command as an array in order to run the convert binary without spawning an intermediate shell, e.g.:

    my @command = ( "/opt/local/bin/convert", "foo.jpg". "-crop", "${w}x$h+$x+$x", "./cropped/foo.jpg" ); my $ret = system(@command);

    Make sure you check $ret to be zero for successful execution, otherwise check system on how to decipher the return code.

    Also, I would try a different, simple binary, check its permissions, move the binary in the current directory where you make sure the apache user has permissions, etc.

    Also, please have a look at The problem of "the" default shell and the comments therein which provide system()/qx/`` alternatives (for example: Re: The problem of "the" default shell).

    p.s. There may be apache or system logs to explain what happened.

    EDIT: Question: where is that exit code (6) documented?

    bw, bliako

      Also note that qx{} doesn't return an exit code (you can find it in $? instead), but the standard output of the command. So, for some reason, convert outputs 6.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        very useful, convert does run then

      Sorry I should have confirmed that the convert command is absolutely correct, it runs successfully from the command line, and the CGI script runs successfully from the command line.

      I got the interpretation of return code 6 from here: here where it says it's ENXIO 6 No such device or address but that may be the wrong information.