Multiplay Labs

tech hits and tips from Multiplay

Archive for the ‘Perl’ Category

LWP::Protocol::https::Socket: socket: Address family not supported by protocol

without comments

When trying to build LWP::Protocol::https to add https support to libwww the tests fail with:-

LWP::Protocol::https::Socket: socket: Address family not supported by protocol at /usr/lib/perl5/site_perl/5.10/LWP/Protocol/http.pm line 51

After some investigation it turns out there’s nothing wrong with LWP::Protocol::https but IO::Socket::INET6 was broken and trying to interpret : as an IPv6 address instead of IPv4 address + port. Updating to IO::Socket::INET6 v2.69 from the previous v2.57 fixed the issue.

This was encountered under cygwin on Windows in case this is a key factor.

Written by Dilbert

May 24th, 2012 at 7:56 pm

Posted in Code,Cygwin,Perl,Windows

Installing new modules for use with perlapp

without comments

Another really simple little thing when you find it but the ActiveState doc’s really hide how to install new perl modules that are required for compilation with their PDK’s perlapp when targeting a foreign platform.

perlapp --target <target> --target-install <module>

e.g.

perlapp --target windows --target-install JSON::XS

Written by Dilbert

March 21st, 2012 at 9:19 pm

Posted in Perl,Windows

Building DBD::mysql under Cygwin with mysql 5.5

without comments

The following instructions will enable you to build DBD::mysql under Cygwin using mysql 5.5 sources.

1. First download the latest mysql source from http://dev.mysql.com/downloads/mysql/
2. Expand the source and change into the directory e.g. tar -xzf mysql-5.5.21.tar.gz; cd mysql-5.5.21
3. Prepare the Makefiles using cmake, we need to disable shared libs to avoid having to mess with LD_LIBRARY_PATH.

cmake . -DCMAKE_LEGACY_CYGWIN_WIN32=0 -DCMAKE_INSTALL_PREFIX=/usr/local -DDISABLE_SHARED=1

4. Build the client and libs:

make mysqlclient libmysql

4.1. If the build errors with duplicate definition for dtoa, then you can fix it by commenting out the cygwin definition in: /usr/include/stdlib.h (dont forget to remove the comment when done)
5. Install mysql components

sh -c 'for dir in client libmysql scripts include; do cd $dir; make install; cd -; done'

6. Build and install DBD::mysql via CPAN, if you don’t have a running mysql instance you may need to “force” install

perl -MCPAN -e shell
cpan[1]> install DBD::mysql

Written by Dilbert

February 29th, 2012 at 9:29 pm

Posted in Cygwin,Perl

Tagged with , , ,

“version” perl Module Upgrade on SFU results in broken perl!

without comments

For those of you who use SFU, a useful POSIX layer thats freely available for Windows that want to update / install new perl modules using CPAN, be aware that the updated the “version” module can lead to a broken perl install. The resulting symptoms are that perl commands hang doing nothing. The cause of this is that you end up with two “version” module folders, one lower case “version” and one upper-case “Version”.

The fix is simply to remove the old “Version” folder from /usr/local/lib/perl5/site_perl//x86-interix-thread-multi/auto/

Written by Dilbert

June 1st, 2011 at 7:56 pm

Posted in Perl

When unlink in perl doesn’t actually remove the file…

without comments

Ok so this was a weird one, we where using unlink in perl and it was returning success yet the file still exists, so what gives?

After much hunting and digging it turned out to be a nice little gotcha about the way unlink works under cygwin and hence is inherited by their perl implementation.

The basic crux is that in order to be a unix link as possible cygwin makes use of the delete on close function within windows to attempt to delete files that are shared locked by other applications. The result is that even though the file is reported as deleted it is only marked as pending deletion and will only actually be deleted when the last the shared lock counter reaches zero.

Unfortunately its easy for this to fail if the other locking application makes a change to the file the delete request will be silently discarded.

So there you have it, cygwin + perl + unlink = files delete some times, you have been warned.

For more info on the internals see the following: Re: Inconsistent behaviour when removing files on Cygwin

Written by Dilbert

December 7th, 2010 at 12:33 am

Posted in Code,Hackery,Perl

perl Makefile.PL errors with “Unable to find a perl 5” on cygwin

without comments

When trying to build a new module on one of our machines which runs cygwin the basic command perl Makefile.pl failed with the error:

Unable to find a perl 5 (by these names: perl.exe perl.exe perl5.exe perl5.8.0.exe miniperl.exe, in these dirs: /usr/local/bin /usr/bin /bin /usr/X11R6/bin /usr/local/libexec/apache /usr/local/bin /usr/bin /bin /usr/X11R6/bin /cygdrive/c/WINDOWS/system32 /cygdrive/c/WINDOWS /cygdrive/c/WINDOWS/System32/Wbem /cygdrive/c/Program /bin /usr/bin)

After doing some digging this turned out to be a simple permissions issue on the perl.exe although perl scripts would happily run in perl -x /usr/bin/perl.exe was returning false.

The fix was a simple chmod a+x /usr/bin/perl.exe for anyone who comes across this issue.

Written by Dilbert

July 4th, 2009 at 1:29 pm

Posted in Hackery,Perl

Perl CGI.pm problems with query strings under Apache

without comments

Ever had a problem with query strings causing strange behaviour in apache when using the CGI module?
If you have the patch below might just save you some time and effort hunting down the problem.

--- CGI.pm.orig	Sat Mar  1 16:58:19 2008
+++ CGI.pm	Sat Mar  1 18:39:21 2008
@@ -2779,5 +2779,10 @@
    my $raw_script_name = $ENV{SCRIPT_NAME} || '';
    my $raw_path_info   = $ENV{PATH_INFO}   || '';
-   my $uri             = unescape($self->request_uri) || '';
+   my $uri             = $self->request_uri || '';
+
+   # ensure we dont get any query string as that can include escaped //
+   # e.g. a url parameter, which will break the apache bug fix
+   $uri =~ s/\?(.*)$//; 
+   $uri = unescape($uri);
 
    my $protected    = quotemeta($raw_path_info);

Written by Dilbert

February 21st, 2009 at 11:45 pm

Posted in Code,Hackery,Perl

Tagged with , , ,

Running perl scripts from rc.d under FreeBSD

without comments

If you have even tried to run a perl script under FreeBSD’s startup system rc.d then you’ll have hit upon a little problem where it doesnt correctly recognise the running process on shutdown. There’s a simple fix for this just apply the patch below and you’ll be good to go.

--- /etc/rc.subr.orig	Mon Oct  8 18:31:34 2007
+++ /etc/rc.subr	Mon Oct  8 18:32:31 2007
@@ -271,5 +271,5 @@
 		_fp_args='_argv'
 		_fp_match='case "$_argv" in
-		    ${_interp}|"${_interp} "*|"${_interpbn}: ${_procname}"*)'
+		    ${_interp}|"${_interp} "*|"[${_interpbn}]"|"${_interpbn}: ${_procname}"*)'
 	else					# a normal daemon
 		_procnamebn=${_procname##*/}

Written by Dilbert

February 21st, 2009 at 11:40 pm

Posted in Hackery,Perl

Tagged with , , ,