[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help on /dev/tty and su -c



On Thu, 15 Mar 2012 20:38:04 +0100 Vincent Fourmond wrote:

> On Thu, Mar 15, 2012 at 7:28 PM, Francesco Poli
> <invernomuto@paranoici.org> wrote:
> > On Thu, 15 Mar 2012 00:15:09 +0100 Vincent Fourmond wrote:
[...]
> >>   Could you try posting the output of
> >>
> >>   p Dir["/proc/self/fd/*"].map {|x| begin File::readlink(x); rescue; end }
> >>
> >>   just before opening /dev/tty ? If 2 or 1 is a /dev/pts, not all hope is lost.
> >
> > I will try to get this output, but will it apply to all Debian systems?
> > I am trying to solve the issue for all apt-listbugs users in the most
> > portable way, not for me...
> 
>   I was just trying to see if you can find a terminal (tty or
> pseudo-tty) in that output, in which case it would be easy to find
> where to send.

In the minimal test.rb, it outputs the following array of values:

["pipe:[89244]", "/dev/pts/8", "/dev/pts/8", nil]

when run without "su -c", and the practically identical

["pipe:[89278]", "/dev/pts/8", "/dev/pts/8", nil]

when run inside "su -c"


Or did you mean I should perform this test in the apt-listbugs code?

> >
> >>
> >>   I know this is probably a lot of work, but wouldn't it be just saner
> >> to use debconf rather than the terminal ? That would be more portable.
> >
> > This is interesting, I have been asked in the past to implement a
> > debconf frontend (see msg #25 of bug #628996), but I don't know how I
> > could ask questions and output data through debconf from within a
> > program written in Ruby...
> > I had searched for something (a library?) to use debconf from Ruby, but
> > had found nothing.
> 
>   As far as I can tell, there isn't.

That's unfortunate, I think.

> But you can access debconf using
> plain shell calls (debconf comes with a bunch of scripts). I guess for
> what you need, it should be fine, more portable and more robust -- let
> the debconf maintainers handle the gory details for you !
> Unfortunately, I can't help you much on that side, I don't use it
> myself :-<...
> 
> > Please tell me more: how can this be done from a Ruby program?
> 
>   Using plain system("debconf-something args")
[...]
> If you have
> debian-policy installed, have a look at:
> 
> file:///usr/share/doc/debian-policy/debconf_specification.html#AEN106

Are your referring to
http://www.debian.org/doc/packaging-manuals/debconf_specification.html
?

> 
> >>   You could also try prompting using readline, which may (? haven't
> >> checked) be able to find a tty even if /dev/tty isn't available.
> >
> > Interesting: I see that libruby provides the virtual package
> > libreadline-ruby.
> > I assume that this means that the readline → ruby binding is included
> > in the Ruby standard library.
> > Could you please suggest some documentation on how to use readline from
> > Ruby programs?
> 
>   As simple as that:
> 
> require 'readline'
> 
> while line = Readline.readline('> ', true)
>   p line
> end
> 
>   I'm worried it won't find the terminal though, but if it is
> possible, it should.

I tried with:


$ cat test_readline.rb 
#!/usr/bin/ruby

require 'readline'

STDIN.each { |line|
    puts "item: #{line}"
    # do many other things...
}

ans = Readline.readline('Enter something: ', true)
puts "You entered \"#{ans}\""
# do many more things...
puts "Bye!"
$ ./test_readline.rb 
1
item: 1
2
item: 2
Enter something: yeah!
You entered "yeah!"
Bye!


Hence, it seems to work, when fed directly from the terminal (I pressed
[Ctrl+D] after seeing the "item: 2" output).
Unfortunately, it seems to enter an endless loop, when STDIN is
connected to a pipe:


$ cat input.txt | ./test_readline.rb 
item: one
item: two
item: three
Enter something: no!
no!
nooo!!
please let me out!!!
:-(
help!
^C./test_readline.rb:10:in `readline': Interrupt
        from ./test_readline.rb:10



> 
>   But, really, I encourage you to have a look at debconf.

I'll try and see, but I am having more and more difficulties in finding
the time to address this issue...   :-( 


-- 
 http://www.inventati.org/frx/frx-gpg-key-transition-2010.txt
 New GnuPG key, see the transition document!
..................................................... Francesco Poli .
 GnuPG key fpr == CA01 1147 9CD2 EFDF FB82  3925 3E1C 27E1 1F69 BFFE

Attachment: pgpqzsUH79BC8.pgp
Description: PGP signature


Reply to: