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/trunk@12898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f800cdbabc
commit
a37d419c5d
3 changed files with 42 additions and 43 deletions
|
@ -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>
|
||||
|
||||
* include/ruby/ruby.h (ruby_special_consts): added RUBY_SPECIAL_SHIFT.
|
||||
|
|
|
@ -15,10 +15,6 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
|||
|
||||
$expect_verbose = false
|
||||
|
||||
r_f.expect(/^Name.*: /) do
|
||||
w_f.print "ftp\n"
|
||||
end
|
||||
|
||||
if !ENV['USER'].nil?
|
||||
username = ENV['USER']
|
||||
elsif !ENV['LOGNAME'].nil?
|
||||
|
@ -27,11 +23,8 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
|||
username = 'guest'
|
||||
end
|
||||
|
||||
r_f.expect('word:') do
|
||||
w_f.print username+"@\n"
|
||||
end
|
||||
r_f.expect("> ") do
|
||||
w_f.print "cd pub/ruby\n"
|
||||
r_f.expect(/^(Name).*: |(word):|> /) do
|
||||
w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
|
||||
end
|
||||
r_f.expect("> ") do
|
||||
w_f.print "dir\n"
|
||||
|
|
|
@ -42,10 +42,10 @@
|
|||
|
||||
#if !defined(HAVE_OPENPTY)
|
||||
#if defined(__hpux)
|
||||
static
|
||||
char *MasterDevice = "/dev/ptym/pty%s",
|
||||
*SlaveDevice = "/dev/pty/tty%s",
|
||||
*deviceNo[] = {
|
||||
static const
|
||||
char MasterDevice[] = "/dev/ptym/pty%s",
|
||||
SlaveDevice[] = "/dev/pty/tty%s",
|
||||
*const deviceNo[] = {
|
||||
"p0","p1","p2","p3","p4","p5","p6","p7",
|
||||
"p8","p9","pa","pb","pc","pd","pe","pf",
|
||||
"q0","q1","q2","q3","q4","q5","q6","q7",
|
||||
|
@ -65,10 +65,10 @@ char *MasterDevice = "/dev/ptym/pty%s",
|
|||
0,
|
||||
};
|
||||
#elif defined(_IBMESA) /* AIX/ESA */
|
||||
static
|
||||
char *MasterDevice = "/dev/ptyp%s",
|
||||
*SlaveDevice = "/dev/ttyp%s",
|
||||
*deviceNo[] = {
|
||||
static const
|
||||
char MasterDevice[] = "/dev/ptyp%s",
|
||||
SlaveDevice[] = "/dev/ttyp%s",
|
||||
*const deviceNo[] = {
|
||||
"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",
|
||||
"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",
|
||||
};
|
||||
#elif !defined(HAVE_PTSNAME)
|
||||
static
|
||||
char *MasterDevice = "/dev/pty%s",
|
||||
*SlaveDevice = "/dev/tty%s",
|
||||
*deviceNo[] = {
|
||||
static const
|
||||
char MasterDevice[] = "/dev/pty%s",
|
||||
SlaveDevice[] = "/dev/tty%s",
|
||||
*const deviceNo[] = {
|
||||
"p0","p1","p2","p3","p4","p5","p6","p7",
|
||||
"p8","p9","pa","pb","pc","pd","pe","pf",
|
||||
"q0","q1","q2","q3","q4","q5","q6","q7",
|
||||
|
@ -104,8 +104,6 @@ char *MasterDevice = "/dev/pty%s",
|
|||
#endif
|
||||
#endif /* !defined(HAVE_OPENPTY) */
|
||||
|
||||
static char SlaveName[DEVICELEN];
|
||||
|
||||
#ifndef HAVE_SETEUID
|
||||
# ifdef HAVE_SETREUID
|
||||
# define seteuid(e) setreuid(-1, (e))
|
||||
|
@ -154,17 +152,15 @@ pty_syswait(struct pty_info *info)
|
|||
cpid = rb_waitpid(info->child_pid, &status, WUNTRACED);
|
||||
if (cpid == -1) return Qnil;
|
||||
|
||||
#if defined(IF_STOPPED)
|
||||
if (IF_STOPPED(status)) { /* suspend */
|
||||
raise_from_wait("stopped", info);
|
||||
}
|
||||
#elif defined(WIFSTOPPED)
|
||||
if (WIFSTOPPED(status)) { /* suspend */
|
||||
raise_from_wait("stopped", info);
|
||||
}
|
||||
#if defined(WIFSTOPPED)
|
||||
#elif defined(IF_STOPPED)
|
||||
#define WIFSTOPPED(status) IF_STOPPED(status)
|
||||
#else
|
||||
---->> Either IF_STOPPED or WIFSTOPPED is needed <<----
|
||||
#endif /* WIFSTOPPED | IF_STOPPED */
|
||||
if (WIFSTOPPED(status)) { /* suspend */
|
||||
raise_from_wait("stopped", info);
|
||||
}
|
||||
else if (kill(info->child_pid, 0) == 0) {
|
||||
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 {
|
||||
int argc;
|
||||
|
@ -190,7 +186,8 @@ pty_exec(VALUE v)
|
|||
}
|
||||
|
||||
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;
|
||||
rb_pid_t pid;
|
||||
|
@ -217,7 +214,7 @@ establishShell(int argc, VALUE *argv, struct pty_info *info)
|
|||
argc = 1;
|
||||
argv = &v;
|
||||
}
|
||||
getDevice(&master,&slave);
|
||||
getDevice(&master, &slave, SlaveName);
|
||||
|
||||
info->thread = rb_thread_current();
|
||||
if ((pid = fork()) < 0) {
|
||||
|
@ -298,7 +295,7 @@ pty_finalize_syswait(struct pty_info *info)
|
|||
}
|
||||
|
||||
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
|
||||
/*
|
||||
|
@ -321,7 +318,7 @@ get_device_once(int *master, int *slave, int fail)
|
|||
}
|
||||
|
||||
*slave = open(name, O_RDWR);
|
||||
strcpy(SlaveName, name);
|
||||
strlcpy(SlaveName, name, sizeof SlaveName);
|
||||
|
||||
return 0;
|
||||
#else /* HAVE__GETPTY */
|
||||
|
@ -348,7 +345,7 @@ get_device_once(int *master, int *slave, int fail)
|
|||
#endif
|
||||
*master = i;
|
||||
*slave = j;
|
||||
strcpy(SlaveName, pn);
|
||||
strlcpy(SlaveName, pn, sizeof SlaveName);
|
||||
return 0;
|
||||
#if defined I_PUSH && !defined linux
|
||||
}
|
||||
|
@ -367,10 +364,10 @@ get_device_once(int *master, int *slave, int fail)
|
|||
char MasterName[DEVICELEN];
|
||||
|
||||
for (p = deviceNo; *p != NULL; p++) {
|
||||
sprintf(MasterName,MasterDevice,*p);
|
||||
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
||||
if ((i = open(MasterName,O_RDWR,0)) >= 0) {
|
||||
*master = i;
|
||||
sprintf(SlaveName,SlaveDevice,*p);
|
||||
snprintf(SlaveName, sizeof SlaveName, SlaveDevice, *p);
|
||||
if ((j = open(SlaveName,O_RDWR,0)) >= 0) {
|
||||
*slave = j;
|
||||
chown(SlaveName, getuid(), getgid());
|
||||
|
@ -387,11 +384,11 @@ get_device_once(int *master, int *slave, int fail)
|
|||
}
|
||||
|
||||
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();
|
||||
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;
|
||||
VALUE rport = rb_obj_alloc(rb_cFile);
|
||||
VALUE wport = rb_obj_alloc(rb_cFile);
|
||||
char SlaveName[DEVICELEN];
|
||||
|
||||
MakeOpenFile(rport, rfptr);
|
||||
MakeOpenFile(wport, wfptr);
|
||||
|
||||
establishShell(argc, argv, &info);
|
||||
establishShell(argc, argv, &info, SlaveName);
|
||||
|
||||
rfptr->mode = rb_io_mode_flags("r");
|
||||
rfptr->fd = info.fd;
|
||||
|
|
Loading…
Add table
Reference in a new issue