2
# Copyright (C) 2004-2006 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
use base qw(Exporter);
24
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
25
native_path posix_path mixed_path
26
check_socket_path_length process_alive);
29
if ($^O eq "cygwin") {
30
# Make sure cygpath works
31
if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
32
die "Could not execute 'cygpath': $!";
34
eval 'sub IS_CYGWIN { 1 }';
37
eval 'sub IS_CYGWIN { 0 }';
39
if ($^O eq "MSWin32") {
40
eval 'sub IS_WIN32PERL { 1 }';
43
eval 'sub IS_WIN32PERL { 0 }';
48
if (IS_CYGWIN or IS_WIN32PERL) {
49
eval 'sub IS_WINDOWS { 1 }';
52
eval 'sub IS_WINDOWS { 0 }';
59
# Convert from path format used by perl to the underlying
60
# operating systems format
63
# Used when running windows binaries (that expect windows paths)
64
# in cygwin perl (that uses unix paths)
69
memoize('mixed_path');
70
memoize('native_path');
71
memoize('posix_path');
77
return unless defined $path;
78
my $cmd= "cygpath -m $path";
80
print "Failed to run: '$cmd', $!\n";
89
if (IS_CYGWIN or IS_WIN32PERL);
96
return unless defined $path;
97
$path= `cygpath $path`;
103
use File::Temp qw /tempdir/;
105
sub check_socket_path_length {
108
return 0 if IS_WINDOWS;
109
# This may not be true, but we can't test for it on AIX due to Perl bug
111
return 0 if ($^O eq 'aix');
113
require IO::Socket::UNIX;
115
my $truncated= undef;
117
# Create a tempfile name with same length as "path"
118
my $tmpdir = tempdir( CLEANUP => 0);
119
my $len = length($path) - length($tmpdir) - 1;
120
my $testfile = $tmpdir . "/" . "x" x ($len > 0 ? $len : 1);
123
$sock= new IO::Socket::UNIX
128
$truncated= 1; # Be negatvie
130
die "Could not create UNIX domain socket: $!"
131
unless defined $sock;
133
die "UNIX domain socket path was truncated"
134
unless ($testfile eq $sock->hostpath());
136
$truncated= 0; # Yes, it worked!
140
die "Unexpected failure when checking socket path length: $@"
141
if $@ and not defined $truncated;
143
$sock= undef; # Close socket
144
rmtree($tmpdir); # Remove the tempdir and any socket file created
151
die "usage: process_alive(pid)" unless $pid;
153
return kill(0, $pid) unless IS_WINDOWS;
155
my @list= split(/,/, `tasklist /FI "PID eq $pid" /NH /FO CSV`);
156
my $ret_pid= eval($list[1]);
157
return ($ret_pid == $pid);