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

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



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:
>
>>   Hello,
>
> Hi! Thanks for your kind reply!
>
>>
>> On Wed, Mar 14, 2012 at 11:21 PM, Francesco Poli
>> <invernomuto@paranoici.org> wrote:
> [...]
>> > Currently, apt-listbugs does all this by opening "/dev/tty", after the
>> > input ends.
>>
>>   Does it do that as root ?
>
> It (typically) does the described steps as root, yes.
>>  Why do you need su ?
>
> It's *not* apt-listbugs that invokes  su -c "command" (except for one
> case, see the first of the two bugs I am struggling with: #662865),
> it's apt-listbugs that *may* be invoked inside an  su -c "command" ,
> either explicitly by the user, or by aptitude ncurses interface (if run
> as a regular user, aptitude ncurses interface asks the user for the root
> password, whenever it needs root privileges to perform an operation and
> invokes su -c "command" to perform it; see the second of the two bugs I
> am struggling with: #662983).

  OK, I understand better the problem now.

>>   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.
>
>>
>>   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. 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")

  Now that I have looked a bit more, it seems that you may be
interested in something like:

(echo input critical stuff; echo go) | debconf-communicate

  The only unfortunate thing is that you need somehow to define the
question stuff beforehand (using debconf templates). You may have to
reset it just before, too. I think it's probably doable. If you have
debian-policy installed, have a look at:

file:///usr/share/doc/debian-policy/debconf_specification.html#AEN106

>>   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.

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

  Cheers,

      Vincent


Reply to: