* 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/trunk@12898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-08-07 05:56:52 +00:00
parent f800cdbabc
commit a37d419c5d
3 changed files with 42 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 13:58:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Aug 7 13:58:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (ruby_special_consts): added RUBY_SPECIAL_SHIFT. * include/ruby/ruby.h (ruby_special_consts): added RUBY_SPECIAL_SHIFT.

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

@ -42,10 +42,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",
@ -65,10 +65,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",
@ -87,10 +87,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",
@ -104,8 +104,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))
@ -154,17 +152,15 @@ pty_syswait(struct pty_info *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);
} }
@ -175,7 +171,7 @@ pty_syswait(struct pty_info *info)
} }
} }
static void getDevice(int*, int*); static void getDevice(int*, int*, char [DEVICELEN]);
struct exec_info { struct exec_info {
int argc; int argc;
@ -190,7 +186,8 @@ pty_exec(VALUE v)
} }
static void static void
establishShell(int argc, VALUE *argv, struct pty_info *info) establishShell(int argc, VALUE *argv, struct pty_info *info,
char SlaveName[DEVICELEN])
{ {
int master,slave; int master,slave;
rb_pid_t pid; rb_pid_t pid;
@ -217,7 +214,7 @@ establishShell(int argc, VALUE *argv, struct pty_info *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 ((pid = fork()) < 0) { if ((pid = fork()) < 0) {
@ -298,7 +295,7 @@ pty_finalize_syswait(struct pty_info *info)
} }
static int static int
get_device_once(int *master, int *slave, int fail) get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int fail)
{ {
#if defined HAVE_OPENPTY #if defined HAVE_OPENPTY
/* /*
@ -321,7 +318,7 @@ get_device_once(int *master, int *slave, int fail)
} }
*slave = open(name, O_RDWR); *slave = open(name, O_RDWR);
strcpy(SlaveName, name); strlcpy(SlaveName, name, sizeof SlaveName);
return 0; return 0;
#else /* HAVE__GETPTY */ #else /* HAVE__GETPTY */
@ -348,7 +345,7 @@ get_device_once(int *master, int *slave, int fail)
#endif #endif
*master = i; *master = i;
*slave = j; *slave = j;
strcpy(SlaveName, pn); strlcpy(SlaveName, pn, sizeof SlaveName);
return 0; return 0;
#if defined I_PUSH && !defined linux #if defined I_PUSH && !defined linux
} }
@ -367,10 +364,10 @@ get_device_once(int *master, int *slave, int 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());
@ -387,11 +384,11 @@ get_device_once(int *master, int *slave, int fail)
} }
static void static void
getDevice(int *master, int *slave) getDevice(int *master, int *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);
} }
} }
@ -405,11 +402,12 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
rb_io_t *wfptr,*rfptr; rb_io_t *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->fd = info.fd; rfptr->fd = info.fd;