1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/pty/pty.c (MasterDevice, SlaveDevice, deviceNo): constified.

* ext/pty/pty.c (SlaveName): removed static buffer.

* ext/pty/expect_sample.rb: support for autologin.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-08-07 05:56:52 +00:00
parent ecf6101e9b
commit 0d197c00b3
3 changed files with 44 additions and 43 deletions

View file

@ -1,3 +1,11 @@
Tue Aug 7 14:56:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/pty/pty.c (MasterDevice, SlaveDevice, deviceNo): constified.
* ext/pty/pty.c (SlaveName): removed static buffer.
* ext/pty/expect_sample.rb: support for autologin.
Tue Aug 7 12:45:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Aug 7 12:45:13 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (ac_cv_func_isinf): set yes also on OpenSolaris. * configure.in (ac_cv_func_isinf): set yes also on OpenSolaris.

View file

@ -15,10 +15,6 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
$expect_verbose = false $expect_verbose = false
r_f.expect(/^Name.*: /) do
w_f.print "ftp\n"
end
if !ENV['USER'].nil? if !ENV['USER'].nil?
username = ENV['USER'] username = ENV['USER']
elsif !ENV['LOGNAME'].nil? elsif !ENV['LOGNAME'].nil?
@ -27,11 +23,8 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
username = 'guest' username = 'guest'
end end
r_f.expect('word:') do r_f.expect(/^(Name).*: |(word):|> /) do
w_f.print username+"@\n" w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
end
r_f.expect("> ") do
w_f.print "cd pub/ruby\n"
end end
r_f.expect("> ") do r_f.expect("> ") do
w_f.print "dir\n" w_f.print "dir\n"

View file

@ -39,10 +39,10 @@
#if !defined(HAVE_OPENPTY) #if !defined(HAVE_OPENPTY)
#if defined(__hpux) #if defined(__hpux)
static static const
char *MasterDevice = "/dev/ptym/pty%s", char MasterDevice[] = "/dev/ptym/pty%s",
*SlaveDevice = "/dev/pty/tty%s", SlaveDevice[] = "/dev/pty/tty%s",
*deviceNo[] = { *const deviceNo[] = {
"p0","p1","p2","p3","p4","p5","p6","p7", "p0","p1","p2","p3","p4","p5","p6","p7",
"p8","p9","pa","pb","pc","pd","pe","pf", "p8","p9","pa","pb","pc","pd","pe","pf",
"q0","q1","q2","q3","q4","q5","q6","q7", "q0","q1","q2","q3","q4","q5","q6","q7",
@ -62,10 +62,10 @@ char *MasterDevice = "/dev/ptym/pty%s",
0, 0,
}; };
#elif defined(_IBMESA) /* AIX/ESA */ #elif defined(_IBMESA) /* AIX/ESA */
static static const
char *MasterDevice = "/dev/ptyp%s", char MasterDevice[] = "/dev/ptyp%s",
*SlaveDevice = "/dev/ttyp%s", SlaveDevice[] = "/dev/ttyp%s",
*deviceNo[] = { *const deviceNo[] = {
"00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f", "00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f",
"10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f", "10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f",
"20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f", "20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f",
@ -84,10 +84,10 @@ char *MasterDevice = "/dev/ptyp%s",
"f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff", "f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff",
}; };
#elif !defined(HAVE_PTSNAME) #elif !defined(HAVE_PTSNAME)
static static const
char *MasterDevice = "/dev/pty%s", char MasterDevice[] = "/dev/pty%s",
*SlaveDevice = "/dev/tty%s", SlaveDevice[] = "/dev/tty%s",
*deviceNo[] = { *const deviceNo[] = {
"p0","p1","p2","p3","p4","p5","p6","p7", "p0","p1","p2","p3","p4","p5","p6","p7",
"p8","p9","pa","pb","pc","pd","pe","pf", "p8","p9","pa","pb","pc","pd","pe","pf",
"q0","q1","q2","q3","q4","q5","q6","q7", "q0","q1","q2","q3","q4","q5","q6","q7",
@ -101,8 +101,6 @@ char *MasterDevice = "/dev/pty%s",
#endif #endif
#endif /* !defined(HAVE_OPENPTY) */ #endif /* !defined(HAVE_OPENPTY) */
static char SlaveName[DEVICELEN];
#ifndef HAVE_SETEUID #ifndef HAVE_SETEUID
# ifdef HAVE_SETREUID # ifdef HAVE_SETREUID
# define seteuid(e) setreuid(-1, (e)) # define seteuid(e) setreuid(-1, (e))
@ -155,17 +153,15 @@ pty_syswait(info)
cpid = rb_waitpid(info->child_pid, &status, WUNTRACED); cpid = rb_waitpid(info->child_pid, &status, WUNTRACED);
if (cpid == -1) return Qnil; if (cpid == -1) return Qnil;
#if defined(IF_STOPPED) #if defined(WIFSTOPPED)
if (IF_STOPPED(status)) { /* suspend */ #elif defined(IF_STOPPED)
raise_from_wait("stopped", info); #define WIFSTOPPED(status) IF_STOPPED(status)
}
#elif defined(WIFSTOPPED)
if (WIFSTOPPED(status)) { /* suspend */
raise_from_wait("stopped", info);
}
#else #else
---->> Either IF_STOPPED or WIFSTOPPED is needed <<---- ---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
#endif /* WIFSTOPPED | IF_STOPPED */ #endif /* WIFSTOPPED | IF_STOPPED */
if (WIFSTOPPED(status)) { /* suspend */
raise_from_wait("stopped", info);
}
else if (kill(info->child_pid, 0) == 0) { else if (kill(info->child_pid, 0) == 0) {
raise_from_wait("changed", info); raise_from_wait("changed", info);
} }
@ -176,7 +172,7 @@ pty_syswait(info)
} }
} }
static void getDevice _((int*, int*)); static void getDevice _((int*, int*, char [DEVICELEN]));
struct exec_info { struct exec_info {
int argc; int argc;
@ -194,10 +190,11 @@ pty_exec(v)
} }
static void static void
establishShell(argc, argv, info) establishShell(argc, argv, info, SlaveName)
int argc; int argc;
VALUE *argv; VALUE *argv;
struct pty_info *info; struct pty_info *info;
char SlaveName[DEVICELEN];
{ {
int i,master,slave; int i,master,slave;
char *p,*getenv(); char *p,*getenv();
@ -223,7 +220,7 @@ establishShell(argc, argv, info)
argc = 1; argc = 1;
argv = &v; argv = &v;
} }
getDevice(&master,&slave); getDevice(&master, &slave, SlaveName);
info->thread = rb_thread_current(); info->thread = rb_thread_current();
if((i = fork()) < 0) { if((i = fork()) < 0) {
@ -305,8 +302,9 @@ pty_finalize_syswait(info)
} }
static int static int
get_device_once(master, slave, fail) get_device_once(master, slave, SlaveName, fail)
int *master, *slave, fail; int *master, *slave, fail;
char SlaveName[DEVICELEN];
{ {
#if defined HAVE_OPENPTY #if defined HAVE_OPENPTY
/* /*
@ -329,7 +327,7 @@ get_device_once(master, slave, fail)
} }
*slave = open(name, O_RDWR); *slave = open(name, O_RDWR);
strcpy(SlaveName, name); strncpy(SlaveName, name, sizeof SlaveName);
return 0; return 0;
#else /* HAVE__GETPTY */ #else /* HAVE__GETPTY */
@ -356,7 +354,7 @@ get_device_once(master, slave, fail)
#endif #endif
*master = i; *master = i;
*slave = j; *slave = j;
strcpy(SlaveName, pn); strncpy(SlaveName, pn, sizeof SlaveName);
return 0; return 0;
#if defined I_PUSH && !defined linux #if defined I_PUSH && !defined linux
} }
@ -375,10 +373,10 @@ get_device_once(master, slave, fail)
char MasterName[DEVICELEN]; char MasterName[DEVICELEN];
for (p = deviceNo; *p != NULL; p++) { for (p = deviceNo; *p != NULL; p++) {
sprintf(MasterName,MasterDevice,*p); snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
if ((i = open(MasterName,O_RDWR,0)) >= 0) { if ((i = open(MasterName,O_RDWR,0)) >= 0) {
*master = i; *master = i;
sprintf(SlaveName,SlaveDevice,*p); snprintf(SlaveName, sizeof SlaveName, SlaveDevice, *p);
if ((j = open(SlaveName,O_RDWR,0)) >= 0) { if ((j = open(SlaveName,O_RDWR,0)) >= 0) {
*slave = j; *slave = j;
chown(SlaveName, getuid(), getgid()); chown(SlaveName, getuid(), getgid());
@ -395,12 +393,13 @@ get_device_once(master, slave, fail)
} }
static void static void
getDevice(master, slave) getDevice(master, slave, slavename)
int *master, *slave; int *master, *slave;
char slavename[DEVICELEN];
{ {
if (get_device_once(master, slave, 0)) { if (get_device_once(master, slave, slavename, 0)) {
rb_gc(); rb_gc();
get_device_once(master, slave, 1); get_device_once(master, slave, slavename, 1);
} }
} }
@ -417,11 +416,12 @@ pty_getpty(argc, argv, self)
OpenFile *wfptr,*rfptr; OpenFile *wfptr,*rfptr;
VALUE rport = rb_obj_alloc(rb_cFile); VALUE rport = rb_obj_alloc(rb_cFile);
VALUE wport = rb_obj_alloc(rb_cFile); VALUE wport = rb_obj_alloc(rb_cFile);
char SlaveName[DEVICELEN];
MakeOpenFile(rport, rfptr); MakeOpenFile(rport, rfptr);
MakeOpenFile(wport, wfptr); MakeOpenFile(wport, wfptr);
establishShell(argc, argv, &info); establishShell(argc, argv, &info, SlaveName);
rfptr->mode = rb_io_mode_flags("r"); rfptr->mode = rb_io_mode_flags("r");
rfptr->f = fdopen(info.fd, "r"); rfptr->f = fdopen(info.fd, "r");