Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mangoapp: Select unique SysV message queue #1660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ColinKinloch
Copy link

@ColinKinloch ColinKinloch commented Dec 8, 2024

This allows multiple mangoapp instances to run on the same system.

Currently gamescope and mangoapp communicate using a System V message queue with the key 0xffffffff. This is because ftok("mangoapp", 65) returns -1 when it fails to find mangoapp in the current working directory.
This means messages from any instance of gamescope will be received by any instance of mangoapp.

A simple fix for this would be to use ftok(".", 65) which would generate a key from the inode of the working directory and the number 65, however this would break backwards compatibility and cause collisions for gamescope instances sharing a working directory.

Instead I decided to use a POSIX message queues with the descriptive name /gamescope-mangoapp-{gamescope pid} which gets shared with mangoapp using the environment variable MANGOAPP_MQ_NAME.

This branch avoids collisions by using the current directory and incrementing the proj_id field until getmsg successfully creates a new queue.

This implementation also leaves the old message queues intact which should silently fail when they fill up.

Works with flightlessmango/MangoHud#1502

before after
Screencast From 2024-12-08 22-21-13.webm Screencast From 2024-12-08 22-20-02.webm

@matte-schwartz
Copy link

I was able to find a case where #1653 would rapidly switch the reported engine name between showing "Gamescope" and "Vulkan" if you launched gamescope --mangoapp -- glxgears and gamescope --mangoapp -- vkcube alongside one another on Cosmic desktop without your PR.

Adding your PR to both gamescope and MangoHud on top of what I already had solved this issue, and made each window lock to the correct engine information

@misyltoad
Copy link
Collaborator

Is this backwards compatible with old mangoapp and vice-versa? It looks it, but I won't lie I am not super up on mq code.

@ColinKinloch
Copy link
Author

Yes.

gamescope passes the same message to both queues so whichever version of mangoapp will continue receiving data. Eventually the unused queue will fill up but both are non blocking so this will return EAGAIN errors and will waste 16384 bytes in the case of the sysv queue.

From mangoapps perspective if MANGOAPP_MQ_NAME is set it will only consume messages from the POSIX queue, so will continue to work with old gamescope versions.

I hope everything I've said is correct, but this is my first time interacting with message queues.

@ColinKinloch
Copy link
Author

I run steam in a flatpak and it seems sandboxing message queues isn't simple.

I'm going to come up with a better solution 😩.

This allows multiple mangoapp instances to run on the same system.
@ColinKinloch ColinKinloch changed the title mangoapp: Use POSIX message queues mangoapp: Select unique SysV message queue Dec 16, 2024
@ColinKinloch
Copy link
Author

I've updated this to attempt to find a clear System V message queue key.

It continues to push messages to the old queue so is still backwards compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants