rubysl-pty 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/ext/rubysl/pty/extconf.rb +16 -0
- data/ext/rubysl/pty/pty.c +470 -0
- data/lib/pty.rb +1 -0
- data/lib/rubysl/pty.rb +2 -0
- data/lib/rubysl/pty/version.rb +5 -0
- data/rubysl-pty.gemspec +24 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d77df78cc8ecc2aa4f7a0b17ea7caee11093fa21
|
4
|
+
data.tar.gz: 3ba373c4cc32822347f63e2b87221c101cfb9a43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 101bdb40064ff296c584ab6b480be71e767e9af91c9d27aa991e3e7f8403660d1f3391a44732ac48b67f76d669bda8d437f929b785013cc5427296aa37d5cdf4
|
7
|
+
data.tar.gz: ccf8dc49c46a2333ccdc977674fd193048e0db7efbfd629e1b94353f691d8fb2d1a96b0c65413fefd981a10ea92546a7082b5c4705067c9c8695838b3872e1f0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::Pty
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-pty'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-pty
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
if /mswin32|mingw|bccwin32/ !~ RUBY_PLATFORM
|
4
|
+
have_header("sys/stropts.h")
|
5
|
+
have_header("sys/wait.h")
|
6
|
+
have_func("setresuid")
|
7
|
+
have_header("libutil.h")
|
8
|
+
have_header("pty.h")
|
9
|
+
have_library("util", "openpty")
|
10
|
+
if have_func("openpty") or
|
11
|
+
have_func("_getpty") or
|
12
|
+
have_func("ptsname") or
|
13
|
+
have_func("ioctl")
|
14
|
+
create_makefile('pty')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,470 @@
|
|
1
|
+
#include "config.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <sys/types.h>
|
4
|
+
#include <sys/stat.h>
|
5
|
+
#include <sys/file.h>
|
6
|
+
#include <fcntl.h>
|
7
|
+
#include <errno.h>
|
8
|
+
#include <pwd.h>
|
9
|
+
#ifdef HAVE_SYS_IOCTL_H
|
10
|
+
#include <sys/ioctl.h>
|
11
|
+
#endif
|
12
|
+
#ifdef HAVE_LIBUTIL_H
|
13
|
+
#include <libutil.h>
|
14
|
+
#endif
|
15
|
+
#ifdef HAVE_PTY_H
|
16
|
+
#include <pty.h>
|
17
|
+
#endif
|
18
|
+
#ifdef HAVE_SYS_WAIT_H
|
19
|
+
#include <sys/wait.h>
|
20
|
+
#else
|
21
|
+
#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
|
22
|
+
#endif
|
23
|
+
#include <ctype.h>
|
24
|
+
|
25
|
+
#include "ruby.h"
|
26
|
+
#include "rubyio.h"
|
27
|
+
#include "util.h"
|
28
|
+
|
29
|
+
#include <signal.h>
|
30
|
+
#ifdef HAVE_SYS_STROPTS_H
|
31
|
+
#include <sys/stropts.h>
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifdef HAVE_UNISTD_H
|
35
|
+
#include <unistd.h>
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#define DEVICELEN 16
|
39
|
+
|
40
|
+
#if !defined(HAVE_OPENPTY)
|
41
|
+
#if defined(__hpux)
|
42
|
+
static const
|
43
|
+
char MasterDevice[] = "/dev/ptym/pty%s",
|
44
|
+
SlaveDevice[] = "/dev/pty/tty%s",
|
45
|
+
*const deviceNo[] = {
|
46
|
+
"p0","p1","p2","p3","p4","p5","p6","p7",
|
47
|
+
"p8","p9","pa","pb","pc","pd","pe","pf",
|
48
|
+
"q0","q1","q2","q3","q4","q5","q6","q7",
|
49
|
+
"q8","q9","qa","qb","qc","qd","qe","qf",
|
50
|
+
"r0","r1","r2","r3","r4","r5","r6","r7",
|
51
|
+
"r8","r9","ra","rb","rc","rd","re","rf",
|
52
|
+
"s0","s1","s2","s3","s4","s5","s6","s7",
|
53
|
+
"s8","s9","sa","sb","sc","sd","se","sf",
|
54
|
+
"t0","t1","t2","t3","t4","t5","t6","t7",
|
55
|
+
"t8","t9","ta","tb","tc","td","te","tf",
|
56
|
+
"u0","u1","u2","u3","u4","u5","u6","u7",
|
57
|
+
"u8","u9","ua","ub","uc","ud","ue","uf",
|
58
|
+
"v0","v1","v2","v3","v4","v5","v6","v7",
|
59
|
+
"v8","v9","va","vb","vc","vd","ve","vf",
|
60
|
+
"w0","w1","w2","w3","w4","w5","w6","w7",
|
61
|
+
"w8","w9","wa","wb","wc","wd","we","wf",
|
62
|
+
0,
|
63
|
+
};
|
64
|
+
#elif defined(_IBMESA) /* AIX/ESA */
|
65
|
+
static const
|
66
|
+
char MasterDevice[] = "/dev/ptyp%s",
|
67
|
+
SlaveDevice[] = "/dev/ttyp%s",
|
68
|
+
*const deviceNo[] = {
|
69
|
+
"00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
|
70
|
+
"10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
|
71
|
+
"20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
|
72
|
+
"30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f",
|
73
|
+
"40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f",
|
74
|
+
"50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f",
|
75
|
+
"60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f",
|
76
|
+
"70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f",
|
77
|
+
"80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f",
|
78
|
+
"90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f",
|
79
|
+
"a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af",
|
80
|
+
"b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf",
|
81
|
+
"c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf",
|
82
|
+
"d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df",
|
83
|
+
"e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef",
|
84
|
+
"f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff",
|
85
|
+
};
|
86
|
+
#elif !defined(HAVE_PTSNAME)
|
87
|
+
static const
|
88
|
+
char MasterDevice[] = "/dev/pty%s",
|
89
|
+
SlaveDevice[] = "/dev/tty%s",
|
90
|
+
*const deviceNo[] = {
|
91
|
+
"p0","p1","p2","p3","p4","p5","p6","p7",
|
92
|
+
"p8","p9","pa","pb","pc","pd","pe","pf",
|
93
|
+
"q0","q1","q2","q3","q4","q5","q6","q7",
|
94
|
+
"q8","q9","qa","qb","qc","qd","qe","qf",
|
95
|
+
"r0","r1","r2","r3","r4","r5","r6","r7",
|
96
|
+
"r8","r9","ra","rb","rc","rd","re","rf",
|
97
|
+
"s0","s1","s2","s3","s4","s5","s6","s7",
|
98
|
+
"s8","s9","sa","sb","sc","sd","se","sf",
|
99
|
+
0,
|
100
|
+
};
|
101
|
+
#endif
|
102
|
+
#endif /* !defined(HAVE_OPENPTY) */
|
103
|
+
|
104
|
+
#ifndef HAVE_SETEUID
|
105
|
+
# ifdef HAVE_SETREUID
|
106
|
+
# define seteuid(e) setreuid(-1, (e))
|
107
|
+
# else /* NOT HAVE_SETREUID */
|
108
|
+
# ifdef HAVE_SETRESUID
|
109
|
+
# define seteuid(e) setresuid(-1, (e), -1)
|
110
|
+
# else /* NOT HAVE_SETRESUID */
|
111
|
+
/* I can't set euid. (;_;) */
|
112
|
+
# endif /* HAVE_SETRESUID */
|
113
|
+
# endif /* HAVE_SETREUID */
|
114
|
+
#endif /* NO_SETEUID */
|
115
|
+
|
116
|
+
static VALUE eChildExited;
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
echild_status(self)
|
120
|
+
VALUE self;
|
121
|
+
{
|
122
|
+
return rb_ivar_get(self, rb_intern("status"));
|
123
|
+
}
|
124
|
+
|
125
|
+
struct pty_info {
|
126
|
+
int fd;
|
127
|
+
int child_pid;
|
128
|
+
VALUE thread;
|
129
|
+
};
|
130
|
+
|
131
|
+
static void
|
132
|
+
raise_from_wait(state, info)
|
133
|
+
struct pty_info *info;
|
134
|
+
char *state;
|
135
|
+
{
|
136
|
+
VALUE last_status = rb_gv_get("$?");
|
137
|
+
char buf[1024];
|
138
|
+
VALUE exc;
|
139
|
+
|
140
|
+
snprintf(buf, sizeof(buf), "pty - %s: %ld", state, (long)info->child_pid);
|
141
|
+
exc = rb_exc_new2(eChildExited, buf);
|
142
|
+
rb_iv_set(exc, "status", last_status);
|
143
|
+
rb_funcall(info->thread, rb_intern("raise"), 1, exc);
|
144
|
+
}
|
145
|
+
|
146
|
+
static VALUE
|
147
|
+
pty_syswait(info)
|
148
|
+
struct pty_info *info;
|
149
|
+
{
|
150
|
+
int cpid, status;
|
151
|
+
|
152
|
+
for (;;) {
|
153
|
+
cpid = rb_waitpid(info->child_pid, &status, WUNTRACED);
|
154
|
+
if (cpid == -1) return Qnil;
|
155
|
+
|
156
|
+
#if defined(WIFSTOPPED)
|
157
|
+
#elif defined(IF_STOPPED)
|
158
|
+
#define WIFSTOPPED(status) IF_STOPPED(status)
|
159
|
+
#else
|
160
|
+
---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
|
161
|
+
#endif /* WIFSTOPPED | IF_STOPPED */
|
162
|
+
if (WIFSTOPPED(status)) { /* suspend */
|
163
|
+
raise_from_wait("stopped", info);
|
164
|
+
}
|
165
|
+
else if (kill(info->child_pid, 0) == 0) {
|
166
|
+
raise_from_wait("changed", info);
|
167
|
+
}
|
168
|
+
else {
|
169
|
+
raise_from_wait("exited", info);
|
170
|
+
return Qnil;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
static void getDevice _((int*, int*, char [DEVICELEN]));
|
176
|
+
|
177
|
+
struct exec_info {
|
178
|
+
int argc;
|
179
|
+
VALUE *argv;
|
180
|
+
};
|
181
|
+
|
182
|
+
static VALUE pty_exec _((VALUE v));
|
183
|
+
|
184
|
+
static VALUE
|
185
|
+
pty_exec(v)
|
186
|
+
VALUE v;
|
187
|
+
{
|
188
|
+
struct exec_info *arg = (struct exec_info *)v;
|
189
|
+
return rb_funcall2(rb_mKernel, rb_intern("exec"),
|
190
|
+
arg->argc, arg->argv);
|
191
|
+
}
|
192
|
+
|
193
|
+
static void
|
194
|
+
establishShell(argc, argv, info, SlaveName)
|
195
|
+
int argc;
|
196
|
+
VALUE *argv;
|
197
|
+
struct pty_info *info;
|
198
|
+
char SlaveName[DEVICELEN];
|
199
|
+
{
|
200
|
+
int i, master, slave;
|
201
|
+
char *p, tmp, *getenv();
|
202
|
+
struct passwd *pwent;
|
203
|
+
VALUE v;
|
204
|
+
struct exec_info arg;
|
205
|
+
int status;
|
206
|
+
|
207
|
+
if (argc == 0) {
|
208
|
+
char *shellname;
|
209
|
+
|
210
|
+
if ((p = getenv("SHELL")) != NULL) {
|
211
|
+
shellname = p;
|
212
|
+
}
|
213
|
+
else {
|
214
|
+
pwent = getpwuid(getuid());
|
215
|
+
if (pwent && pwent->pw_shell)
|
216
|
+
shellname = pwent->pw_shell;
|
217
|
+
else
|
218
|
+
shellname = "/bin/sh";
|
219
|
+
}
|
220
|
+
v = rb_str_new2(shellname);
|
221
|
+
argc = 1;
|
222
|
+
argv = &v;
|
223
|
+
}
|
224
|
+
getDevice(&master, &slave, SlaveName);
|
225
|
+
|
226
|
+
info->thread = rb_thread_current();
|
227
|
+
VALUE child_pid = rb_funcall(rb_mKernel, rb_intern("fork"), 0);
|
228
|
+
|
229
|
+
/* if(i < 0) { */
|
230
|
+
/* close(master); */
|
231
|
+
/* close(slave); */
|
232
|
+
/* rb_sys_fail("fork failed"); */
|
233
|
+
/* } */
|
234
|
+
|
235
|
+
if(child_pid == Qnil) { /* child */
|
236
|
+
/*
|
237
|
+
* Set free from process group and controlling terminal
|
238
|
+
*/
|
239
|
+
#ifdef HAVE_SETSID
|
240
|
+
(void) setsid();
|
241
|
+
#else /* HAS_SETSID */
|
242
|
+
# ifdef HAVE_SETPGRP
|
243
|
+
# ifdef SETGRP_VOID
|
244
|
+
if (setpgrp() == -1)
|
245
|
+
perror("setpgrp()");
|
246
|
+
# else /* SETGRP_VOID */
|
247
|
+
if (setpgrp(0, getpid()) == -1)
|
248
|
+
rb_sys_fail("setpgrp()");
|
249
|
+
if ((i = open("/dev/tty", O_RDONLY)) < 0)
|
250
|
+
rb_sys_fail("/dev/tty");
|
251
|
+
else {
|
252
|
+
if (ioctl(i, TIOCNOTTY, (char *)0))
|
253
|
+
perror("ioctl(TIOCNOTTY)");
|
254
|
+
close(i);
|
255
|
+
}
|
256
|
+
# endif /* SETGRP_VOID */
|
257
|
+
# endif /* HAVE_SETPGRP */
|
258
|
+
#endif /* HAS_SETSID */
|
259
|
+
|
260
|
+
/*
|
261
|
+
* obtain new controlling terminal
|
262
|
+
*/
|
263
|
+
#if defined(TIOCSCTTY)
|
264
|
+
close(master);
|
265
|
+
(void) ioctl(slave, TIOCSCTTY, (char *)0);
|
266
|
+
/* errors ignored for sun */
|
267
|
+
#else
|
268
|
+
close(slave);
|
269
|
+
slave = open(SlaveName, O_RDWR);
|
270
|
+
if (slave < 0) {
|
271
|
+
perror("open: pty slave");
|
272
|
+
_exit(1);
|
273
|
+
}
|
274
|
+
close(master);
|
275
|
+
#endif
|
276
|
+
write(slave, "", 1);
|
277
|
+
dup2(slave,0);
|
278
|
+
dup2(slave,1);
|
279
|
+
dup2(slave,2);
|
280
|
+
close(slave);
|
281
|
+
#if defined(HAVE_SETEUID) || defined(HAVE_SETREUID) || defined(HAVE_SETRESUID)
|
282
|
+
seteuid(getuid());
|
283
|
+
#endif
|
284
|
+
|
285
|
+
arg.argc = argc;
|
286
|
+
arg.argv = argv;
|
287
|
+
rb_protect(pty_exec, (VALUE)&arg, &status);
|
288
|
+
sleep(1);
|
289
|
+
_exit(1);
|
290
|
+
}
|
291
|
+
|
292
|
+
read(master, &tmp, 1);
|
293
|
+
close(slave);
|
294
|
+
|
295
|
+
info->child_pid = FIX2INT(child_pid);
|
296
|
+
info->fd = master;
|
297
|
+
}
|
298
|
+
|
299
|
+
static int
|
300
|
+
get_device_once(master, slave, SlaveName, fail)
|
301
|
+
int *master, *slave, fail;
|
302
|
+
char SlaveName[DEVICELEN];
|
303
|
+
{
|
304
|
+
#if defined HAVE_OPENPTY
|
305
|
+
/*
|
306
|
+
* Use openpty(3) of 4.3BSD Reno and later,
|
307
|
+
* or the same interface function.
|
308
|
+
*/
|
309
|
+
if (openpty(master, slave, SlaveName,
|
310
|
+
(struct termios *)0, (struct winsize *)0) == -1) {
|
311
|
+
if (!fail) return -1;
|
312
|
+
rb_raise(rb_eRuntimeError, "openpty() failed");
|
313
|
+
}
|
314
|
+
|
315
|
+
return 0;
|
316
|
+
#elif defined HAVE__GETPTY
|
317
|
+
char *name;
|
318
|
+
|
319
|
+
if (!(name = _getpty(master, O_RDWR, 0622, 0))) {
|
320
|
+
if (!fail) return -1;
|
321
|
+
rb_raise(rb_eRuntimeError, "_getpty() failed");
|
322
|
+
}
|
323
|
+
|
324
|
+
*slave = open(name, O_RDWR);
|
325
|
+
strncpy(SlaveName, name, sizeof SlaveName);
|
326
|
+
|
327
|
+
return 0;
|
328
|
+
#else /* HAVE__GETPTY */
|
329
|
+
int i,j;
|
330
|
+
|
331
|
+
#ifdef HAVE_PTSNAME
|
332
|
+
char *pn;
|
333
|
+
void (*s)();
|
334
|
+
|
335
|
+
extern char *ptsname(int);
|
336
|
+
extern int unlockpt(int);
|
337
|
+
extern int grantpt(int);
|
338
|
+
|
339
|
+
if((i = open("/dev/ptmx", O_RDWR, 0)) != -1) {
|
340
|
+
s = signal(SIGCHLD, SIG_DFL);
|
341
|
+
if(grantpt(i) != -1) {
|
342
|
+
signal(SIGCHLD, s);
|
343
|
+
if(unlockpt(i) != -1) {
|
344
|
+
if((pn = ptsname(i)) != NULL) {
|
345
|
+
if((j = open(pn, O_RDWR, 0)) != -1) {
|
346
|
+
#if defined I_PUSH && !defined linux
|
347
|
+
if(ioctl(j, I_PUSH, "ptem") != -1) {
|
348
|
+
if(ioctl(j, I_PUSH, "ldterm") != -1) {
|
349
|
+
ioctl(j, I_PUSH, "ttcompat");
|
350
|
+
#endif
|
351
|
+
*master = i;
|
352
|
+
*slave = j;
|
353
|
+
strncpy(SlaveName, pn, sizeof SlaveName);
|
354
|
+
return 0;
|
355
|
+
#if defined I_PUSH && !defined linux
|
356
|
+
}
|
357
|
+
}
|
358
|
+
#endif
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
close(i);
|
364
|
+
}
|
365
|
+
if (!fail) rb_raise(rb_eRuntimeError, "can't get Master/Slave device");
|
366
|
+
return -1;
|
367
|
+
#else
|
368
|
+
char **p;
|
369
|
+
char MasterName[DEVICELEN];
|
370
|
+
|
371
|
+
for (p = deviceNo; *p != NULL; p++) {
|
372
|
+
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
373
|
+
if ((i = open(MasterName,O_RDWR,0)) >= 0) {
|
374
|
+
*master = i;
|
375
|
+
snprintf(SlaveName, sizeof SlaveName, SlaveDevice, *p);
|
376
|
+
if ((j = open(SlaveName,O_RDWR,0)) >= 0) {
|
377
|
+
*slave = j;
|
378
|
+
chown(SlaveName, getuid(), getgid());
|
379
|
+
chmod(SlaveName, 0622);
|
380
|
+
return 0;
|
381
|
+
}
|
382
|
+
close(i);
|
383
|
+
}
|
384
|
+
}
|
385
|
+
if (fail) rb_raise(rb_eRuntimeError, "can't get %s", SlaveName);
|
386
|
+
return -1;
|
387
|
+
#endif
|
388
|
+
#endif
|
389
|
+
}
|
390
|
+
|
391
|
+
static void
|
392
|
+
getDevice(master, slave, slavename)
|
393
|
+
int *master, *slave;
|
394
|
+
char slavename[DEVICELEN];
|
395
|
+
{
|
396
|
+
if (get_device_once(master, slave, slavename, 0)) {
|
397
|
+
rb_gc();
|
398
|
+
get_device_once(master, slave, slavename, 1);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
/* ruby function: getpty */
|
403
|
+
static VALUE
|
404
|
+
pty_getpty(argc, argv, self)
|
405
|
+
int argc;
|
406
|
+
VALUE *argv;
|
407
|
+
VALUE self;
|
408
|
+
{
|
409
|
+
VALUE res, rport, wport;
|
410
|
+
struct pty_info info;
|
411
|
+
struct pty_info thinfo;
|
412
|
+
rb_io_t *wfptr,*rfptr;
|
413
|
+
char SlaveName[DEVICELEN];
|
414
|
+
|
415
|
+
establishShell(argc, argv, &info, SlaveName);
|
416
|
+
|
417
|
+
rport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(info.fd),
|
418
|
+
rb_str_new2("r"));
|
419
|
+
|
420
|
+
rb_ivar_set(rport, rb_intern("@path"), rb_str_new2(SlaveName));
|
421
|
+
|
422
|
+
wport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(dup(info.fd)),
|
423
|
+
rb_str_new2("r"));
|
424
|
+
|
425
|
+
rb_ivar_set(wport, rb_intern("@path"), rb_str_new2(SlaveName));
|
426
|
+
rb_funcall(wport, rb_intern("sync="), 1, Qtrue);
|
427
|
+
|
428
|
+
res = rb_ary_new2(3);
|
429
|
+
rb_ary_store(res,0,(VALUE)rport);
|
430
|
+
rb_ary_store(res,1,(VALUE)wport);
|
431
|
+
rb_ary_store(res,2,INT2FIX(info.child_pid));
|
432
|
+
|
433
|
+
if (rb_block_given_p()) {
|
434
|
+
rb_yield(res);
|
435
|
+
return Qnil;
|
436
|
+
}
|
437
|
+
return res;
|
438
|
+
}
|
439
|
+
|
440
|
+
/* ruby function: protect_signal - obsolete */
|
441
|
+
static VALUE
|
442
|
+
pty_protect(self)
|
443
|
+
VALUE self;
|
444
|
+
{
|
445
|
+
rb_warn("PTY::protect_signal is no longer needed");
|
446
|
+
rb_yield(Qnil);
|
447
|
+
return self;
|
448
|
+
}
|
449
|
+
|
450
|
+
/* ruby function: reset_signal - obsolete */
|
451
|
+
static VALUE
|
452
|
+
pty_reset_signal(self)
|
453
|
+
VALUE self;
|
454
|
+
{
|
455
|
+
rb_warn("PTY::reset_signal is no longer needed");
|
456
|
+
return self;
|
457
|
+
}
|
458
|
+
|
459
|
+
void
|
460
|
+
Init_pty()
|
461
|
+
{
|
462
|
+
VALUE cPTY = rb_define_module("PTY");
|
463
|
+
rb_define_module_function(cPTY,"getpty",pty_getpty,-1);
|
464
|
+
rb_define_module_function(cPTY,"spawn",pty_getpty,-1);
|
465
|
+
rb_define_module_function(cPTY,"protect_signal",pty_protect,0);
|
466
|
+
rb_define_module_function(cPTY,"reset_signal",pty_reset_signal,0);
|
467
|
+
|
468
|
+
eChildExited = rb_define_class_under(cPTY,"ChildExited",rb_eRuntimeError);
|
469
|
+
rb_define_method(eChildExited,"status",echild_status,0);
|
470
|
+
}
|
data/lib/pty.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/pty"
|
data/lib/rubysl/pty.rb
ADDED
data/rubysl-pty.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/pty/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-pty"
|
6
|
+
spec.version = RubySL::PTY::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library pty.}
|
10
|
+
spec.summary = %q{Ruby standard library pty.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-pty"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["ext/rubysl/pty/extconf.rb"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysl-pty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubysl-prettyprint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Ruby standard library pty.
|
70
|
+
email:
|
71
|
+
- brixen@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/rubysl/pty/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- ext/rubysl/pty/extconf.rb
|
84
|
+
- ext/rubysl/pty/pty.c
|
85
|
+
- lib/pty.rb
|
86
|
+
- lib/rubysl/pty.rb
|
87
|
+
- lib/rubysl/pty/version.rb
|
88
|
+
- rubysl-pty.gemspec
|
89
|
+
homepage: https://github.com/rubysl/rubysl-pty
|
90
|
+
licenses:
|
91
|
+
- BSD
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.7
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Ruby standard library pty.
|
113
|
+
test_files: []
|