Skip to content

Commit 89c3248

Browse files
committed
skeleton implementations
1 parent b14a696 commit 89c3248

14 files changed

+714
-5
lines changed

.TRAVIS.PL

+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#/usr/bin/env perl
2+
3+
use strict;
4+
use warnings;
5+
use utf8;
6+
7+
use Cwd ();
8+
use Symbol qw/gensym/;
9+
use IPC::Open3 qw/open3/;
10+
use IO::Select;
11+
use POSIX qw/:sys_wait_h/;
12+
13+
use Test::Most;
14+
15+
sub run_cmd (@)
16+
{
17+
my %args = @_;
18+
19+
my $cmd = $args{cmd};
20+
my @args = defined($args{args}) ? @{$args{args}} : ();
21+
my $in = $args{in};
22+
my $timeout = $args{timeout};
23+
my $quiet = $args{quiet};
24+
my $cb_out = $args{cb_out};
25+
my $cb_err = $args{cb_err};
26+
my $nb = $args{nb} // 4096;
27+
28+
if (!defined($cmd))
29+
{
30+
warn '[ERR] Invalid parameter: cmd';
31+
return undef;
32+
}
33+
34+
$timeout = 60 if (!defined($timeout) || $timeout !~ m/^\d+$/);
35+
$timeout = undef if ($timeout == 0);
36+
37+
# :TODO 12/31/2014 03:47:37 PM Ji-Hyeon Gim
38+
# 예전에 잠깐 집어넣었다가 안쓸거 같아서 뺐었던 기억이 나는데...
39+
# 매개변수 in에 문자열이 아니라 파일 핸들을 받는 경우에 대한 처리를
40+
# 포함할 것인지 생각해보자.
41+
# 그럴 경우 예전처럼 gensym으로 만들어진 cmd_in이 아니라 바로 in을
42+
# 넘겨주면 되는거니까...
43+
44+
# generate symbol
45+
my ($cmd_in, $cmd_out, $cmd_err) = map gensym, 1..3;
46+
47+
# Open Process
48+
my $pid = open3($cmd_in, $cmd_out, $cmd_err, $cmd, @args);
49+
my $start = time;
50+
51+
# For selecting.
52+
my $select_handle = IO::Select->new();
53+
54+
if (defined($in))
55+
{
56+
print $cmd_in $in;
57+
58+
#$select_handle->add($cmd_in);
59+
#
60+
#while (my @ready = $select_handle->can_write($timeout))
61+
#{
62+
# foreach my $handle (@ready)
63+
# {
64+
# syswrite($handle, $in);
65+
# }
66+
#}
67+
#
68+
#$select_handle->remove($cmd_in);
69+
}
70+
71+
$select_handle->add($cmd_out);
72+
$select_handle->add($cmd_err);
73+
74+
my $out = '';
75+
my $err = '';
76+
77+
while (my @ready = $select_handle->can_read($timeout))
78+
{
79+
foreach my $handle (@ready)
80+
{
81+
my $buf = '';
82+
83+
# Non-Buffered I/O
84+
if ($nb)
85+
{
86+
if (sysread($handle, $buf, $nb))
87+
{
88+
if ($handle == $cmd_out)
89+
{
90+
if ($cb_out)
91+
{
92+
local $_ = $buf;
93+
chomp($_);
94+
$cb_out->();
95+
}
96+
97+
$out .= $buf;
98+
}
99+
elsif ($handle == $cmd_err)
100+
{
101+
if ($cb_err)
102+
{
103+
local $_ = $buf;
104+
chomp($_);
105+
$cb_err->();
106+
}
107+
108+
$err .= $buf;
109+
}
110+
}
111+
else
112+
{
113+
# EOF or Error
114+
$select_handle->remove($handle);
115+
}
116+
}
117+
else
118+
{
119+
$buf = <$handle>;
120+
121+
if ($buf)
122+
{
123+
if ($handle == $cmd_out)
124+
{
125+
if ($cb_out)
126+
{
127+
local $_ = $buf;
128+
chomp($_);
129+
$cb_out->();
130+
}
131+
132+
$out .= $buf;
133+
}
134+
elsif ($handle == $cmd_err)
135+
{
136+
if ($cb_err)
137+
{
138+
local $_ = $buf;
139+
chomp($_);
140+
$cb_err->();
141+
}
142+
143+
$err .= $buf;
144+
}
145+
}
146+
else
147+
{
148+
# EOF or Error
149+
$select_handle->remove($handle);
150+
}
151+
}
152+
}
153+
}
154+
155+
close($cmd_in);
156+
close($cmd_out);
157+
close($cmd_err);
158+
159+
my $is_timeout = 0;
160+
161+
# check whether timeout or not.
162+
if ($select_handle->count)
163+
{
164+
kill('TERM', $pid);
165+
$is_timeout = 1;
166+
}
167+
168+
my ($kid, $reap_count) = (0, 0);
169+
170+
do {
171+
select(undef, undef, undef, 0.05);
172+
$kid = waitpid($pid, WNOHANG);
173+
} until ($kid > 0 || ++$reap_count >= 10);
174+
175+
my $status = undef;
176+
177+
if ($kid > 0)
178+
{
179+
$status = $?>>8;
180+
}
181+
182+
chomp($out);
183+
chomp($err);
184+
185+
if ($out =~ m/^open3:/)
186+
{
187+
warn "[ERR] Failed to execute with open3: $cmd";
188+
return undef;
189+
}
190+
191+
return {
192+
cmd => @args ? join(' ', $cmd, @args) : $cmd,
193+
pid => $kid,
194+
status => ($is_timeout) ? -1 : $status,
195+
out => $out,
196+
err => ($is_timeout) ? 'Timeout exceeded' : $err,
197+
runtime => time - $start,
198+
};
199+
}
200+
201+
sub test_libgfapi
202+
{
203+
my $retval = run_cmd(
204+
cmd => 'make test TEST_VERBOSE=1',
205+
cb_out => sub { print STDOUT "$_\n"; },
206+
cb_err => sub { print STDERR "$_\n"; });
207+
208+
if (!defined($retval) || $retval->{status})
209+
{
210+
die $retval->{status};
211+
}
212+
213+
return 0;
214+
}
215+
216+
our $ROOT = Cwd::abs_path(Cwd::cwd());
217+
218+
ok(1, 'libgfapi-perl');
219+
220+
test_libgfapi();
221+
222+
done_testing();

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.swp
2+
*.old

.travis.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
branches:
2+
only:
3+
- master
4+
- /^v\d/
5+
6+
notifications:
7+
email: false
8+
9+
sudo: required
10+
11+
language: perl
12+
13+
dist: trusty
14+
15+
perl:
16+
- "5.10"
17+
- "5.14"
18+
- "5.18"
19+
- "5.20"
20+
- "5.22"
21+
- "5.24"
22+
23+
before_install:
24+
- sudo apt-get update
25+
- sudo apt-get install -y glusterfs-server glusterfs-client libacl1 attr
26+
27+
install:
28+
- cpanm -quiet --notest --skip-satisfied --installdeps .
29+
30+
script:
31+
- perl .TRAVIS.PL

.travis.yml.docker

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
branches:
2+
only:
3+
- master
4+
- /^v\d/
5+
6+
notifications:
7+
email: false
8+
9+
sudo: required
10+
11+
services:
12+
- docker
13+
14+
env:
15+
matrix:
16+
- OS_TYPE=centos:6
17+
- OS_TYPE=centos:7
18+
19+
language: perl
20+
21+
perl:
22+
- "5.24"
23+
24+
before_install:
25+
- sudo apt-get update
26+
- echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s devicemapper"' | sudo tee /etc/default/docker > /dev/null
27+
- sudo service docker restart
28+
- sleep 5
29+
- sudo docker pull $OS_TYPE
30+
31+
install: "perl -e 1" # dummy
32+
33+
script:
34+
- "perl t/travis.t ${OS_TYPE}"

Changes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
0.01 2017-05-13 19:21:45 Asia/Seoul
3+
4+
- Initial release

LICENSE

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
This software is Copyright (c) 2017 by Ji-Hyeon Gim.
2+
3+
This is free software, licensed under:
4+
5+
The GNU General Public License, Version 3, June 2007
6+
17
GNU GENERAL PUBLIC LICENSE
28
Version 3, 29 June 2007
39

@@ -631,8 +637,8 @@ to attach them to the start of each source file to most effectively
631637
state the exclusion of warranty; and each file should have at least
632638
the "copyright" line and a pointer to where the full notice is found.
633639

634-
{one line to give the program's name and a brief idea of what it does.}
635-
Copyright (C) {year} {name of author}
640+
<one line to give the program's name and a brief idea of what it does.>
641+
Copyright (C) <year> <name of author>
636642

637643
This program is free software: you can redistribute it and/or modify
638644
it under the terms of the GNU General Public License as published by
@@ -652,7 +658,7 @@ Also add information on how to contact you by electronic and paper mail.
652658
If the program does terminal interaction, make it output a short
653659
notice like this when it starts in an interactive mode:
654660

655-
{project} Copyright (C) {year} {fullname}
661+
<program> Copyright (C) <year> <name of author>
656662
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657663
This is free software, and you are welcome to redistribute it
658664
under certain conditions; type `show c' for details.

Makefile.PL

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use strict;
2+
use warnings FATAL => 'all';
3+
use ExtUtils::MakeMaker;
4+
5+
WriteMakefile(
6+
NAME => 'GlusterFS::GFAPI::FFI',
7+
DISTNAME => 'GlusterFS-GFAPI-FFI',
8+
AUTHOR => 'Ji-Hyeon Gim <[email protected]>',
9+
VERSION_FROM => 'lib/GlusterFS/GFAPI/FFI.pm',
10+
ABSTRACT_FROM => 'lib/GlusterFS/GFAPI/FFI.pm',
11+
LICENSE => 'perl',
12+
CONFIGURE_REQUIRES => {
13+
'ExtUtils::MakeMaker' => 0,
14+
'FFI::CheckLib' => 0,
15+
'FFI::Platypus' => 0,
16+
},
17+
BUILD_REQUIRES => {
18+
'ExtUtils::MakeMaker' => 0,
19+
},
20+
PREREQ_PM => {
21+
'Carp' => 0,
22+
'FFI::Platypus' => 0,
23+
'FFI::Platypus::Buffer' => 0,
24+
'FFI::Platypus::Memory' => 0,
25+
'Try::Tiny' => 0,
26+
'strict' => 0,
27+
'warnings' => 0,
28+
'threads' => 0,
29+
},
30+
TEST_REQUIRES => {
31+
'Symbol' => 0,
32+
'IPC::Open3' => 0,
33+
'IO::Select' => 0,
34+
'List::Util' => 0,
35+
'POSIX' => 0,
36+
'Scalar::Util' => 0,
37+
'Test::Deep' => 0,
38+
'Test::More' => 0,
39+
'Time::HiRes' => 0,
40+
'locale' => 0,
41+
'utf8' => 0,
42+
},
43+
EXE_FILES => [],
44+
dist => {
45+
COMPRESS => 'gzip -9f',
46+
SUFFIX => 'gz',
47+
},
48+
clean => {
49+
FILES => 'GlusterFS-GFAPI-FFI-*',
50+
},
51+
test => {
52+
'TESTS' => "t/*.t",
53+
},
54+
(
55+
eval { ExtUtils::MakeMaker->VERSION(6.46) }
56+
? (
57+
META_MERGE => {
58+
'meta-spec' => { version => 2 },
59+
resources => {
60+
type => 'git',
61+
url => 'https://github.com/potatogim/libgfapi-perl.git',
62+
web => 'https://github.com/potatogim/libgfapi-perl',
63+
},
64+
})
65+
: ()
66+
),
67+
);

0 commit comments

Comments
 (0)