rubysl-pty 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -7
- data/ext/rubysl/pty/pty.c +64 -1
- data/lib/rubysl/pty/version.rb +1 -1
- data/spec/open_spec.rb +50 -0
- data/spec/spawn_spec.rb +12 -0
- metadata +20 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da964a021b41c3d8908cc6d09a82b39f2a05166f
|
4
|
+
data.tar.gz: 2547e6607b59d30e5e38052595a6f3bc9f0f7ad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dc482d93408011b66b2e559118df48541c2c00c15f6efa9b257c52c4731228641c0f2ad7526506677ffc4a680d277569b06b05d1b6c25d3ce9edd80d13cafcc
|
7
|
+
data.tar.gz: 492d65972f7c6664692c12d70fcdd3622a80814999b64c1ad522fd7414cdd63a6585fae8d7b8e2ce1aaf3ac27e22f3d6a65cbadd186b8451422920e251a9d36c
|
data/.travis.yml
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
language: ruby
|
2
|
-
before_install:
|
3
|
-
- rvm use $RVM --install --binary --fuzzy
|
4
|
-
- gem update --system
|
5
|
-
- gem --version
|
6
|
-
- gem install rubysl-bundler
|
7
2
|
env:
|
8
|
-
-
|
9
|
-
script:
|
3
|
+
- RUBYLIB=lib:.
|
4
|
+
script: mspec spec
|
5
|
+
branches:
|
6
|
+
only:
|
7
|
+
- 1.0
|
8
|
+
- 2.0
|
9
|
+
rvm:
|
10
|
+
- 2.1.0
|
11
|
+
- rbx-2
|
12
|
+
|
data/ext/rubysl/pty/pty.c
CHANGED
@@ -315,6 +315,9 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|
315
315
|
if (ioctl(slavefd, I_PUSH, "ttcompat") == -1) goto error;
|
316
316
|
#endif
|
317
317
|
|
318
|
+
rb_fd_fix_cloexec(masterfd);
|
319
|
+
rb_fd_fix_cloexec(slavefd);
|
320
|
+
|
318
321
|
*master = masterfd;
|
319
322
|
*slave = slavefd;
|
320
323
|
strlcpy(SlaveName, slavedevice, DEVICELEN);
|
@@ -339,6 +342,10 @@ error:
|
|
339
342
|
if (!fail) return -1;
|
340
343
|
rb_raise(rb_eRuntimeError, "openpty() failed");
|
341
344
|
}
|
345
|
+
|
346
|
+
rb_fd_fix_cloexec(*master);
|
347
|
+
rb_fd_fix_cloexec(*slave);
|
348
|
+
|
342
349
|
if (no_mesg(SlaveName, nomesg) == -1) {
|
343
350
|
if (!fail) return -1;
|
344
351
|
rb_raise(rb_eRuntimeError, "can't chmod slave pty");
|
@@ -356,6 +363,10 @@ error:
|
|
356
363
|
}
|
357
364
|
|
358
365
|
*slave = open(name, O_RDWR);
|
366
|
+
|
367
|
+
rb_fd_fix_cloexec(*master);
|
368
|
+
rb_fd_fix_cloexec(*slave);
|
369
|
+
|
359
370
|
/* error check? */
|
360
371
|
strlcpy(SlaveName, name, DEVICELEN);
|
361
372
|
|
@@ -382,6 +393,10 @@ error:
|
|
382
393
|
if(ioctl(slavefd, I_PUSH, "ldterm") == -1) goto error;
|
383
394
|
ioctl(slavefd, I_PUSH, "ttcompat");
|
384
395
|
#endif
|
396
|
+
|
397
|
+
rb_fd_fix_cloexec(masterfd);
|
398
|
+
rb_fd_fix_cloexec(slavefd);
|
399
|
+
|
385
400
|
*master = masterfd;
|
386
401
|
*slave = slavefd;
|
387
402
|
strlcpy(SlaveName, slavedevice, DEVICELEN);
|
@@ -401,9 +416,11 @@ error:
|
|
401
416
|
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
402
417
|
if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) {
|
403
418
|
*master = masterfd;
|
419
|
+
rb_fd_fix_cloexec(*master);
|
404
420
|
snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
|
405
421
|
if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) {
|
406
422
|
*slave = slavefd;
|
423
|
+
rb_fd_fix_cloexec(*slave);
|
407
424
|
if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
|
408
425
|
if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
|
409
426
|
return 0;
|
@@ -489,7 +506,7 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
|
|
489
506
|
rb_ivar_set(rport, rb_intern("@path"), rb_str_new2(SlaveName));
|
490
507
|
|
491
508
|
wport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(dup(info.fd)),
|
492
|
-
rb_str_new2("
|
509
|
+
rb_str_new2("w"));
|
493
510
|
|
494
511
|
rb_ivar_set(wport, rb_intern("@path"), rb_str_new2(SlaveName));
|
495
512
|
rb_funcall(wport, rb_intern("sync="), 1, Qtrue);
|
@@ -503,6 +520,51 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
|
|
503
520
|
return res;
|
504
521
|
}
|
505
522
|
|
523
|
+
static VALUE
|
524
|
+
pty_close_pty(VALUE assoc)
|
525
|
+
{
|
526
|
+
VALUE io;
|
527
|
+
int i;
|
528
|
+
|
529
|
+
for (i = 0; i < 2; i++) {
|
530
|
+
io = rb_ary_entry(assoc, i);
|
531
|
+
if (RB_TYPE_P(io, T_FILE) && 0 <= RFILE(io)->fptr->fd) {
|
532
|
+
rb_io_close(io);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
return Qnil;
|
536
|
+
}
|
537
|
+
|
538
|
+
static VALUE
|
539
|
+
pty_open(VALUE klass) {
|
540
|
+
int master_fd, slave_fd;
|
541
|
+
char slavename[DEVICELEN];
|
542
|
+
VALUE master_io, slave_file;
|
543
|
+
rb_io_t *master_fptr, *slave_fptr;
|
544
|
+
VALUE assoc;
|
545
|
+
|
546
|
+
getDevice(&master_fd, &slave_fd, slavename, 1);
|
547
|
+
|
548
|
+
master_io = rb_funcall(rb_cIO, rb_intern("new"), 2, INT2FIX(master_fd),
|
549
|
+
rb_str_new2("r+"));
|
550
|
+
|
551
|
+
rb_funcall(master_io, rb_intern("sync="), 1, Qtrue);
|
552
|
+
|
553
|
+
slave_file = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(slave_fd),
|
554
|
+
rb_str_new2("r+"));
|
555
|
+
|
556
|
+
rb_ivar_set(slave_file, rb_intern("@path"),
|
557
|
+
rb_obj_freeze(rb_str_new2(slavename)));
|
558
|
+
rb_funcall(slave_file, rb_intern("sync="), 1, Qtrue);
|
559
|
+
|
560
|
+
assoc = rb_assoc_new(master_io, slave_file);
|
561
|
+
|
562
|
+
if (rb_block_given_p()) {
|
563
|
+
return rb_ensure(rb_yield, assoc, pty_close_pty, assoc);
|
564
|
+
}
|
565
|
+
return assoc;
|
566
|
+
}
|
567
|
+
|
506
568
|
/*
|
507
569
|
* Document-class: PTY::ChildExited
|
508
570
|
*
|
@@ -523,6 +585,7 @@ Init_pty()
|
|
523
585
|
VALUE cPTY = rb_define_module("PTY");
|
524
586
|
rb_define_module_function(cPTY, "getpty", pty_getpty, -1);
|
525
587
|
rb_define_module_function(cPTY, "spawn", pty_getpty, -1);
|
588
|
+
rb_define_singleton_method(cPTY, "open", pty_open, 0);
|
526
589
|
rb_define_singleton_method(cPTY, "__get_device__", pty_get_device, 0);
|
527
590
|
|
528
591
|
eChildExited = rb_define_class_under(cPTY, "ChildExited", rb_eRuntimeError);
|
data/lib/rubysl/pty/version.rb
CHANGED
data/spec/open_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "pty"
|
2
|
+
|
3
|
+
describe "PTY.open" do
|
4
|
+
before(:each) do
|
5
|
+
@master, @slave = PTY.open
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:each) do
|
9
|
+
@master.close
|
10
|
+
@slave.close
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns master as an IO object" do
|
14
|
+
@master.class.should == IO
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns slave as a File object" do
|
18
|
+
@slave.class.should == File
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns master and slave as ttys" do
|
22
|
+
@master.tty?.should == true
|
23
|
+
@slave.tty?.should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns slave as a device file" do
|
27
|
+
@slave.stat.chardev?.should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "syncs master and slave" do
|
31
|
+
@master.sync.should == true
|
32
|
+
@slave.sync.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "allows writing to master, and reading from slave" do
|
36
|
+
@master.puts "sshao was here"
|
37
|
+
@slave.gets.should == "sshao was here\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets master and slave fd flags to 2" do
|
41
|
+
require "fcntl"
|
42
|
+
@master.fcntl(Fcntl::F_GETFL).should == 2
|
43
|
+
@slave.fcntl(Fcntl::F_GETFL).should == 2
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sets master and slave to close on exec" do
|
47
|
+
@master.close_on_exec?.should == true
|
48
|
+
@slave.close_on_exec?.should == true
|
49
|
+
end
|
50
|
+
end
|
data/spec/spawn_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pty"
|
2
|
+
|
3
|
+
describe "PTY.spawn" do
|
4
|
+
before(:each) do
|
5
|
+
@read, @write, @pid = PTY.spawn
|
6
|
+
end
|
7
|
+
|
8
|
+
it "allows reading from the first IO, and writing from the second IO" do
|
9
|
+
@write.puts "sshao was here"
|
10
|
+
@read.gets.should == "sshao was here\r\n"
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,67 +1,67 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-pty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
|
-
|
15
|
+
type: :development
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '1.3'
|
20
|
-
type: :development
|
21
21
|
prerelease: false
|
22
|
-
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
|
-
|
29
|
+
type: :development
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '10.0'
|
34
|
-
type: :development
|
35
35
|
prerelease: false
|
36
|
-
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mspec
|
43
|
-
|
43
|
+
type: :development
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: '1.5'
|
48
|
-
type: :development
|
49
49
|
prerelease: false
|
50
|
-
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubysl-prettyprint
|
57
|
-
|
57
|
+
type: :development
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '2.0'
|
62
|
-
type: :development
|
63
63
|
prerelease: false
|
64
|
-
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- lib/rubysl/pty.rb
|
87
87
|
- lib/rubysl/pty/version.rb
|
88
88
|
- rubysl-pty.gemspec
|
89
|
+
- spec/open_spec.rb
|
90
|
+
- spec/spawn_spec.rb
|
89
91
|
homepage: https://github.com/rubysl/rubysl-pty
|
90
92
|
licenses:
|
91
93
|
- BSD
|
@@ -106,9 +108,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.5
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Ruby standard library pty.
|
113
|
-
test_files:
|
114
|
-
|
115
|
+
test_files:
|
116
|
+
- spec/open_spec.rb
|
117
|
+
- spec/spawn_spec.rb
|