[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Bug in Ruby's PTY extension

ronald braswell

8/6/2007 4:28:00 PM




>From: Nobuyoshi Nakada <nobu@ruby-lang.org>
>Reply-To: ruby-talk@ruby-lang.org
>To: ruby-talk@ruby-lang.org (ruby-talk ML)
>Subject: Re: Bug in Ruby's PTY extension
>Date: Mon, 6 Aug 2007 17:38:17 +0900
>
>Hi,
>
>At Mon, 6 Aug 2007 02:28:38 +0900,
>ronald braswell wrote in [ruby-talk:263410]:
> > I noticed that Solaris 10 does not support TIOCSCTTY so in function
> > establishShell() the child process closes the slave device and reopens
>it to
> > force it to be the controlling tty. The parent process also closes the
> > slave device because it does not need it. I added a call to nanosleep
>for
> > 20 milliseconds just before the parent process closes the slave fd at
>the
> > end of establishShell() and I now both expect and RExpect work reliably.
> I
> > suspect that just keeping a reference to the open file object in the
>parent
> > process while the child process closes and reopens the slave device
>prevents
> > the EOF from occurring -- but I am far from an expert on Solaris
>internals.
> > This may not be the best way to solve the problem and just adding the
>small
> > delay does not ensure that the problem will never happen again but so
>far,
> > so good.
>
>Does this patch work?
>
>
>Index: ext/pty/expect_sample.rb
>===================================================================
>--- ext/pty/expect_sample.rb (revision 12878)
>+++ ext/pty/expect_sample.rb (working copy)
>@@ -16,8 +16,4 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r
> $expect_verbose = false
>
>- r_f.expect(/^Name.*: /) do
>- w_f.print "ftp\n"
>- end
>-
> if !ENV['USER'].nil?
> username = ENV['USER']
>@@ -28,9 +24,6 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r
> 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
>Index: ext/pty/pty.c
>===================================================================
>--- ext/pty/pty.c (revision 12878)
>+++ ext/pty/pty.c (working copy)
>@@ -40,8 +40,8 @@
> #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",
>@@ -63,8 +63,8 @@ char *MasterDevice = "/dev/ptym/pty%s",
> };
> #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",
>@@ -85,8 +85,8 @@ char *MasterDevice = "/dev/ptyp%s",
> };
> #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",
>@@ -102,6 +102,4 @@ char *MasterDevice = "/dev/pty%s",
> #endif /* !defined(HAVE_OPENPTY) */
>
>-static char SlaveName[DEVICELEN];
>-
> #ifndef HAVE_SETEUID
> # ifdef HAVE_SETREUID
>@@ -156,15 +154,13 @@ pty_syswait(info)
> 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);
>@@ -177,5 +173,5 @@ pty_syswait(info)
> }
>
>-static void getDevice _((int*, int*));
>+static void getDevice _((int*, int*, char [DEVICELEN]));
>
> struct exec_info {
>@@ -195,11 +191,12 @@ pty_exec(v)
>
> static void
>-establishShell(argc, argv, info)
>+establishShell(argc, argv, info, SlaveName)
> int argc;
> VALUE *argv;
> struct pty_info *info;
>+ char SlaveName[DEVICELEN];
> {
> int i,master,slave;
>- char *p,*getenv();
>+ char *p, tmp, *getenv();
> struct passwd *pwent;
> VALUE v;
>@@ -224,5 +221,5 @@ establishShell(argc, argv, info)
> argv = &v;
> }
>- getDevice(&master,&slave);
>+ getDevice(&master, &slave, SlaveName);
>
> info->thread = rb_thread_current();
>@@ -274,4 +271,5 @@ establishShell(argc, argv, info)
> close(master);
> #endif
>+ write(slave, "", 1);
> dup2(slave,0);
> dup2(slave,1);
>@@ -289,4 +287,5 @@ establishShell(argc, argv, info)
> }
>
>+ read(master, &tmp, 1);
> close(slave);
>
>@@ -306,6 +305,7 @@ pty_finalize_syswait(info)
>
> static int
>-get_device_once(master, slave, fail)
>+get_device_once(master, slave, SlaveName, fail)
> int *master, *slave, fail;
>+ char SlaveName[DEVICELEN];
> {
> #if defined HAVE_OPENPTY
>@@ -354,4 +354,5 @@ get_device_once(master, slave, fail)
> if(ioctl(j, I_PUSH, "ptem") != -1) {
> if(ioctl(j, I_PUSH, "ldterm") != -1) {
>+ ioctl(j, I_PUSH, "ttcompat");
> #endif
> *master = i;
>@@ -396,10 +397,11 @@ get_device_once(master, slave, fail)
>
> static void
>-getDevice(master, slave)
>+getDevice(master, slave, SlaveName)
> int *master, *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);
> }
> }
>@@ -418,9 +420,10 @@ pty_getpty(argc, argv, self)
> 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");
>
>
>--
>Nobu Nakada
>

Hi Nobu,

Thanks for your patch. It is much better than the quick hack that I had
done. I have tested it and it works fine! Just one thing, I had to comment
out freeDevice() in my version of pty.c since it referenced the previously
file scoped SlaveName. freeDevice() was not externally linked and there
were no references to it in pty.c. Maybe I overlooked the deletion of it
in you diff -u output.

Ron

_________________________________________________________________
Tease your brain--play Clink! Win cool prizes!
http://club.live.com/clink.aspx?icid=clink_hotmai...


2 Answers

Nobuyoshi Nakada

8/7/2007 5:59:00 AM

0

Hi,

At Tue, 7 Aug 2007 01:28:08 +0900,
ronald braswell wrote in [ruby-talk:263528]:
> Thanks for your patch. It is much better than the quick hack that I had
> done. I have tested it and it works fine! Just one thing, I had to comment
> out freeDevice() in my version of pty.c since it referenced the previously
> file scoped SlaveName. freeDevice() was not externally linked and there
> were no references to it in pty.c. Maybe I overlooked the deletion of it
> in you diff -u output.

It has been deleted in 1.8.6 already, since it wasn't used at
all.

--
Nobu Nakada

Sheldon Cooper

1/25/2011 11:52:00 PM

0

On Jan 25, 7:11 am, Yoorg...@Jurgis.net wrote:
> On Tue, 25 Jan 2011 01:21:07 -0800 (PST), Sheldon Cooper
>
> <richarddead...@gmail.com> wrote:
> >18 of that 20 remained Democrats.
>
> That's nonsense of course--

No, it's an historical fact.

> and it does not negate the fact (and truth)
> that their IDEOLOGY remained conservative (except Byrd).

"Except Byrd"? Byrd when on CNN a few years before his death and
blathered on condemning "white niggers".

Here's most of the Dixiecrat Sentors.

18 of the 20 remained Democrat the rest of their careers.


(D)VA Harry F. Byrd, 1933-1965
(D)VA A. Willis Robertson, 1946-1966
(D)WV Robert C. Byrd, 1959-
(D)MS John C. Stennis, 1947-1989
(D)MS James O. Eastland, 1941-1941,1943-1978
(D)LA Allen J. Ellender, 1937-1972
(D)LA Russell B. Long, 1948-1987
(D)NC Everett Jordan,
(D) SC Olin Johnston,
(D) Georgia - Richard Russell,
(D) Georgia - Herman Talmedge
(D) Alabama - Lister Hill,
(D) Alabama - John Sparkman
(D) Arkansas - John McClellan,
(D) Arkansas - William Fulbright
(D) Florida - Spessard Holland,

> There is a reason they "remained democrats"

Because they agreed with the Democrats.

>(for a time)--->

The bime being THE REST OF THEIR LIVES

it was
> because the entire southern conservative electorate associated the
> demise of slavery and segregation with Republicans and liberals--and
> therefore could not be elected (in the south) unless they were
> democrats.

Here's the truth.

The Democrats were racists.

The Democrats ARE racist. The fact that they swapped what racist the
hate doesn't make them any less racist or hateful.

YOU are a hate monger. YOU are one of the most hateful people on
Usenet.

You hate members of the Tea Party and whites and conservatives with
the same passion that your parents hated blacks.

You hate FOX News

You hate Rush Limbaugh.

You're a hate monger.

You desperately want to blame

> The shift from democrat to republican came AFTER the Mid 60's--when
> enforcement of the CRA began in earnest, enforcing integration, the
> passage of LIBERAL/PROGRESSIVE legislation to end discrimination and
> the ENFORCEMENT of the law.

What also happen in the mid 60s, 70s, and 80s?

THE NORTHERN REPUBLICANS MOVED SOUTH.

When the Democrats controlled the South, you had you had segregation,
you had terrible behavior.

Since the Republicans took over the south, there were no
segregation.

Now, you can pretend that, in modern Atlanta, there's still "colored
only" rest rooms if you like - but please don't insist that I indulge
your fantasy.