How to prevent mouse initialization in Pygame

Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to prevent mouse initialization in Pygame

Роман Мещеряков

Hi all,

In my Python application running on Raspberry Pi under Raspbian I use Pygame to display some software-generated images via framebuffer. I don’t need any input from mouse, keyboard or any other devices, all I need is a convenient way of using framebuffer.

 

I initialize Pygame in the following way:

 

class FramebufferStaticImage(object):



    black
= (0, 0, 0)

    white
= (255, 255, 255)

 

    _ENV_VAR_DISPLAY
= "DISPLAY"

    _instance
= None

   

   
def __init__(self, log):

       
"Ininitializes a new pygame screen using the framebuffer"

       
# Based on "Python GUI in Linux frame buffer"

       
# http://www.karoltomala.com/blog/?p=679

       
if FramebufferStaticImage._instance != None:

           
raise Exception("No more than 1 instance of FramebufferStaticImage is allowed!")

       
FramebufferStaticImage._instance = self

       
self._log = log

       
self._log.info("[fb_static_image] Init: entered")

       
self._screen = None

 

       
# Try ensure using framebuffer and not X11 display even if it exists

       
if self._ENV_VAR_DISPLAY in os.environ:

           
del os.environ[self._ENV_VAR_DISPLAY]

       

        os
.putenv('SDL_FBDEV', '/dev/fb0')

        os
.putenv('SDL_VIDEODRIVER', 'fbcon')

        os
.environ['SDL_NOMOUSE'] = '1'

####        os.putenv('SDL_NOMOUSE', '1')

       
self._log.debug("Current environment is: {env}", env = os.environ)

       
import pygame

        pygame
.display.init()

 

       
self._width = pygame.display.Info().current_w

       
self._height = pygame.display.Info().current_h

       
self._log.info("[fb_static_image] Framebuffer size: {width} x {height}",

                       width
= self._width, height = self._height)

       
self._screen = pygame.display.set_mode(

           
(self._width, self._height), pygame.FULLSCREEN)

       
# Clear the screen to start

       
self._screen.fill(self.black)

       
# Initialise font support

        pygame
.font.init()

       
# Render the screen

        pygame
.display.update()

       
self._log.info("[fb_static_image] Init: leaving")


 

Problem #1: I have mouse pointer at the top left corner of Pygame-drawn images. I want mouse pointer to be hidden.

I know that I can disable mouse pointer using pygame.mouse.set_visible, but here comes

Problem #2: I have to run my application with sudo in order for pygame to not raise “unable to open a console terminal” exception. But I want to run my application without root rights, because this increases my application’s security.

There are some posts on forums that recommend setting SDL_NOMOUSE=1 environment variable before initializing pygame which should skip mouse initialization and maybe make it possible to get rid of sudo, but this doesn’t work for me: I still need to use sudo and mouse pointer is still there.

If this makes any difference, I have no mouse or keyboard attached to the Raspberry Pi, I connect to it using SSH.

I use

Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1

libsdl-image1.2 version 1.2.12-5+b1

libsdl1.2debian version 1.2.15-10+rpi1

 

Does SDL_NOMOUSE work for anyone using recent Pygame versions?

Is it possible to skip mouse initialization in Pygame?

P.S. This question was originally posted on StackExchange, but it seems I chose the wrong section. For this reason or another, I haven’t got any straight answer yet, so I write here and hope for the best :)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Ian Mallett-2
On Fri, Jun 30, 2017 at 12:28 PM, Роман Мещеряков <[hidden email]> wrote:

In my Python application running on Raspberry Pi under Raspbian I use Pygame to display some software-generated images via framebuffer. I don’t need any input from mouse, keyboard or any other devices, all I need is a convenient way of using framebuffer.

 

I initialize Pygame in the following way:

 

Problem #1: I have mouse pointer at the top left corner of Pygame-drawn images. I want mouse pointer to be hidden.

I know that I can disable mouse pointer using pygame.mouse.set_visible, but here comes

Problem #2: I have to run my application with sudo in order for pygame to not raise “

​​
unable to open a console terminal” exception. But I want to run my application without root rights, because this increases my application’s security.

There are some posts on forums that recommend setting SDL_NOMOUSE=1 environment variable before initializing pygame which should skip mouse initialization and maybe make it possible to get rid of sudo, but this doesn’t work for me: I still need to use sudo and mouse pointer is still there.

If this makes any difference, I have no mouse or keyboard attached to the Raspberry Pi, I connect to it using SSH.

I use

Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1

libsdl-image1.2 version 1.2.12-5+b1

libsdl1.2debian version 1.2.15-10+rpi1

 

Does SDL_NOMOUSE work for anyone using recent Pygame versions?

Is it possible to skip mouse initialization in Pygame?

P.S. This question was originally posted on StackExchange, but it seems I chose the wrong section. For this reason or another, I haven’t got any straight answer yet, so I write here and hope for the best :)

​Hi,

It's not exactly clear to me what you're trying to do. It sounds like:

I want to SSH into a RPI, open a fullscreen window on it, and disable user input on that window entirely. However, the mouse cursor still shows on that window, and I can't disable it with `mouse.set_visible(...)` because that makes my program require root privileges.

If this is so, your code and attempts are more-or-less what I would have tried. I don't know enough about Debian to know if that permission error is insurmountable (I can think of a fairly good reason it should be; you don't want random users to be able to hijack already running graphical sessions, although I'd expect opening a fullscreen window would also require root privileges for the same reason).

If it does turns out to be unworkable, is SSHing into the RPI and uploading images to an already-running daemon an answer? What exactly are you trying to do?

Ian​
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Jake b
In reply to this post by Роман Мещеряков
The best SE to post this would probably be stack overflow. There's quite a few pygame questions.

Do you always require sudo to run, or only if using ssh?

On Jun 30, 2017 1:29 PM, "Роман Мещеряков" <[hidden email]> wrote:

Hi all,

In my Python application running on Raspberry Pi under Raspbian I use Pygame to display some software-generated images via framebuffer. I don’t need any input from mouse, keyboard or any other devices, all I need is a convenient way of using framebuffer.

 

I initialize Pygame in the following way:

 

class FramebufferStaticImage(object):



    black
= (0, 0, 0)

    white
= (255, 255, 255)

 

    _ENV_VAR_DISPLAY
= "DISPLAY"

    _instance
= None

   

   
def __init__(self, log):

       
"Ininitializes a new pygame screen using the framebuffer"

       
# Based on "Python GUI in Linux frame buffer"

       
# http://www.karoltomala.com/blog/?p=679

       
if FramebufferStaticImage._instance != None:

           
raise Exception("No more than 1 instance of FramebufferStaticImage is allowed!")

       
FramebufferStaticImage._instance = self

       
self._log = log

       
self._log.info("[fb_static_image] Init: entered")

       
self._screen = None

 

       
# Try ensure using framebuffer and not X11 display even if it exists

       
if self._ENV_VAR_DISPLAY in os.environ:

           
del os.environ[self._ENV_VAR_DISPLAY]

       

        os
.putenv('SDL_FBDEV', '/dev/fb0')

        os
.putenv('SDL_VIDEODRIVER', 'fbcon')

        os
.environ['SDL_NOMOUSE'] = '1'

####        os.putenv('SDL_NOMOUSE', '1')

       
self._log.debug("Current environment is: {env}", env = os.environ)

       
import pygame

        pygame
.display.init()

 

       
self._width = pygame.display.Info().current_w

       
self._height = pygame.display.Info().current_h

       
self._log.info("[fb_static_image] Framebuffer size: {width} x {height}",

                       width
= self._width, height = self._height)

       
self._screen = pygame.display.set_mode(

           
(self._width, self._height), pygame.FULLSCREEN)

       
# Clear the screen to start

       
self._screen.fill(self.black)

       
# Initialise font support

        pygame
.font.init()

       
# Render the screen

        pygame
.display.update()

       
self._log.info("[fb_static_image] Init: leaving")


 

Problem #1: I have mouse pointer at the top left corner of Pygame-drawn images. I want mouse pointer to be hidden.

I know that I can disable mouse pointer using pygame.mouse.set_visible, but here comes

Problem #2: I have to run my application with sudo in order for pygame to not raise “unable to open a console terminal” exception. But I want to run my application without root rights, because this increases my application’s security.

There are some posts on forums that recommend setting SDL_NOMOUSE=1 environment variable before initializing pygame which should skip mouse initialization and maybe make it possible to get rid of sudo, but this doesn’t work for me: I still need to use sudo and mouse pointer is still there.

If this makes any difference, I have no mouse or keyboard attached to the Raspberry Pi, I connect to it using SSH.

I use

Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1

libsdl-image1.2 version 1.2.12-5+b1

libsdl1.2debian version 1.2.15-10+rpi1

 

Does SDL_NOMOUSE work for anyone using recent Pygame versions?

Is it possible to skip mouse initialization in Pygame?

P.S. This question was originally posted on StackExchange, but it seems I chose the wrong section. For this reason or another, I haven’t got any straight answer yet, so I write here and hope for the best :)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков

What I want to do with my Raspberry Pi: my application will run as a service and I will interact with it via web interface. There will be multimedia projector connected to RPi. Using web interface and pygame-based backend of my application I want to output to the projector some test patterns like grids, colour fillings etc.


суббота, 1 июля 2017 г., 21:26:53 UTC+3 пользователь Jake b написал:
The best SE to post this would probably be stack overflow. There's quite a few pygame questions.

Do you always require sudo to run, or only if using ssh?

 

I attached keyboard (and mouse) and logged in using this keyboard. This was very surprising to me but running my application from this real console doesn’t require sudo to use pygame! Why do I need sudo when running from SSH console?!

The good point is that using framebuffer on Raspbian without root access is possible. Though this point can be not so good after taking into account Ian’s words about random user hijacking already running graphical session, because this random user could be attacker that managed to get limited user access.

There is the second observation. If I run my pygame-using script as a service via systemd under limited user, I get the usual “unable to open a console terminal” exception (tried with and without mouse and keyboard attached). If I run my pygame-using script as a service via systemd under root, the service just exits unexpectedly! In /var/log/syslog there is no exception or any other useful information about cause of service exiting, it seems like some sort of crash. Very mysterious...


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Michael Lutinsky
> I attached keyboard (and mouse) and logged in using this keyboard. 
> This was very surprising to me but running my application from this 
> real console doesn’t require sudo to use pygame! Why do I need sudo 
> when running from SSH console?!

I think I can answer this. When your keyboard and mouse are plugged directly into a Linux box and you're sitting in front of the box using it regularly, the system has already started the X Window server, which is a root-level process, for you. 

When you log into the Linux box using ssh, you are given a text-only container/shell to play in. The X Window server is attached to a different login instance, not to you. So if you want to have access to the video sub-system from an ssh shell, you need to get root permission.

Alternatively, you could set up a VNC daemon server on the Pi to run when your desktop loads, and then from a remote computer, you could log into the Pi and control the desktop. I think that is more what you're looking for.


Michael
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков

среда, 5 июля 2017 г., 3:39:28 UTC+3 пользователь [hidden email] написал:
I think I can answer this. When your keyboard and mouse are plugged directly into a Linux box and you're sitting in front of the box using it regularly, the system has already started the X Window server, which is a root-level process, for you. 

When you log into the Linux box using ssh, you are given a text-only container/shell to play in. The X Window server is attached to a different login instance, not to you. So if you want to have access to the video sub-system from an ssh shell, you need to get root permission.

Alternatively, you could set up a VNC daemon server on the Pi to run when your desktop loads, and then from a remote computer, you could log into the Pi and control the desktop. I think that is more what you're looking for.


I’m not sure that X Window server is the cause, because I set up my Raspberry Pi to boot to command line. At least I see no desktop GUI after booting with keyboard connected, just command line login prompt. There is also second reason: I instruct pygame to not use X Window server (which, if I understand right, should set $DISPLAY environment variable), but to use framebuffer.

But I think you are right in that ssh console and “real” console are different in some aspects which are important for pygame initialization.

By the way, I examined __init__.py file of pygame (on my system it’s located in /usr/lib/python2.7/dist-packages/pygame/) and found out that it imports some modules with self-descriptive names like “key”, “mouse” and “joystick”. Moreover, comments and code in this file told me that these modules are not mandatory. So I renamed “mouse.so”, “key.so” and “joystick.so” in the aforementioned directory. My hope was that this will at least help me to get rid of mouse pointer in the top left corner of the screen or maybe even will let pygame initialize from ssh console without sudo. But, unfortunately, renaming didn’t change anything apart from several warnings printed on each pygame import:

 

pyscopefb.py:2: RuntimeWarning: import joystick: No module named joystick

(ImportError: No module named joystick)

 import pygame

pyscopefb.py:2: RuntimeWarning: import key: No module named key

(ImportError: No module named key)

 import pygame

pyscopefb.py:2: RuntimeWarning: import mouse: No module named mouse

(ImportError: No module named mouse)

 import pygame

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Daniel Foerster
Yeah that's not going to work because the attempted imports just fail. If you think having the mouse not initialized might help, change your call to pygame.init() into calls like pygame.display.init().

On Jul 5, 2017 10:33, "Роман Мещеряков" <[hidden email]> wrote:

среда, 5 июля 2017 г., 3:39:28 UTC+3 пользователь [hidden email] написал:
I think I can answer this. When your keyboard and mouse are plugged directly into a Linux box and you're sitting in front of the box using it regularly, the system has already started the X Window server, which is a root-level process, for you. 

When you log into the Linux box using ssh, you are given a text-only container/shell to play in. The X Window server is attached to a different login instance, not to you. So if you want to have access to the video sub-system from an ssh shell, you need to get root permission.

Alternatively, you could set up a VNC daemon server on the Pi to run when your desktop loads, and then from a remote computer, you could log into the Pi and control the desktop. I think that is more what you're looking for.


I’m not sure that X Window server is the cause, because I set up my Raspberry Pi to boot to command line. At least I see no desktop GUI after booting with keyboard connected, just command line login prompt. There is also second reason: I instruct pygame to not use X Window server (which, if I understand right, should set $DISPLAY environment variable), but to use framebuffer.

But I think you are right in that ssh console and “real” console are different in some aspects which are important for pygame initialization.

By the way, I examined __init__.py file of pygame (on my system it’s located in /usr/lib/python2.7/dist-packages/pygame/) and found out that it imports some modules with self-descriptive names like “key”, “mouse” and “joystick”. Moreover, comments and code in this file told me that these modules are not mandatory. So I renamed “mouse.so”, “key.so” and “joystick.so” in the aforementioned directory. My hope was that this will at least help me to get rid of mouse pointer in the top left corner of the screen or maybe even will let pygame initialize from ssh console without sudo. But, unfortunately, renaming didn’t change anything apart from several warnings printed on each pygame import:

 

pyscopefb.py:2: RuntimeWarning: import joystick: No module named joystick

(ImportError: No module named joystick)

 import pygame

pyscopefb.py:2: RuntimeWarning: import key: No module named key

(ImportError: No module named key)

 import pygame

pyscopefb.py:2: RuntimeWarning: import mouse: No module named mouse

(ImportError: No module named mouse)

 import pygame

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Greg Ewing
In reply to this post by Роман Мещеряков
Роман Мещеряков wrote:
>
> I instruct pygame to not use X Window
> server (which, if I understand right, should set $DISPLAY environment
> variable), but to use framebuffer.

Probably the framebuffer device is owned by root and only allows
access by root. Changing the permissions on /dev/fb might let
you avoid the need to run as root.

--
Greg

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Alec Bennett
Why not just programmatically move the mouse offscreen?

Or change the mouse cursor to something invisible. Both are easy under wx python, im guessing easy with pygame too.




> On Jul 5, 2017, at 4:22 PM, Greg Ewing <[hidden email]> wrote:
>
> Роман Мещеряков wrote:
>> I instruct pygame to not use X Window server (which, if I understand right, should set $DISPLAY environment variable), but to use framebuffer.
>
> Probably the framebuffer device is owned by root and only allows
> access by root. Changing the permissions on /dev/fb might let
> you avoid the need to run as root.
>
> --
> Greg
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков
In reply to this post by Daniel Foerster
среда, 5 июля 2017 г., 18:37:31 UTC+3 пользователь Daniel Foerster написал:
Yeah that's not going to work because the attempted imports just fail. If you think having the mouse not initialized might help, change your call to pygame.init() into calls like pygame.display.init().

I tried pygame.display.init() already and that didn’t help, mouse pointer is still there and root rights are still required for the successful run...

четверг, 6 июля 2017 г., 2:22:41 UTC+3 пользователь Greg Ewing написал:
Probably the framebuffer device is owned by root and only allows 
access by root. Changing the permissions on /dev/fb might let 
you avoid the need to run as root. 

I already changed permissions for the limited user (pi) according to this instruction: How do I let an SDL app (not running as root) use the console, but to no avail :(


четверг, 6 июля 2017 г., 3:29:43 UTC+3 пользователь Alec Bennett написал:
Why not just programmatically move the mouse offscreen? 

Or change the mouse cursor to something invisible. Both are easy under wx python, im guessing easy with pygame too. 


I know this is possible, there is even dedicated method pygame.mouse.set_visible(), but I need to eliminate mouse (or, better, any input device) initialization, because I want to run pygame without root rights and I believe skipping input devices initialization will let me do that.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Martin Kühne
> I already changed permissions for the limited user (pi) according to this instruction: How do I let an SDL app (not running as root) use the console, but to no avail :(

I just wanted to suggest you make sure permissions in /dev are
granted, but you appear to have arrived at that conclusion yourself.
Of course now you have to figure out which device is being opened
unsuccessfully. /dev/console only applies to text i/o and not
framebuffer and graphics. /dev/fb0 maybe? Maybe use strace instead?

cheers!
mar77i
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков

First some interesting fact. Earlier I wrote that performed limited user permissions setup according to reply in the How do I let an SDL app (not running as root) use the console StackExchange post. Today I discovered that rights change on /dev/console doesn’t survive reboot. I changed rights back and immediately, without rebooting, tried pygame example again. No visible changes, same “Unable to open console terminal” error for the limited user.


суббота, 8 июля 2017 г., 6:40:08 UTC+3 пользователь Martin Kühne написал:
> I already changed permissions for the limited user (pi) according to this instruction: How do I let an SDL app (not running as root) use the console, but to no avail :(

I just wanted to suggest you make sure permissions in /dev are
granted, but you appear to have arrived at that conclusion yourself.
Of course now you have to figure out which device is being opened
unsuccessfully. /dev/console only applies to text i/o and not
framebuffer and graphics. /dev/fb0 maybe? Maybe use strace instead?

cheers!
mar77i

I tried running under strace and got 2 log files: one of running under root and one for running under limited user (pi). Here is the different part:


ssh terminal, run as root

ssh terminal, run as limited user

Comment

open("/dev/tty0", O_WRONLY) = 5

ioctl(5, VIDIOC_QUERYCAP or VT_OPENQRY, 0x1e5f89c) = 0

close(5)                = 0

open("/dev/tty0", O_WRONLY) = 5

ioctl(5, VIDIOC_QUERYCAP or VT_OPENQRY, 0x776e1c) = 0

close(5)                = 0

Visible match, but I don’t know whether ioctl output data was the same, looking at subsequent system calls I suppose it wasn’t.

Frankly speaking, I don’t understand what does ioctl call with 2 OR’ed requests mean…

According to this article (it’s 1994!!! But there is no reason not to believe…), ioctl VT_OPENQRY is something like “kernel, give me some number of the free terminal I could use”

geteuid32()             = 0

geteuid32()             = 1000

Mismatch: got user ID we are running behind of

open("/dev/vc/2", O_RDWR) = -1 ENOENT (No such file or directory)


Mismatch: there was no try to open "/dev/vc/2" under limited user

open("/dev/tty2", O_RDWR) = 5


Mismatch: there was no try to open "/dev/tty2" under limited user

Looking at this and previous system calls I suppose ioctl VT_OPENQRY returned terminal number 2 for the case when pygame was run under root. For the limited-user case it’s not clear what was the result of that ioctl.

open("/dev/tty", O_RDWR) = 6


open("/dev/tty", O_RDWR) = 5


Match: opened current terminal device

ioctl(6, TIOCNOTTY)     = 0

close(6)                = 0



Root version detached itself from the current terminal. As I could find using Google, this is what usually daemon processes started from terminal do.


ioctl(5, VT_GETSTATE, 0x7ee7da28) = -1 ENOTTY (Inappropriate ioctl for device)


According to article mentioned above, ioctl VT_GETSTATE query is something like “kernel, give me list of terminals available and their use state”

ioctl(5, KDGKBMODE, 0x7eaf2078) = 0


ioctl(5, KDGKBMODE, 0x7ee7da28) = -1 ENOTTY (Inappropriate ioctl for device)

“Kernel, give me keyboard mode associated with this tty”

Limited-user version run this request on /dev/tty and root-user version run on /dev/tty2.

ioctl(5, KDGKBENT, 0x7eaf2078) = 0

close(5)                = 0

munmap(0x74340000, 3145728) = 0

close(3)                = 0

rt_sigaction(SIGINT, NULL, {0x127304, [], SA_RESTORER, 0x76d18180}, 8) = 0

rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0

write(2, "Traceback (most recent call last"..., 35) = 35

Seems previous ioctl result was fatal for limited-user version.


Despite large amount of data from strace, it’s really not clear to me what permissions and on what files should I set to allow limited user to run pygame from ssh terminal...

 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков
In reply to this post by Роман Мещеряков

Very strange that 2 latest Martin’s replies sent 9th of July are not shown on the Google Groups site...

Sorry that I didn’t reply for a while. Thank you Martin for the link to StackExchange question about terminals! It took a while to read the question and replies and links mentioned there. It will require some time to understand everything, but at least I feel myself less confused when someone mentions “terminal”, “console”, “/dev/tty” or “/dev/pts/0” :)

Martin, in one of your previous messages you mentioned “client terminal” and “master terminal”. My knowledge of the subject and terminology is still not very good. What is the difference between them? Google didn’t give me anything useful on the “client terminal vs master terminal” query.

As of membership in the tty group, I checked that my limited user (pi) is member of this group.

I was wondering what is ioctl call with double “VIDIOC_QUERYCAP or VT_OPENQRY” request. It seems I found and answer. VIDIOC_QUERYCAP has a value of 0x80685600 on Raspbian and VT_OPENQRY is 0x5600. I read that in early Linux ioctl request values were 16-bit integers. Lowest 16 bits of VIDIOC_QUERYCAP and VT_OPENQRY match and it seems this why strace shows both constants. After some experiments I understood that actual constant passed to ioctl is VT_OPENQRY. Also my experiments revealed that ioctl VT_OPENQRY result is the same for both root and limited user: it’s the number 2 which I believe designates /dev/tty2. (I should note this result was obtained by running simple python program which just opens /dev/tty0 and performs ioctl on the file descriptor returned; but I think we can assume that behaviour during pygame execution is the same.). This means that the point of divergence between root and limited user resides later in the program execution. More specifically, the question is: why limited-user version of pygame doesn’t try to open /dev/tty2? Does anyone have any suggestion on how to investigate that? I will appreciate any suggestions...


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Fwd: [pygame] How to prevent mouse initialization in Pygame

Martin Kühne
In reply to this post by Роман Мещеряков
Sorry everyone for the confusion, as was mentioned, two of my previous
emails was sent off-list for whatever reason.
I read up on the topic arriving at the SE thread that was linked
before [0] and tried to figure out the problem based on the work with
strace, which I commended as very through and well-conceived. I also
asked Roman to tell me whether group membership in `tty` would help,
which own the files in /dev on my system. Also Roman, please note that
many ioctls return data in pointers that can be passed to them which
should be the spot where your results actually differ.

cheers!
mar77i

[0] https://unix.stackexchange.com/questions/117981/what-are-the-responsibilities-of-each-pseudo-terminal-pty-component-software.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Weeble
Hi, I'm not able to follow along as I don't have a Pi, but since I see
attempts to dissect the behaviour of the SDL code via strace, I
thought it worth pointing out that this source code is available and
need not be treated as a complete black box. You can download it from
the SDL site. My links below are to an unofficial copy that somebody
has uploaded to github, but seems to be match the download version.

FB_OpenKeyboard in SDL_fbevents[1] is called unconditionally during
Framebuffer video initialization.[2] You can see there that *most* of
the logic to find a keyboard device is guarded by a check that
geteuid() == 0. (I.e. that the user is root.) The only fallback for
when not root is to try to open /dev/tty. If it fails to find a
keyboard device it can use it aborts. I hope that helps back up what
has been gleaned from the strace and maybe gives some clues.

[1] - https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbevents.c#L246
[2] - https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbvideo.c#L531

On 13 July 2017 at 21:22, Martin Kühne <[hidden email]> wrote:

> Sorry everyone for the confusion, as was mentioned, two of my previous
> emails was sent off-list for whatever reason.
> I read up on the topic arriving at the SE thread that was linked
> before [0] and tried to figure out the problem based on the work with
> strace, which I commended as very through and well-conceived. I also
> asked Roman to tell me whether group membership in `tty` would help,
> which own the files in /dev on my system. Also Roman, please note that
> many ioctls return data in pointers that can be passed to them which
> should be the spot where your results actually differ.
>
> cheers!
> mar77i
>
> [0] https://unix.stackexchange.com/questions/117981/what-are-the-responsibilities-of-each-pseudo-terminal-pty-component-software.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Alec Bennett
Another possibility would be to execute a command that moves the mouse way off screen?




On Fri, Jul 14, 2017 at 5:26 AM, Annette Wilson <[hidden email]> wrote:
Hi, I'm not able to follow along as I don't have a Pi, but since I see
attempts to dissect the behaviour of the SDL code via strace, I
thought it worth pointing out that this source code is available and
need not be treated as a complete black box. You can download it from
the SDL site. My links below are to an unofficial copy that somebody
has uploaded to github, but seems to be match the download version.

FB_OpenKeyboard in SDL_fbevents[1] is called unconditionally during
Framebuffer video initialization.[2] You can see there that *most* of
the logic to find a keyboard device is guarded by a check that
geteuid() == 0. (I.e. that the user is root.) The only fallback for
when not root is to try to open /dev/tty. If it fails to find a
keyboard device it can use it aborts. I hope that helps back up what
has been gleaned from the strace and maybe gives some clues.

[1] - https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbevents.c#L246
[2] - https://github.com/infertux/SDL-1.2.7/blob/master/src/video/fbcon/SDL_fbvideo.c#L531

On 13 July 2017 at 21:22, Martin Kühne <[hidden email]> wrote:
> Sorry everyone for the confusion, as was mentioned, two of my previous
> emails was sent off-list for whatever reason.
> I read up on the topic arriving at the SE thread that was linked
> before [0] and tried to figure out the problem based on the work with
> strace, which I commended as very through and well-conceived. I also
> asked Roman to tell me whether group membership in `tty` would help,
> which own the files in /dev on my system. Also Roman, please note that
> many ioctls return data in pointers that can be passed to them which
> should be the spot where your results actually differ.
>
> cheers!
> mar77i
>
> [0] https://unix.stackexchange.com/questions/117981/what-are-the-responsibilities-of-each-pseudo-terminal-pty-component-software.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков
In reply to this post by Martin Kühne


четверг, 13 июля 2017 г., 23:22:27 UTC+3 пользователь Martin Kühne написал:
Also Roman, please note that
many ioctls return data in pointers that can be passed to them which
should be the spot where your results actually differ.


I remember that, in particular, VT_OPENQRY accepts pointer to integer to store result. In my experiments I printed to stdout value of integer pointed to, not the pointer itself.

пятница, 14 июля 2017 г., 19:33:29 UTC+3 пользователь Alec Bennett написал:
Another possibility would be to execute a command that moves the mouse way off screen?


I think the title of this discussion thread became confusing, because my goal is not to just get rid of mouse pointer, but rather get rid of necessity to run pygame-based script as root. When I started this thread I thought that need for root rights was a consequence of mouse initialization. But now with help of kind people here I realized that the problem is not mouse but keyboard/console terminal initialization instead.

As the moment I think that more correct title for this discussion thread would be “How to run pygame framebuffer graphics without root rights” or something similar.


I started thinking about looking into SDL sources already, but I was hoping there is an easier way. But after Annette’s reply with direct references to relevant points in the code I realized that time has come :) Thank you very much Annette for your help!

I succeeded with SDL compilation from libSDL 1.2 sources for Debian using this really simple and working instruction. Here are first results.

First I commented out FB_OpenKeyboard call in SDL_fbvideo.c, but that lead to pygame error without descriptive error message, so I reverted my changes and tried removing check for root rights inside FB_OpenKeyboard. This revealed necessity to add read permissions to the tty group on the /dev/tty2 device. After fixing that, the failing system call now is:

ioctl(5, VT_ACTIVATE, 0x2)              = -1 EPERM (Operation not permitted)

I’ve spent some time investigating this but haven’t find complete solution yet.

Taking into account that my ultimate goal is to run pygame without root rights as a daemon, I suppose completely eliminating keyboard/console terminal initialization is a more promising direction.

Let me know in case you have any advice or suggestion.


 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Martin Kühne
What's your status about the `tty` group membership?

cheers!
mar77i
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков

понедельник, 17 июля 2017 г., 21:34:54 UTC+3 пользователь Martin Kühne написал:

What's your status about the `tty` group membership?

cheers!
mar77i

The limited user is a member of this group:


pi@masternoinit:~ $ groups

pi adm tty dialout cdrom sudo audio video plugdev games users input netdev console gpio i2c spi


 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to prevent mouse initialization in Pygame

Роман Мещеряков

Good news: I succeeded with commenting out SDL code that deals with keyboard, and after that I was able to run pygame framebuffer graphics without root rights! But there is a small issue: there is a text cursor blanking at the bottom of the screen.

By the way, it turned out that /dev/console rights change mentioned in reply to the How do I let an SDL app (not running as root) use the console StackExchange post is not necessary, at least on Raspbian.

My next steps are to run pygame framebuffer graphics as a daemon. I will try using systemd as a daemon supervisor, because this is the default choice in Raspbian.


Kind regards, Roman Mescheryakov
12
Loading...