Autore Topic: Problema con Shell su Fedora (il codice funziona in IDE ma non in un eseguibile)  (Letto 2837 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Riporto una discussione apparsa nella M.L.I.:

« Hmm. I have sudo-1.8.6p7 in use (more accurately, the error comes from the
 'sudoers' plugin but it has the same version here) on Arch Linux and, as I
 said, my test program works.

 Well, I had another look at the source code and it seems that there's a
 certain variable 'def_requiretty' which is zero in my system's package and
 prevents checking /dev/tty at all. This finally explains why all test cases
 worked on my system even though there was no /dev/tty accessible from
 Desktop. See sudoers(5) for a description and how to deactivate this in the
 sudoers configuration.

 Since editing user configurations to make programs work is often not
 desirable, I experimented with a patched sudo that requires the tty et
 voila! Got the same error as yours when running from desktop. However, now
 I can't solve it either :-)

I'll start another thread to attract Benoit's attention again...

Tobias Boege
»


« Hmm, nevermind. You can use the Exec instruction to get it to work:

hProcess = Exec ["sudo", "-s", "id", "-u" ] For Input Output As "Process"

This is how the IDE does it and as you mentioned, the IDE gets it correctly.
Maybe someone can enlighten us why it doesn't work with Shell but it's not
that important to me.

Regards,
Tobi
»


« SHELL "a b c" ...

is equivalent to:

EXEC [ System.Shell, "-c", "a b c" ]

with a call to setpgid(0,0) to create its own session like an
independant shell.

As for virtual terminal creation, they work both the same.

- "For Input Output" => create a virtual terminal for the i/o of the
child process, and get the i/o of the child process through it.

- "For Read Write" => Just redirect the i/o of the child process to get
them in the parent process.

Can you try to replace "SHELL ..." by "EXEC [ System.Shell, "-c", ... ]"
and tell me if it works better?

--
Benoît Minisini
»


« Exec [System.Shell, "-c", "sudo -s id -u"] For Input Output

It works!

Regards,
Tobi
»


« So is it the setpgid() call that prevents sudo from finding the virtual
terminal? Strange...

--
Benoît Minisini
»


« Well, I spent the whole forenoon searching for a solution and setpgid() was
mentioned sometimes{0} when it was about acquiring a virtual terminal. Only
a session leader can change the virtual terminal (setsid()) but you *must
not* be a group leader (but you are by setpgid(0, 0)). This seems to be it,
indeed.

Regards,
Tobi

{0} http://blog.habets.pp.se/2009/03/Moving-a-process-to-another-terminal
»
« Ultima modifica: 30 Marzo 2013, 14:47:34 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
...la discussione continua......

« NOT on the Fedora 17 - LXDE 0.5.12 - Gambas 3.4.0 when run from
executable. Same error again

Screen01.png -> Running executable with error message
Screen02.png -> changed code using Exec [System.Shell .....]

Somehow it is impossible to use sudo on the Fedora box from Gambas
executable.
Although all works when done directly in terminal by hand or when done
from Gambas 3 app run in IDE. The Gambas 3 executables just refuse to
work...

On my Linux Mint 13 all works just fine.

--
Kind regards,

Willy (aka gbWilly)
»


« Sorry, but you must use "For Input Output", not "For Read Write".

--
Benoît Minisini
»


« Well I used Read Write because when replacing Read Write with Input
Output the application does nothing but keep the system busy!!

Source Archive attached (made by Tobias, adapted by me)

--
Kind regards,

Willy (aka gbWilly)
»


« The not doing anything mentioned above is only when run from IDE on
Fedora. On other distro's no problem at all when running from IDE

I can confirm that the:
Exec [System.Shell, "-c", "sudo -s id -u"] For Input Output
now works on Fedora from executable.
So now I'll implement this manner of executing a Shell in my application
and see if all works there as well

Tobi, Benoît, Thanks...

--
Kind regards,

Willy (aka gbWilly)
»
« Ultima modifica: 31 Marzo 2013, 18:29:02 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »