2
# Copyright (c) 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
3
# Use is subject to license terms.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; version 2 of the License.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
use base qw(Exporter);
25
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
26
native_path posix_path mixed_path
27
check_socket_path_length process_alive);
30
if ($^O eq "cygwin") {
31
# Make sure cygpath works
32
if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
33
die "Could not execute 'cygpath': $!";
35
eval 'sub IS_CYGWIN { 1 }';
38
eval 'sub IS_CYGWIN { 0 }';
40
if ($^O eq "MSWin32") {
41
eval 'sub IS_WIN32PERL { 1 }';
44
eval 'sub IS_WIN32PERL { 0 }';
49
if (IS_CYGWIN or IS_WIN32PERL) {
50
eval 'sub IS_WINDOWS { 1 }';
53
eval 'sub IS_WINDOWS { 0 }';
60
# Convert from path format used by perl to the underlying
61
# operating systems format
64
# Used when running windows binaries (that expect windows paths)
65
# in cygwin perl (that uses unix paths)
70
memoize('mixed_path');
71
memoize('native_path');
72
memoize('posix_path');
78
return unless defined $path;
79
my $cmd= "cygpath -m $path";
81
print "Failed to run: '$cmd', $!\n";
90
if (IS_CYGWIN or IS_WIN32PERL);
97
return unless defined $path;
98
$path= `cygpath $path`;
104
use File::Temp qw /tempdir/;
106
sub check_socket_path_length {
109
return 0 if IS_WINDOWS;
110
# This may not be true, but we can't test for it on AIX due to Perl bug
112
return 0 if ($^O eq 'aix');
113
# Similarly the path length is hidden.
114
# See Debian bug #651002
115
return 0 if ($^O eq 'gnu');
117
require IO::Socket::UNIX;
119
my $truncated= undef;
121
# Create a tempfile name with same length as "path"
122
my $tmpdir = tempdir( CLEANUP => 0);
123
my $len = length($path) - length($tmpdir) - 1;
124
my $testfile = $tmpdir . "/" . "x" x ($len > 0 ? $len : 1);
127
$sock= new IO::Socket::UNIX
132
$truncated= 1; # Be negatvie
134
die "Could not create UNIX domain socket: $!"
135
unless defined $sock;
137
die "UNIX domain socket path was truncated"
138
unless ($testfile eq $sock->hostpath());
140
$truncated= 0; # Yes, it worked!
144
die "Unexpected failure when checking socket path length: $@"
145
if $@ and not defined $truncated;
147
$sock= undef; # Close socket
148
rmtree($tmpdir); # Remove the tempdir and any socket file created
155
die "usage: process_alive(pid)" unless $pid;
157
return kill(0, $pid) unless IS_WINDOWS;
159
my @list= split(/,/, `tasklist /FI "PID eq $pid" /NH /FO CSV`);
160
my $ret_pid= eval($list[1]);
161
return ($ret_pid == $pid);